using knob to adjust audio frequency

17 次查看(过去 30 天)
Gavin
Gavin 2025-12-1,0:33
回答: Walter Roberson 2025-12-1,3:21
How can I use a knob to adjust the frequency of audio such as the handel.mat sound

回答(1 个)

Walter Roberson
Walter Roberson 2025-12-1,3:21
Use uiknob with the 'ValueChangedFcn' option to call a callback function that stores the new frequency.
Beyond that will depend on whether you want continuous frequency change or discrete frequency change.
If you want discrete frequency change, then you can use audioplayer stop() method, then set the SampleRate property, and then play() -- but this will restart the audio from the beginning, and will play the audio only once per invocation of play(). [Note: it just might be possible to resume() after setting the SampleRate property... not sure.]
If you want continuous frequency change, then you would use https://www.mathworks.com/help/audio/ref/audiodevicewriter-system-object.html . I do not know what happens if you change the SampleRate while you are playing.
You might possibly need to set the SampleRate somewhat high, and then resample() the soundwave from the chosen frequency to the chosen SampleRate; some buffer management would be needed to be able to switch frequencies in mid playing.

类别

Help CenterFile 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!

Translated by