I am trying to simultaneously playback and record a chirp signal. No sound is coming from my speakers. I pretty much copied the exampled from the matlab docs...
2 views (last 30 days)
Show older comments
% Test signal generation
frameSize = 1024;
Fs = 44100;
t = 0:1/Fs:1; % Time vector for 1 second
testSignal = chirp(t, 20, t(end), 20000); % Sweep from 20 Hz to 20 kHz
testSignal = testSignal(:);
% Write the test signal to a WAV file
audiowrite('testChirp.wav', testSignal, Fs);
% Read the test signal from the file
fileReader = dsp.AudioFileReader('testChirp.wav', 'SamplesPerFrame', frameSize);
fs = fileReader.SampleRate;
% Initialize audioPlayerRecorder
aPR = audioPlayerRecorder('SampleRate', fs);
% Initialize file writer for the recorded signal
fileWriter = dsp.AudioFileWriter('recordedOutput.wav', 'SampleRate', fs);
% Play and record the test signal
while ~isDone(fileReader)
audioToPlay = fileReader();
[audioRecorded, nUnderruns, nOverruns] = aPR(audioToPlay);
fileWriter(audioRecorded);
% Handle underruns and overruns
if nUnderruns > 0
fprintf('Audio player queue was underrun by %d samples.\n', nUnderruns);
end
if nOverruns > 0
fprintf('Audio recorder queue was overrun by %d samples.\n', nOverruns);
end
end
% Release system objects
release(fileReader)
release(fileWriter)
release(aPR)
2 Comments
Walter Roberson
on 13 Nov 2023
Edited: Walter Roberson
on 13 Nov 2023
I observe the same behaviour on my (intel) Mac.
Testing, if I use audioDeviceWriter then I do get sound output.
Answers (0)
See Also
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!