How to remove header of a wavfile in Matlab

2019-05-05 08:04发布

问题:

I need to remove first 1024 bytes of a wave file. I tried to do but I got corrupted/distorted wavfile:

wavFile = fopen(fullFileName, 'r'); % Open file for reading 
fseek (wavFile, 1024, -1);% Skip past header, which is 1024 bytes long.
wF = fread (wavFile, inf, 'int16');% 16-bit signed integers
wF = wF(:)';
newWavFile = fopen(strcat('new_',fileNames(fileNo).name), 'w+');% Open file for reading
fwrite(newWavFile,wF);
fclose(wavFile);

What can be the problem?

回答1:

I could manage to remove header and correct the distortion by :

            wavFile = fopen(fullFileName, 'r');% Open file for reading 
            fseek (wavFile, 1024, -1);% Skip past header, which is 1024 bytes long.
            wF = fread (wavFile, inf, 'int16');% 16-bit signed integers
            wF = wF(:)';
            wF = 0.8*wF/max(abs(wF));
            newWavFile =strcat('1_',fileNames(fileNo).name);% Open file for reading
            wavwrite(wF,16000,16,newWavFile);