Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

How to interpret WAV data?

0 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Peter Reichard

ungelesen,
18.05.2005, 08:07:1518.05.05
an
Hi,

I am writting a program to draw a sample curve. I have read some online
documents about the WAV formate, however, my curve doesn't look like in
other sample editors.

If I have a 8bit mono sample, one article described that the data is saved
like:

channel 0 | channel 0 | channel 0
[BYTE] [BYTE] [BYTE]

The range for each value is therefore 0-255 (128 means zero). However, an
other article says that each channel ist stored as an integer. For me, that
means 2 bytes, like:

channel 0 | channel 0 | channel 0
[BYTE][BYTE] [BYTE][BYTE] [BYTE][BYTE]

Because it has the same range (0-255), it would be a waste of memory and
only applicable for 16bit mono samples. What is the correct storage scheme?

Thanks


Iain

ungelesen,
18.05.2005, 10:27:0818.05.05
an

You can find the format for wavs in the MSDN documentation.

Basically there is a preamble then a format descriptor (which tells you how
many bits per sample among other things).

then there is a sized chunk of data.

If you know that your data is 8 bit mono, it will be stored as a sequence
of signed bytes.

If it were 16 bit stereo it would be stored as pairs of signed shorts.

Iain
--
Iain Downs (DirectShow MVP)
Software Product Consultant
www.idcl.co.uk

Alessandro Angeli [MVP::DigitalMedia]

ungelesen,
18.05.2005, 12:42:5918.05.05
an
Iain wrote:

> If you know that your data is 8 bit mono, it will be
> stored as a sequence of signed bytes.

UNSIGNED bytes, not signed :-)

> If it were 16 bit stereo it would be stored as pairs of
> signed shorts.

--

// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net


Iain

ungelesen,
18.05.2005, 14:14:1418.05.05
an
On Wed, 18 May 2005 18:42:59 +0200, Alessandro Angeli [MVP::DigitalMedia]
wrote:

> Iain wrote:
>
>> If you know that your data is 8 bit mono, it will be
>> stored as a sequence of signed bytes.
>
> UNSIGNED bytes, not signed :-)
>
>> If it were 16 bit stereo it would be stored as pairs of
>> signed shorts.

Surely the values go +/- zero? So FF == -1 and so on. And if cast to a
larger integer value the sign bit should be extended?

Phil Frisbie, Jr.

ungelesen,
18.05.2005, 17:23:3318.05.05
an
Iain wrote:

> On Wed, 18 May 2005 18:42:59 +0200, Alessandro Angeli [MVP::DigitalMedia]
> wrote:
>
>>Iain wrote:
>>
>>>If you know that your data is 8 bit mono, it will be
>>>stored as a sequence of signed bytes.
>>
>>UNSIGNED bytes, not signed :-)
>>
>>>If it were 16 bit stereo it would be stored as pairs of
>>>signed shorts.
>
>
> Surely the values go +/- zero?

No. 8 bit PCM is unsigned, with 127 the 'zero' level.

> So FF == -1 and so on. And if cast to a
> larger integer value the sign bit should be extended?
>
> Iain

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Peter Reichard

ungelesen,
18.05.2005, 19:54:2418.05.05
an
>> Surely the values go +/- zero?
>
> No. 8 bit PCM is unsigned, with 127 the 'zero' level.

That's right, 16bit has signed values and 0 is the zero level.


Alessandro Angeli [MVP::DigitalMedia]

ungelesen,
19.05.2005, 07:36:2619.05.05
an
Phil Frisbie, Jr. wrote:

> No. 8 bit PCM is unsigned, with 127 the 'zero' level.

128 is the zero level.

Iain

ungelesen,
20.05.2005, 05:26:5020.05.05
an
On Thu, 19 May 2005 13:36:26 +0200, Alessandro Angeli [MVP::DigitalMedia]
wrote:

> Phil Frisbie, Jr. wrote:


>
>> No. 8 bit PCM is unsigned, with 127 the 'zero' level.
>
> 128 is the zero level.

I sit corrected!

Alessandro Angeli [MVP::DigitalMedia]

ungelesen,
24.05.2005, 05:55:3524.05.05
an
Harassment Panda wrote:

> I think I missed the answer ;-)
> Say you are using DirextX to strip out the header details
> i.e. Formats; is there a simple algorithm that can be
> used on all wave formats, something that say can be
> iterated through, dependant on the number of channels and
> format of the buffer?
> Or is there more than 2 storage possibilities which stops
> this from being so simple?

If your data is PCM (wFormatTag == WAVE_FORMAT_PCM), the
samples are wBitsPerSample/8 bytes wide, in little endian
order, and there are nChannels samples per frame, in channel
order. The samples are signed and silence is 0 but for 8-bit
samples which are unsigned and silence is 128.

0 neue Nachrichten