How can I check if AudioDeviceWriter is currently playing?

2 Ansichten (letzte 30 Tage)
I'd like to use the audioDeviceWriter object directly from a workspace variable instead of using an audioFileReader. At first, it appears that this should be possible using a regular frame loop, but because the audio is buffered in, the loop ends before playback has finished and the device is released. Typically, the "isDone" function is used with an audioFileReader to finish playback, but in this case, I can't seem to find a property that I can check to manually determine if playback has stopped. Additionally, I don't want to assume that beginning a timer before the frame loop begins and stopping after a given amount of time will work given the variance in time to acquire the device and begin playback. Ideally, this method would also work for an audioPlayerRecorder to use workspace variables for output and input without having to write to files.
% Note the use of a workspace variable instead of AudioFileReader
load handel
deviceWriter = audioDeviceWriter('SampleRate',Fs);
framesize = deviceWriter.BufferSize;
nframes = ceil(length(y)/framesize);
for i = 1:nframes
begSamp = 1 + framesize*(i-1);
endSamp = framesize*i;
if endSamp > length(y), endSamp = length(y); end % Avoid outOfBounds error
playFrame = y(begSamp:endSamp);
if length(playFrame) < framesize % End of workspace variable
playFrame(framesize) = 0; % Pad with zeros to match the frame size
pause % Must pause in order to wait for the audio to finish
% Ideally, could instead use a function checkIfDone(deviceWriter) that returns when playback is complete
break
end
deviceWriter(playFrame);
end
release(deviceWriter);
If that isn't possible with the current architecture, that would also be useful to know. Thanks in advance!

Akzeptierte Antwort

Aidan Meacham
Aidan Meacham am 1 Okt. 2019
Bearbeitet: Aidan Meacham am 1 Okt. 2019
The solution to this problem (assuming your soundcard supports it) is to use AudioPlayerRecorder and ignore the recorded signal instead of trying to use audioDeviceWriter with a variable. This is not very clear in the documentation for audioDeviceReader and audioDeviceWriter, and I am not sure what I was trying to do above is in fact possible with the current architecture. For now, I would only use the audioDeviceWriter when you have an audioFileReader to go with it.
In any case, I recommend looking through the code for the impulseResponseMeasurer app included in the Audio Toolbox for inspiration on this topic. Below is a good place to get started.
edit audio.irapp.model.ImpulseResponsePlayerRecorder

Weitere Antworten (0)

Kategorien

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

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by