using knob to adjust audio frequency
17 views (last 30 days)
Show older comments
How can I use a knob to adjust the frequency of audio such as the handel.mat sound
0 Comments
Answers (1)
Walter Roberson
on 1 Dec 2025 at 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.
0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!