Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Matlab to make a simple version of octave sauce game

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use Matlab to make a simple version of the octave sauce game". The editor shows you the operation process through an actual case, the operation method is simple and fast, and is practical. I hope this article "how to use Matlab to make a simple version of the octet sauce game" can help you solve the problem.

Effect.

Game mode

Yell after plugging in the headphones on the computer!

Description

1) to use this code, you should first install:

Audio Toolbox toolbox, the version used by bloggers is:

Audio Toolbox version 3.0 (R2021a)

2) in order to ensure that the game starts after loading all the materials, the loading interface is set to stop for 3 seconds and then start running the game.

If you hang up as soon as you enter the interface, the resource should be loaded for too long. Please close the window and try to run it again.

Code for the main part of the toolbox

1) basic settings

Here, I don't bother to change the truncated data recognized by voice commands that are copied directly. You can change it according to your needs:

[audio_t,fs] = audioread ('stop_command.flac'); classificationRate = 20 leading adrenders audioDeviceReader (' SampleRate',fs,'SamplesPerFrame',floor (fs/classificationRate)); audioBuffer=dsp.AsyncBuffer (fs)

Sound signal drawing:

If ishandle (fig) audio_t=adr (); write (audioBuffer,audio_t); audio_y=read (audioBuffer,fs,fs-adr.SamplesPerFrame); audio_x= (0: (length (audio_y)-1)). / (length (audio_y)-1); audioHdl.XData=audio_x; audioHdl.YData=audio_y;end

Note:

After the code, the sound acquisition device must be released and the timer real class must be deleted, otherwise there will be the following prompt bug:A given audio device may only be opened once.

That is, a device is turned on twice.

Therefore, you need to set the following callback to avoid this situation:

Set (gcf,'tag','co','CloseRequestFcn',@clo); function clo (~, ~) stop (game) delete (game) release (adr) delete (findobj ('tag','co')) Clf,close,clcend complete code function audioGame%@author:slandarer% use toolkit:% Audio Toolbox version 3.0 (R2021a)% figure create fig=figure ('Units','normalized','Position', [0.2 0.2 0.6 0.5]); fig.NumberTitle='off';fig.MenuBar='none';fig.Resize='off';fig.Name='audio Game by slandarer';% axes_1 create (main axes) ax_1=axes (fig); ax_1.Position= [0 011] Ax_1.XTick= []; ax_1.YTick= []; ax_1.ZTick= []; ax_1.XLim= [0600]; ax_1.YLim= [0200]; hold (ax_1,'on')% axes_2 creation (acoustic display axes creation) ax_2=axes (fig); ax_2.Position= [0.7 0.8 0.3 0.2]; ax_2.XTick= []; ax_2.YTick= []; ax_2.ZTick= []; ax_2.XLim= [0 1] Ax_2.YLim= [- 11]; ax_2.Box='on';ax_2.LineWidth=2;ax_2.Color= [250250247]. / 255 position hold (ax_2,'on')% drawing function handle groundHdl=fill (ax_1, [0jue 600, 600, 0], [0memo65pc65], [0m64115]. / 255); holeHdl_1=fill (ax_1, [0pc5050] + 500, [0pc055j65], [11 1], 'EdgeColor', [11 1]) HoleHdl_2=fill (ax_1, [0pje 50rect 50]] + 800, [0pje 0je 65rect 65], [11 1], 'EdgeColor', [11 1]); holeHdl_3=fill (ax_1, [0 recorder 50] + 1100, [0 recorder 6], [11 1],' EdgeColor', [11 1]); audioHdl=plot (ax_2, [0prit 1], [0mem0], 'Color', [0mem64115]. / 255); roleHdl_a=scatter (ax_1,100,95,300,'filled','CData', [0r 64115]. / 255) RoleHdl_b=fill (ax_1, [- 505] + 100, [90Eng 65Die 90], [0rect 64115]. / 255);% basic properties role.y=0;role.v=0;role.a=-2;% window main callback = = [audio _ tmag fs] = audioread ('stop_command.flac'); classificationRate = 20 fs audioDeviceReader (' SampleRate',fs,'SamplesPerFrame',floor (fs/classificationRate)); audioBuffer=dsp.AsyncBuffer (fs); pause (3) fps=20 Game=timer ('ExecutionMode','FixedRate','Period',1/fps,'TimerFcn',@audioMainGame); start (game) set (gcf,'tag','co','CloseRequestFcn',@clo); function clo (~, ~) stop (game) delete (game) release (adr) delete (findobj (' tag','co')); clf,close,clcend function audioMainGame (~, ~) holeHdl_1.XData=holeHdl_1.XData-5 HoleHdl_2.XData=holeHdl_2.XData-5; holeHdl_3.XData=holeHdl_3.XData-5; if holeHdl_1.XData (1)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report