Clear Filters
Clear Filters

Need help about function

1 view (last 30 days)
moonman
moonman on 19 Sep 2011
I have written this function for piano
function tone=note(keynum,dur) % %This function produces sinusoidal waveform corresponding to given piano %key number %tone=output sinusoidal waveform %keynum= The piano keyboard number %dur= The duration in seconds of output note fs=8000; tt=0:(1/fs):dur; freq = 440 (2^((keynum-49)/12)); tone=sin(2*pi*freq(0:0.000125:1));
Now If i use soundsc(tone,fs) command in the code of this function then every thing is ok but the book says
"You can play the output of this function using the soundsc() function in Matlab. DO NOTcall the sound fucntion within the M-file.
Plz help me how to go about this. when i write note(12,3) in matlab it is ok but when i write soundsc(tone,fs) in matlab after this it gives error

Accepted Answer

Wayne King
Wayne King on 19 Sep 2011
How are you calling the function, note(), at the command line?
You should call it as:
tone = note(12,3);
Then there will be a variable in your workspace named tone and you can execute
soundsc(tone,fs)
If you call it as
note(12,3)
then your output appears as ans
Wayne
  1 Comment
moonman
moonman on 19 Sep 2011
Thanks a lot King, u r true Guru of Matlab

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!