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 |
+--+

Preguntas similare

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
*/
Respuesta Responder a este mensaje
#2 Frank
23/02/2004 - 02:00 | Informe spam
Hi, Alessandro :p

Really really many many thinks! That's very kind of you. Thanks your reply,
thanks your time... You got so big help to me :p Thank you, and if you got
some more time, could you tell why(I wanna learn more) =)

Frank



"Alessandro Angeli [MVP::DigitalMedia]"
:OEoNJ9U#
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
*/


Respuesta Responder a este mensaje
#3 Alessandro Angeli [MVP::DigitalMedia]
23/02/2004 - 14:44 | Informe spam
Frank wrote:

Hi, Alessandro :p

Really really many many thinks! That's very kind of you.
Thanks your reply, thanks your time... You got so big
help to me :p Thank you, and if you got some more time,
could you tell why(I wanna learn more) =)




why what?




Frank



"Alessandro Angeli [MVP::DigitalMedia]"

OEoNJ9U#
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
*/






/**
* Alessandro Angeli
*
* MVP::DigitalMedia
*
* a dot angeli at biosys dot net
*/
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida