Commit 8e9dcb66 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

Use the same 8/16bit conversion routines as in pcmconverter.c.

Reorder the two ifs in the first part of cp_fields to simplify the code.
parent 336d8fe2
...@@ -117,61 +117,46 @@ void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len) ...@@ -117,61 +117,46 @@ void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len)
} }
} }
/* WAV format info can be found at: */ /* WAV format info can be found at:
/* */ *
/* http://www.cwi.nl/ftp/audio/AudioFormats.part2 */ * http://www.cwi.nl/ftp/audio/AudioFormats.part2
/* ftp://ftp.cwi.nl/pub/audio/RIFF-format */ * ftp://ftp.cwi.nl/pub/audio/RIFF-format
/* */ *
/* Import points to remember: */ * Import points to remember:
/* */ * 8-bit WAV is unsigned
/* 8-bit WAV is unsigned */ * 16-bit WAV is signed
/* 16-bit WAV is signed */ */
/* Use the same formulas as pcmconverter.c */
static inline INT16 cvtU8toS16(BYTE byte) static inline INT16 cvtU8toS16(BYTE b)
{ {
INT16 s = (byte - 128) << 8; return (short)((b+(b << 8))-32768);
return s;
} }
static inline BYTE cvtS16toU8(INT16 word) static inline BYTE cvtS16toU8(INT16 s)
{ {
BYTE b = (word + 32768) >> 8; return (s >> 8) ^ (unsigned char)0x80;
return b;
} }
static inline void cp_fields(const IDirectSoundBufferImpl *dsb, BYTE *ibuf, BYTE *obuf ) static inline void cp_fields(const IDirectSoundBufferImpl *dsb, BYTE *ibuf, BYTE *obuf )
{ {
INT fl = 0, fr = 0; INT fl,fr;
if (dsb->wfx.nChannels == 2) {
if (dsb->wfx.wBitsPerSample == 8) { if (dsb->wfx.wBitsPerSample == 8) {
if (dsound->wfx.wBitsPerSample == 8 &&
dsound->wfx.nChannels == dsb->wfx.nChannels) {
/* avoid needless 8->16->8 conversion */ /* avoid needless 8->16->8 conversion */
if ( (dsound->wfx.wBitsPerSample == 8) && (dsound->wfx.nChannels == 2) ) { *obuf=*ibuf;
*obuf=*ibuf; if (dsb->wfx.nChannels==2)
*(obuf+1)=*(ibuf+1); *(obuf+1)=*(ibuf+1);
return; return;
}
fl = cvtU8toS16(*ibuf);
fr = cvtU8toS16(*(ibuf + 1));
} else if (dsb->wfx.wBitsPerSample == 16) {
fl = *((INT16 *)ibuf);
fr = *(((INT16 *)ibuf) + 1);
}
} else if (dsb->wfx.nChannels == 1) {
if (dsb->wfx.wBitsPerSample == 8) {
/* avoid needless 8->16->8 conversion */
if ( (dsound->wfx.wBitsPerSample == 8) && (dsound->wfx.nChannels == 1) ) {
*obuf=*ibuf;
return;
}
fl = cvtU8toS16(*ibuf);
fr = fl;
} else if (dsb->wfx.wBitsPerSample == 16) {
fl = *((INT16 *)ibuf);
fr = fl;
} }
fl = cvtU8toS16(*ibuf);
fr = (dsb->wfx.nChannels==2 ? cvtU8toS16(*(ibuf + 1)) : fl);
} else {
fl = *((INT16 *)ibuf);
fr = (dsb->wfx.nChannels==2 ? *(((INT16 *)ibuf) + 1) : fl);
} }
if (dsound->wfx.nChannels == 2) { if (dsound->wfx.nChannels == 2) {
if (dsound->wfx.wBitsPerSample == 8) { if (dsound->wfx.wBitsPerSample == 8) {
*obuf = cvtS16toU8(fl); *obuf = cvtS16toU8(fl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment