Create and dynamically change a continuous tone with user input in MATLAB
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 7 Dec 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.
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!