Sunday, January 9, 2011

Generating sine wave tone using Scilab

Scilab is a powerful numerical software. It has different sound handling functions. The following code (as a demonstration) can generate a sine wave tone with different parameters that can be controlled (frequency, tone length, and amplitude). The code also enables you to save the sound file as a wave file.
As a concept, you can also use Scilab to generate noise waves like saw tooth, step, impulse, etc. and then you can say bye bye to all tone generator software.

Here you are the code

//Generating sine wave tone toolbox

txt=['Length in seconds';'Frequency';'Amplitude'];
parameters=x_mdialog('Enter wave properties',txt,['10';'10000';'1']);
frequency=evstr(parameters(2));     //tone frequency
size_x=frequency*evstr(parameters(1));     //number of bits
A=evstr(parameters(3));     //Wave amplitude
y=A*[sin(x);sin(x)];     //sine wave for both left and right channels
file_save=uiputfile("*.wav");     //Saving the wave file
wavwrite(y,frequency, 8,file_save+'.wav')     //Writing the wave file

And this is apture for the toolbox