Simultaneous Recording and Reprodction of a File in MATLAB

7 次查看(过去 30 天)
I'm currently working on my undergraduate thesis, which consists on an assisted reverberation system for a small auditoria and got stuck while trying to record a file and play it while it's still in the recoring process. I was wondering if somebody could help me get pass this inconvienience.
I have to get audio from an external sound card, proccess it and play it into a speaker system in real time.
Thanks.

回答(4 个)

Daniel Shub
Daniel Shub 2011-3-24
If you want to start playback and recording at the same time, this is really going to depend on your sound card and OS. Cheap sound cards sometimes do not lock the playback and recording clocks, but mid level and above cards do. Assuming your sound card supports what you are trying to do, look for a MATLAB based implementation of port audio that supports both playback and recording. Both Psych Toolbox and PAWAVPLAY are implementations of port audio, but I am not sure recording is implemented. Assuming Windows, based on comments about the Data Acquisition toolbox, you would need an ASIO compatible sound card to use port audio.

Walter Roberson
Walter Roberson 2011-3-23
The facilities in the Data Acquisition Toolbox would be most natural for that. You would use analoginput() to add a 'winsound' device, set() the sample rate and number of channels, getdata() to receive samples, and process them. To output, you would first analogoutput() a 'winsound' device and set() the parameters for it, and then at time of output, putdata() the samples.
  2 个评论
Felipe Tavera
Felipe Tavera 2011-3-24
Thanks Walter, already got a pretty basic setup running. However, as it's not possible to trigger both, the analog input and output at the same time, i'm having problems with the latency and, i'm only guessing it's going to get worse as I write the processing code for the recorded audiowave, Have you got any recommendations to reduce the recording vs. playback latency in order for it to appear in real time? (i'm looking for a latency below the integration period of the human ear, something below 50ms).
You've been a huge help.
Thank you.
Walter Roberson
Walter Roberson 2011-3-24
Sorry, I do not have the Data Acquisition Toolbox (and I run Matlab off a server anyhow.) Perhaps one of the DAQ people will have some suggestions.
Generally speaking, using Matlab for real-time work is hard unless you are using the Real Time Workshop on a target machine. Though I understand that some of the Simulink modules can get pretty close -- and probably the system you describe would be pretty easy to model in Simulink.
The best collection of routines that I know of for near real time work are the Psychometric Toolbox, http://psychtoolbox.org/PTB-2/intro.html . Although it is intended for vision, it has routines intended for synchronizing sound and vision, which is difficult in Matlab; you might be able to get some valuable clues from their code.

请先登录,再进行评论。


Daniel Shub
Daniel Shub 2011-3-24
Assuming you have a channel to spare on your sound card you can set up a loop back to compensate for the latency. You can push a pulse out the loop back channel and measure the latency. Once the latency is known you should be able to adjust you "indices" for the playback and recording.

Felipe Tavera
Felipe Tavera 2011-5-24
Although Walter's answer got me in the right direction, I never could get the simultaneous recording and reproduction running from the data acquisition toolbox. I tried also by recording first little chunks and them play them back, but still got a lot of latency and the sound quality was nowhere near acceptable.
I finally changed my workspace to simulink were i've managed to make everything (so far) work as i need it to. I solved my problem by just joining the 'from audio device' and the 'to audio device' blocks together (and putting all of the processing blocks in the middle) and realizing that, as my intention was to process the input signal and play it back in realtime, i wasn't in the need to record any of the data that went through my system.
Regarding latency i struggled with it quite a bit, and never got it as fast as i wanted to, so, i'm currently using a TI DSP card from the university; which solved any kind of latency problem.
Hope this answer works, although technically, the recording proccess was left aside.
Thanks to everyone that wrote on my question, every input helped me in getting to the result I am currently in.

类别

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