我有一个 simulink 块,它从 matlab 中获取一个函数,并将其输出作为“到音频设备”图的输入。我得到的错误是 Port Audio: Invalid number of channels..所以我添加了变量 H 以使用 DSP.AudioRecorder 录制音频,但我不能将其设置为输出 H = fcn() .. 所以主要问题是最简单的方法是什么,因为我现在很迷茫。谢谢!
我拥有的以下代码是:
function y = fcn()
%#codegen
Fs = 125; %# Samples per second
toneFreq = 50; %# Tone frequency, in Hertz
nSeconds = 2; %# Duration of the sound
y = sin(linspace(0, nSeconds*toneFreq*2*pi, round(nSeconds*Fs)));
coder.extrinsic('sound');
coder.extrinsic('audiowrite');
H = dsp.AudioRecorder('DeviceName','Default', 'SampleRate', 48000, 'BufferSizeSource', 'Property', 'BufferSize', 512, 'NumChannels', 2);
step(H);
sound(y, Fs); %# Play sound at sampling rate Fs
audiowrite(y, Fs, 8, 'tone_50Hz.wav'); %# Save as an 8-bit, 1 kHz signal