Audio streaming in MATLAB using Audio system toolbox

2 次查看(过去 30 天)
I am using the Audio System Toolbox to stream audio data in real-time. I followed the below to have some good understanding before the implementation: 1. https://www.mathworks.com/help/audio/gs/real-time-audio-in-matlab.html 2. https://www.mathworks.com/videos/real-time-audio-processing-for-algorithm-prototyping-and-custom-measurements-121075.html
So what I able to achieve is: 1. Created a 1D sample array of the sine wave 2. Generated an audio file(.wav) using that array 3. And collected frame after frame from the audio file and push it to the buffer for real-time audio processing.
And this works fine for me without any glitches. But what I would like to do is: While reading from the file and playing it, keep on pushing new data to the file.
How could I achieve that? Here is my code snippet:
freq =1e-2;
n=(1:40000);
y = (sin((2*pi*freq).*n)+cos(((2*pi*freq).*n))+pi)/2;
% Define audio file sampling rate
Fs = 44100; % Audiowrite supports only samples rates of 44100 and 48000
nBits = 24;
filename = 'music.wav';
audiowrite(filename, y, Fs,'BitsPerSample', nBits);
frameLength = 256; % Number of samples peer frame
fileReader = dsp.AudioFileReader(filename, 'SamplesPerFrame',frameLength);
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);
% AUdiostream Loop
while ~isDone(fileReader)
signal = fileReader();
deviceWriter(signal);
end
% Release the system object
release(fileReader);
release(deviceWriter);
Appreciate your help.

回答(0 个)

类别

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