Page 1 of 1

amplifying an audio signal

PostPosted: September 18th, 2009, 8:11 am
by stef
hello,

On laptops, the recorded sound is often too weak.
So when I playback a recorded sound, I want to give the signal some extra gain.
Without knowing too many details about Wave Audio Package (and streams)
(other than that it's great package ;-)
I wrote the code below,
which give a read stream error.

Can anyone give me simple solution ?
(it concerns small audio snippets, so they always fit in the array "display_ar")

thanks,
Stef Mientki

Nsamp := WaveStorage_part.Wave.DataSize ; //length in bytes
Nsamp:=Nsamp div 2;

WaveStorage_part.Wave.BeginRead;
WaveStorage_part.WaveStream[0].ReadBuffer( display_ar, 2*Nsamp); // in bytes
WaveStorage_part.Wave.EndRead;

for i:= 0 to NSamp-1 do
display_ar[i] := 10 * display_ar[i] ;

WaveStorage_part.Wave.BeginRewritePCM (WaveStorage_part.Wave.PCMFormat);
WaveStorage_part.WaveStream[0].WriteBuffer( display_ar, 2*Nsamp); // in bytes
WaveStorage_part.Wave.EndReWrite;

WaveStorage_part.Wave.BeginRead;
WaveStorage_part.WaveStream[0].ReadBuffer( display_ar, 2*Nsamp); // in bytes
.... In the above line I get a stream read error
WaveStorage_part.Wave.EndRead;

Re: amplifying an audio signal

PostPosted: September 18th, 2009, 1:43 pm
by Kambiz
Simply use ChangeVolume method of TWaveStreamAdaptor class.

For example, the following line of code increases the volume by 50%:

WaveStorage_part.Wave.ChangeVolume(50);

Re: amplifying an audio signal

PostPosted: September 18th, 2009, 2:16 pm
by stef
thanks Kambiz,

unbelievable how simple (sometimes) things can be.

cheers,
Stef