Latency issue when using DSP System Toolbox for Real-Time audio processing

3 views (last 30 days)
Trying to make a real-time audio processor which performs pitch detection and pitch shifting, but setting up the basic audio in - audio out is causing trouble as the latency is massive. The basic code is as follows;
Fs = 44100;
nbits = 16;
buffSize = 516;
if (audiodevinfo(1,0,Fs,nbits,2) == 1)
fprintf('Audio input device found\n');
else
fprintf('No audio input device found\n')
return
end
Speaker = dsp.AudioPlayer('SampleRate',Fs);
WavWriter = dsp.AudioFileWriter('myspeech.wav','FileFormat', 'WAV');
Microphone = dsp.AudioRecorder('SampleRate',Fs, ...
'NumChannels',2, ...
'BufferSize',buffSize, ...
'QueueDuration',0.0, ...
'SamplesPerFrame', buffSize);
tic;
while(toc<5)
audioIn = step(Microphone);
step(Speaker, audioIn);
step(WavWriter,audioIn);
end
fprintf('Recording complete\n')
end
release(Microphone);
release(Speaker);
release(WavWriter);
It records and plays fine, but the latency is over 1 second long. I'm guessing, the cause is most likely due to the warning I get; "Warning: The BufferSize property is not relevant in this configuration of the System object." I'm also guessing that the QueueDuration property is "not relevant" too, and its resetting to its default which is a delay of 1.0 (I think). I'm working with Matlab 2011 (which doesn't support ASIO btw, so I'm using the directsound ins/outs).
Any help with this issue or suggestions for a different approach would be hugely appreciated. Thanks a mil. Mark

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!