Can someone please explain how this function? It is for simultaneously recording with the input(X) being white noise at FS 44100hz
2 次查看(过去 30 天)
显示 更早的评论
function recording = audioOI(x,fs)
% audioOI - Simulataneously plays and records the test signal.
% Uses Parallel Computing Toolbox.
% INPUT: x - test signal
% fs - sampling frequency
% OUTPUT: y - recorded signal
time = length(x)/fs; % play/record time
recObj = audiorecorder(44100,16,2);
parfor ii = 1:2
if ii==1
recordblocking(recObj, time);
recording{ii} = getaudiodata(recObj);
elseif ii==2
soundsc(x, fs);
end
end
0 个评论
回答(2 个)
Hari
2025-2-18
编辑:Walter Roberson
2025-2-19
Hi,
I understand that you are looking for an explanation of the "audioOI" function, which is designed to simultaneously play and record a test signal, with the input signal being white noise at a sampling frequency of 44100 Hz.
Here is the explanation for the important steps:
Setup and Initialization:
The function calculates the duration of the signal based on its length and sampling frequency. It then initializes an "audiorecorder" object to record audio at 44100 Hz, 16-bit depth, and 2 channels (stereo).
time = length(x) / fs; % Calculate the duration of the signal
recObj = audiorecorder(44100, 16, 2); % Initialize the recorder
Parallel Execution:
The parfor loop is used to run two operations simultaneously. This requires the "Parallel Computing Toolbox".
parfor ii = 1:2
% Parallel loop for simultaneous operations
end
Recording Operation:
If the loop index ii is 1, the function records audio for the specified duration using recordblocking. The recorded audio data is then retrieved and stored in the recording cell array.
if ii == 1
recordblocking(recObj, time); % Record audio
recording{ii} = getaudiodata(recObj); % Retrieve audio data
Playback Operation:
If the loop index ii is 2, the function plays the input signal x using soundsc, which scales the audio for playback.
elseif ii == 2
soundsc(x, fs); % Play the input signal
end
Output:
The function returns the recorded signal stored in the recording variable. This allows you to analyze the recorded audio after playback and recording have completed.
Refer to the documentation of "audiorecorder": https://www.mathworks.com/help/matlab/ref/audiorecorder.html and "parfor": https://www.mathworks.com/help/parallel-computing/parfor.html for more details on these functions.
Hope this helps!
0 个评论
Walter Roberson
2025-2-19
These days, since R2017a, the provided code should be replaced. Instead the provided code should use audioPlayerRecorder https://www.mathworks.com/help/audio/ref/audioplayerrecorder-system-object.html which provides streaming services for simultaneously playing a sound and recording input.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!