could you help me with generation audio signal with such a parameters:
- sample rate = 8000 Hz,
- mono,
- 16-bits per sample.
I need write samples to file without any header, in little-endian representation with sign (LSB,MSB). E.g. if sample has value 32767 (it is maximum in this representation) then it will be saved as 0xFF7F.
This signal should contain couple of tones. I have such a code for generating tones:
frequency = 2000;
duration = 2;
amplitude = 1;
sampleFreq = 8000;
t = linspace( 0, duration, duration * sampleFreq );
s = amplitude * sin( 2 * pi * frequency * t ) + amplitude * sin( 2 * pi * frequency/2 * t ) + amplitude * sin( 2 * pi * frequency*2 * t );
It creates vector (mono) with 8000 Hz sample rate. But I don’t know how to write samples in 16-bits with LSB,MSB convention.
Regards.
you can either use wavewrite or audiowrite.
wavwrite(s,filename)writes the data stored in the variablesto a WAVE file calledfilename. Thefilenameinput is a string enclosed in single quotes. The data has a sample rate of 8000 Hz and is assumed to be 16-bit.If there an endianess issue, you can format the big-endian output into little-endian (and vice versa) using the swapbytes function, i.e.
s = swapbytes(s)you can remove the header using the following SO answer