Create and dynamically change a continuous tone with user input in MATLAB
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
neuroDuck
il 7 Dic 2021
Commentato: neuroDuck
il 8 Dic 2021
Hi all,
Does anyone know a way that you would dynamically change a tone based on user input? That is, I want to generate a continuous tone in Matlab (for 5 seconds), of a particular frequency, and allow changing of that frequency while it plays (i.e. within that five seconds), by a particular percentage at a time, using a keyboard (e.g. up for increase pitch, down for decrease). Is this even possible with Matlab? At present, I currently just produce a several rapid tones, checking for user input after each one and adjust the next tone based on this, but a dynamically-changing continuous tone would be more ideal. Thank you!
0 Commenti
Risposta accettata
Walter Roberson
il 7 Dic 2021
See
In particular, you cannot change the tone instantly . There is always going to be some processing delay, and MATLAB itself is being interrupted by the operating system for random things, and processing at the MATLAB level is slower than you would need for real-time audio.
So what you need to do is have a buffer of samples that you write into, and the audio drivers take samples from the buffer and output them when the time comes. If you use a large buffer then you have plenty of time to do other things, but it could be a while before any new sounds you queue make it to the speakers.
There is always a trade-off: if your buffer is too small, your code has too much overhead and cannot keep up. If your buffer is too big, delays before changes become audible become too large.
In some cases it is not possible to resolve the problem to your satisfaction -- not without doing things like killing off nearly all the other programs on the host, or compiling the MATLAB code to reduce interpretation delays.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!