Discussion:
Question for converting 8bit to 16bit wav?
(too old to reply)
Frank
2004-02-22 03:29:05 UTC
Permalink
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 |
+-----------------------------------------+
Alessandro Angeli [MVP::DigitalMedia]
2004-02-22 14:16:50 UTC
Permalink
Post by Frank
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
*/
Frank
2004-02-23 01:00:17 UTC
Permalink
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
Post by Alessandro Angeli [MVP::DigitalMedia]
Post by Frank
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
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]
2004-02-23 13:44:34 UTC
Permalink
Post by Frank
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?
Post by Frank
Frank
"Alessandro Angeli [MVP::DigitalMedia]"
Post by Alessandro Angeli [MVP::DigitalMedia]
Post by Frank
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
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
*/
tjfoe
2010-12-19 12:22:47 UTC
Permalink
Alessandro Angeli [MVP::DigitalMedia] wrote on 02/22/2004 09:16 ET
Post by Alessandro Angeli [MVP::DigitalMedia]
Post by Frank
Hi, al
Fro some reason,I need use Lame mp3 encoder to conver
wav to mp3, But Since Lame only receive 16bit Raw wav
data so that I got a issue that how to convert 8bit wa
file to 16bit wav file, or say that how to convert 8bi
Raw Wave data to 16bit Raw Wave data. Many thanks =
Actually, Lame 3.95.1 should support 8-bit PCM streams, bot
raw (specifying the bit-width with the --bitwidth switch) o
wrapped in a RIFF/WAV structure (which is practically
WAVEFORMATEX structure followed by the raw stream)
If you still want to do the conversion yourself, here is
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 her
/// if output_file is a WAV and not raw
/// write the empty header her
while(!eof(input_file))
fread(input,sizeof(PCM8),BUFFER_LENGTH,input_file)
for(int i = 0; i &lt; BUFFER_LENGTH; i++)
output[i] = ((PCM16)input[i] - 128) &lt;&lt; 8
fwrite(output,sizeof(PCM16),BUFFER_LENGTH,output_file)
/// if output_file is a WAV and not raw
/// write the filled header her
/*
* Alessandro Angel
* MVP::DigitalMedi
* a dot angeli at biosys dot ne
*
Hi

I want to bring 24 Bit to 32 Bit signed long for playing 24/96 wav with my 3
Bit library. Could you please tell me, what I have to put in for &quot;x&quot
and &quot;y&quot; (below)

output[i] = ((PCM32)input[i] - x) &lt;&lt; y

May be you could give me any link to understand these numbers :-)

Thanks a lot
Regard
Thomas

Loading...