Matlab real-time audio plotting in a GUI

11 views (last 30 days)
Liwei Wang
Liwei Wang on 23 Feb 2024
Commented: Matthew on 2 Apr 2024
Hi Community,
I encountered the following two problems using the audioPlayerRecorder object. I hope to display some processed variable based on input audio and provide audio alarming if such variable above a certain threshold. I followed instructions here: https://www.mathworks.com/help/audio/gs/real-time-audio-in-matlab.html Right now the audio processing is conducted in an infinite while loop. The code is roughly working however still have some issues
Problem 1): since the current procesing time is long. When running the code, the audio player queue always has some underruns. I do not know how to solve this. I tried Malab multi-threading while the performance is even worse
Problem 2) I tried to design a GUI for the existing code, when pressing the 'start' button, the code should run and real-time display the variable in the area speicifed by the GUI settings. However, when pressing the start button, the loop not conduct properly, should I use timer for such process?
Thank you in advance for any help.
Best,
Larry
  3 Comments
Liwei Wang
Liwei Wang on 8 Mar 2024
Hi Mario @Mario Malic, Thank you for your kind reply. Actually, I hope to build a system continuous conducting audio recording and playing (unless manually stopped by user). I use the AudioPlayerRecorde object. I noticed that when the processing algorithm is complex, the player part sometimes have underruns since whether I trigger the player function depends on the processing result of input audio. The player part just plays some beeping sound as alarm (generated by sine() function). It is strange as the player just plays some pre-generated tones while still have underruns. And The processing algorithm cannot be minimized. I am wondering is there any suggestions for solving this? (Maybe by decreasing the sampling rate?)
For the UI part, I tried to use the UI figure function. Is it possibe to permanently display the processing result (SNR value dots with lines between each dot)? Somes docs said a while() loop cannot be conducted by a buttonPressed() function?
Thank you in advance for any help.
Best,
Larry
Matthew
Matthew on 2 Apr 2024
Hi,
I am facing a similar issue. I am creating an application that plays real time audio and plots the spectrum with some other functions. Also using the AudioPlayerRecorder.
Here is a quick list of things I have tried that have not seemed to work:
  • Using the background thread or parallel processing toolbox. Unfortunately neither the AudioPlayerRecorder or the GUI can be pushed to a background thread, meaning that an update to the GUI results in an underflow in the audio.
  • Timer. I have a successful demo of using a timer to periodically play/record samples. However I've run into the same issue regarding underflows with GUI underflows. This solution works to a point, but does not scale as the GUI demands increase.
The big issue that I am facing is the fact that the AudioPlayerRecorder and anything to do with the GUI seems to fight over the same resource without an easy way to multithread the two operations.
I am open to all ideas to get this to work.
Thanks,
Matt

Sign in to comment.

Answers (0)

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!