Real time audio input, audio output

21 views (last 30 days)
Hello everyone,
I am involved in a project that listens to audio in using a microphone, which is then immediately outputted via a speaker. The emphasis is on using continuous audio in, from a microphone, to continuous audio out to a speaker.
The end goal, would be to add a delay function in-between the audio received, and to the audio outputted. To almost act as an audio delayer.
From my very basic understanding; sound amplitude is recorded at certain time intervals at a certain frequency, called the sampling rate. This is how the analog signal is converted to a digital signal which a computer can process. This amplitude is then stored in a 1 x n array. Where n is the sample frequency x length of recording. Is there a method of outputting the amplitudes that the microphone has received, which are stored in the array? And if I am to apply a time delay, I would calculate the desired delay time, and then multiply it by the sampling frequency, and offset the output by this number of values?
I am using the data acquisition toolbox, that has instructed me to creating a continuous audio input. linked here: https://uk.mathworks.com/help/daq/examples/getting-started-acquiring-data-using-audio-in-session.html I now need to work out how and where the amplitudes are stored, and output these to an audio driver.
Any help would be greatly appreciated.
Many thanks,
Don

Accepted Answer

Walter Roberson
Walter Roberson on 25 Feb 2018
"This amplitude is then stored in a 1 x n array."
Close, but traditionally the data is stored in an N x C array, where N is the number of samples and C is the number of channels. For one channel this is the transpose of what you wrote.
"Is there a method of outputting the amplitudes that the microphone has received, which are stored in the array?"
Sure, once they are in MATLAB they are just numbers and you can display them or plot them.
"And if I am to apply a time delay, I would calculate the desired delay time, and then multiply it by the sampling frequency, and offset the output by this number of values?"
That is one method, that is valid to within 1/fs seconds. But sometimes a higher resolution is desired, and in that case other methods need to be used.
"I now need to work out how and where the amplitudes are stored"
Look at the lines
plotFFT = @(src, event) helper_continuous_fft(event.Data, src.Rate, hp);
hl = addlistener(s, 'DataAvailable', plotFFT);
This says that every time data is available, that plotFFT is to be called with parameters src and event, and that event.Data will have the actual data input.
"and output these to an audio drive"
For this kind of work you should consider a different approach: use the Audio System Toolbox
  2 Comments
Dong-uk Hyon
Dong-uk Hyon on 26 Feb 2018
Thanks for your reply Walter,
Would you be able to recommend any codes that will allow to me record continuous audio in, and output this data to a speaker? or is it necessary to have Audio System Toolbox for this? If the output to a speaker is not possible, could you recommend a graphic output of these values?
Thanks very much for your help.
kind regards, Don
Walter Roberson
Walter Roberson on 26 Feb 2018
For continuous work, the possibilities are:
Note: for this purpose you should probably avoid using a DAQ with USB connector: USB packetizes data, making it difficult to get sample-level timing precision.

Sign in to comment.

More 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!