Real time audio input, audio output
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dong-uk Hyon
el 25 de Feb. de 2018
Comentada: Walter Roberson
el 26 de Feb. de 2018
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 25 de Feb. de 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"
2 comentarios
Walter Roberson
el 26 de Feb. de 2018
For continuous work, the possibilities are:
- audio system toolbox; https://www.mathworks.com/help/audio/gs/real-time-audio-in-matlab.html
- dsp toolbox (some functionality overlaps with audio system toolbox); https://www.mathworks.com/help/dsp/ref/audiodevicewriter-system-object.html
- data acquisition toolbox with a board that does digital to analog and is connected to an amplifier and speaker
- instrument control toolbox, at least hypothetically; you might have difficulty finding a suitable device, and lag could be a problem
- interfacing to an external device such as arduino or raspberry pi -- but remember that they are asynch devices and response time to/from them is variable.
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!