Create and dynamically change a continuous tone with user input in MATLAB
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2021 年 12 月 7 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio I/O and Waveform Generation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!