scilab - sounds
TRANSCRIPT
Utility Software II lab 9 Jacek Wiślicki, [email protected]
SCILAB – SOUNDSScilab offers many utilities for signal generation and processing. The following exercises concentrate on sounds.In order to generate a sound (a wave) use the code as bellow:
// At first we create 0.5 seconds of sound parameters.t=soundsec(0.5);// Then we generate the sound.s=sin(440*t)+sin(220*t)/2+sin(880*t)/2;[nr,nc]=size(t);s(nc/2:nc)=sin(330*t(nc/2:nc));// We can easily make a Fourier analysis of it.analyze(s);
The result of the code is a 0.5 s long wave with the frequencies of 440, 220 and 880 Hz and its spectral analysis (Fourier) reveals:
In order to hear the signal save it to a file (test.wav). The signal can be also reloaded and visualized:// Save the file in WAV format.// we renormalize s in order to check that save+load is invariants=s-sum(s)/prod(size(s));s=s/max(abs(s));savewave("test.wav",s);// Load it back.s1=loadwave("test.wav");if maxi(abs(s1-s)) < 1.e-4; end// Now we can make a complete picture of the sound.mapsound(s);
Exercise 1 (5 points)Write a function enabling generation of a single-frequency wave of a given duration:
note(frequency, duration)
page 1 of 2
Utility Software II lab 9 Jacek Wiślicki, [email protected]
Calling the function note should result in saving the sound to a .wav file named according to a pattern: frequency_duration.wav, e.g. note(400, 1.5) generates a file 400_1.5.wav. Generate a basic octave sounds (e.g. 0.5 s long) according to their frequencies presented in the table:
sound frequency [Hz]c1 261,6d 293,7e 329,6f 349,6g 391,9a 440,0h 493,9c2 523,2
Exercise 2 (15 points)Rewrite the function from the previous exercise so that it takes one more argument delay denoting the delay of sound beginning. The function should return a sound wave. Write another function player combining the octave waves (properly delayed) into a melody according to the notes:
g e e f d d c1 e gg e e f d d c1 f c1
The final melody should sound like: http://jacenty.kis.p.lodz.pl/utility_software_ii/melody.mp3.Hint: there may be need to increase a stack size in order to process the waves.
page 2 of 2