# matlab - DSP Audio Function Block to Audio Output

DO IT by the Mask option of the context menu of the block by right-click mouse button. and input the text like   disp('Metropolis Hastings/n(MH) sampl

up vote 0 down vote favorite I have a simulink block which takes a function from matlab and takes the output of that as an input to the "To Audio Device" diagram. The error I get with this is Port Audio: Invalid number of channels..So I added the variable H to record audio with the DSP.AudioRecorder, but I can't set that as an output H = fcn() .. So main question is what's the simplest way to do this because I'm pretty lost right now. Thanks! The following code I have is:

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

|
this question asked Sep 18 '13 at 14:55 user1819301 68 3 13

up vote 0 down vote "To Audio Device" block considers each column as a channel. You should transpose your data y before returning as output from fcn. Currently you are getting the error because you have a row vector as y and each sample in this row vector is being considered a separate channel.
|
this answer answered Sep 19 '13 at 18:46 Navan 3,931 1 17 19

|

up vote 0 down vote favorite I have a simulink block which takes a function from matlab and takes the output of that as an input to the "To Audio Device" diagram. The err

×
• 登录
• 注册

×