The
matlab .m file listed below will take an input .wav file, scale the
file up or down by x dB and write an output file .wav file.
The
routine will not produce an output file if scaling produces values > 1 or
<-1 since these produce clipping in a .wav file
For an
input file named "truth.wav" you would get an output file,
"truth-3.wav" scaled down by 3 dB with the
syntax:
change_wavefile_db('truth.wav','truth-3.wav',-3)
Of
course you should test the routine yourself before using it.
Van
Summers
202
782 8585
function change_wavefile_db(infile,outfile,dbchange)
%change_wavefile_db(infile,outfile,dbchange)
[origwave,fs,bits]=wavread(infile);
orig_rmslin
= sqrt(mean(origwave.^2));
orig_rmsdb =
20 .* log10(sqrt(mean(origwave.^2)))
new_rmslin=10^((orig_rmsdb+dbchange)/20);
newwave=origwave.*(new_rmslin/orig_rmslin);
new_rmsdb =
20 .* log10(sqrt(mean(newwave.^2)))
max_mag =
max(abs(newwave));
if max_mag >
1
display('WITH
SCALING MAX MAGNITUDE > 1, .WAV WOULD CLIP, NO OUTPUT FILE CREATED
!!!')
else
wavwrite(newwave,fs,outfile);
end
|