How do I play and record audio at the same time?

So this question is more related to Matlab itself.

Some background info: I'm trying out the Exponential Sine Sweep method to obtain the Room Impulse Response with my laptop speakers and microphone for testing.

I can generate the Sine sweep perfectly but I have trouble playing and recording it without a lot of lag. I'm now trying to use "audioPlayerRecorder" from the Audio System Toolbox but when I do:

f1 = 80;       % Start frequency (Hz)
f2 = 22000;    % Stop frequency (Hz)
T = 3;         % Sweep duration in seconds
fs = 44100;    % Sampling frequency

[sweep, inverse] = ESS_generator(f1, f2, T, fs);

playRec = audioPlayerRecorder(fs);
recording = playRec(sweep);


I get an error on the last line saying: Error using coder.internal.assert (line 33) No full-duplex audio device detected

But I know that my laptop is able to use the microphone and speakers simultaneously so I'm thinking maybe the error gets thrown because of a missing configuration?

I'm running the code on Linux with the ALSA audio drivers. I'm using external speakers through the AUX audio port, and the default laptop microphone.

• I don't know if Matlab is capable of doing that. What I have done in the past is to use Matlab to play the sound, while another process (sox in my case) does the recording. – MBaz Feb 14 at 17:20
• May be simulink could do that (simultaneous playback and recording)? have you checked its documentation as well ? – Fat32 Feb 15 at 23:17
• @MBaz , How 'real-time' is this method? Since I assume you have a delay between the playing the audio using matlab and starting the recording. – Mistergrave Feb 17 at 13:18
• @Fat32, I'll check this out. Thanks! – Mistergrave Feb 17 at 13:18
• @Mistergrave It is real time in the sense that both streams are playing at the specified sampling rate. There is of course a delay, but that is unrelated to the system being 'real time". See this paper for more details: ieeexplore.ieee.org/document/5739249 – MBaz Feb 17 at 17:13