Filter löschen
Filter löschen

Recorded Audio is Shorter than Expected

2 Ansichten (letzte 30 Tage)
XIWEN LI
XIWEN LI am 8 Mär. 2022
Beantwortet: jibrahim am 11 Mär. 2022
I am trying to use dsp tool box to do real-time audio recording. I use tic toc to time it. However, recorded audio is always shorter than desired time. I am wondering what might cause it. Here is my coded:
close all;
clear all;
clc
frameLength = 1024;
fs=48000;
audioFrameLength=1024;
fileWriter = dsp.AudioFileWriter( ...
'Filename', 'test_mic_array.wav', ...
'SampleRate',fs,...
'DataType','int32');
deviceWriter=audioDeviceWriter(...
'SampleRate', fs,...
'BitDepth','24-bit integer')
deviceReader = audioDeviceReader(...
'Device', 'miniDSP ASIO Driver',...
'Driver', 'ASIO', ...
'SampleRate', fs, ...
'NumChannels', 8 ,...
'SamplesPerFrame', audioFrameLength,...
'BitDepth', '32-bit float',...
'OutputDataType','int32');
setup(deviceReader)
scope = timescope( ...
'SampleRate',fs, ...
'TimeSpan',2, ...
'BufferLength',fs*2*2, ...
'YLimits',[-2^32,2^32], ...
'TimeSpanOverrunAction',"Scroll");
reverb = reverberator( ...
'SampleRate', 48000, ...
'PreDelay',0.5, ...
'WetDryMix',0.4);
% fprintf('Latency due to device buffer: %f seconds.\n',deviceReader.SamplesPerFrame/deviceReader.SampleRate)
disp('Recording now.')
tic
while toc < 20
acquiredAudio = deviceReader();
acquiredAudio=bitshift(acquiredAudio,10);
scope(acquiredAudio)
deviceWriter(acquiredAudio);
fileWriter(acquiredAudio);
end
disp('Recording complete.')
release(fileWriter)
release(deviceReader)
release(deviceWriter)
release(reverb)
release(scope)

Akzeptierte Antwort

jibrahim
jibrahim am 11 Mär. 2022
Hi Xiwen,
I suspect the scope is taking a long time to set up the first time you call it.
Consider adding this code outside of the for loop to remove this overhead:
setup(scope,zeros(frameLength,1,'int32'))
scope.show

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by