Question for converting 8bit to 16bit wav?

22/02/2004 - 04:29 por Frank | Informe spam
Hi, all

Fro some reason,I need use Lame mp3 encoder to convert wav to mp3, But Since
Lame only receive 16bit Raw wave data so that I got a issue that how to
convert 8bit wav file to 16bit wav file, or say that how to convert 8bit Raw
Wave data to 16bit Raw Wave data. Many thanks =)

Frank F.Han

+--+
| winsays@:-)hotmail:-).com |
+--+
 

Leer las respuestas

#1 Alessandro Angeli [MVP::DigitalMedia]
22/02/2004 - 15:16 | Informe spam
Frank wrote:

Hi, all

Fro some reason,I need use Lame mp3 encoder to convert
wav to mp3, But Since Lame only receive 16bit Raw wave
data so that I got a issue that how to convert 8bit wav
file to 16bit wav file, or say that how to convert 8bit
Raw Wave data to 16bit Raw Wave data. Many thanks =)



Actually, Lame 3.95.1 should support 8-bit PCM streams, both
raw (specifying the bit-width with the --bitwidth switch) or
wrapped in a RIFF/WAV structure (which is practically a
WAVEFORMATEX structure followed by the raw stream).

If you still want to do the conversion yourself, here is a
fragment of non-optimized C code to get you started:



typedef signed short PCM16;
typedef unsigned char PCM8;

PCM16 output[BUFFER_LENGTH];
PCM8 input[BUFFER_LENGTH];

/// if input_file is a WAV and not raw,
/// skip the header here

/// if output_file is a WAV and not raw,
/// write the empty header here

while(!eof(input_file)) {
fread(input,sizeof(PCM8),BUFFER_LENGTH,input_file);
for(int i = 0; i < BUFFER_LENGTH; i++) {
output[i] = ((PCM16)input[i] - 128) << 8;
}
fwrite(output,sizeof(PCM16),BUFFER_LENGTH,output_file);
}

/// if output_file is a WAV and not raw,
/// write the filled header here




/**
* Alessandro Angeli
*
* MVP::DigitalMedia
*
* a dot angeli at biosys dot net
*/

Preguntas similares