From 6c33443944b24b4b44990ce8cc7c18dee0a3edc6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 18 Sep 2003 21:10:57 +0000 Subject: [PATCH] Simplify. --- stepmania/src/RageSoundReader_WAV.cpp | 59 ++++++++------------------- stepmania/src/RageSoundReader_WAV.h | 13 +----- 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/stepmania/src/RageSoundReader_WAV.cpp b/stepmania/src/RageSoundReader_WAV.cpp index 294c8a96ea..ad6b1428ed 100644 --- a/stepmania/src/RageSoundReader_WAV.cpp +++ b/stepmania/src/RageSoundReader_WAV.cpp @@ -46,11 +46,6 @@ enum FMT_ADPCM =2 /* ADPCM compressed waveform data. */ }; -struct ADPCMCOEFSET -{ - Sint16 iCoef1, iCoef2; -}; - /* Call this to convert milliseconds to an actual byte position, based on audio data characteristics. */ Uint32 RageSoundReader_WAV::ConvertMsToBytePos(int BytesPerSample, int channels, Uint32 ms) const { @@ -132,37 +127,14 @@ bool RageSoundReader_WAV::read_uint8(FILE *rw, Uint8 *ui8) const RageSoundReader_WAV::adpcm_t::adpcm_t() { - memset( this, 0, sizeof(*this) ); + cbSize = 0; + memset( blockheaders, 0, sizeof(blockheaders) ); + wSamplesPerBlock = 0; + samples_left_in_block = 0; + nibble_state = 0; + nibble = 0; } -RageSoundReader_WAV::adpcm_t::adpcm_t( const adpcm_t &cpy ) -{ - memset( this, 0, sizeof(*this) ); - - this->cbSize = cpy.cbSize; - memcpy( this->blockheaders, cpy.blockheaders, sizeof(this->blockheaders) ); - this->wSamplesPerBlock = cpy.wSamplesPerBlock; - this->wNumCoef = cpy.wNumCoef; - this->samples_left_in_block = cpy.samples_left_in_block; - this->nibble_state = cpy.nibble_state; - this->nibble = cpy.nibble; - Alloc(); -} - -void RageSoundReader_WAV::adpcm_t::Alloc() -{ - Dealloc(); - - ASSERT( wNumCoef != 0 ); - - aCoef = new ADPCMCOEFSET[wNumCoef]; -} - -void RageSoundReader_WAV::adpcm_t::Dealloc() -{ - delete [] aCoef; - aCoef = NULL; -} bool RageSoundReader_WAV::read_fmt_chunk() { @@ -177,14 +149,17 @@ bool RageSoundReader_WAV::read_fmt_chunk() { RETURN_IF_MACRO(!read_le16(rw, &adpcm.cbSize), false); RETURN_IF_MACRO(!read_le16(rw, &adpcm.wSamplesPerBlock), false); - RETURN_IF_MACRO(!read_le16(rw, &adpcm.wNumCoef), false); + Uint16 NumCoef; + RETURN_IF_MACRO(!read_le16(rw, &NumCoef), false); - adpcm.Alloc(); - - for (int i = 0; i < adpcm.wNumCoef; i++) + for ( int i = 0; i < NumCoef; i++ ) { - RETURN_IF_MACRO(!read_le16(rw, &adpcm.aCoef[i].iCoef1), false); - RETURN_IF_MACRO(!read_le16(rw, &adpcm.aCoef[i].iCoef2), false); + Sint16 c1, c2; + RETURN_IF_MACRO(!read_le16(rw, &c1), false); + RETURN_IF_MACRO(!read_le16(rw, &c2), false); + + adpcm.Coef1.push_back( c1 ); + adpcm.Coef2.push_back( c2 ); } } @@ -319,8 +294,8 @@ bool RageSoundReader_WAV::decode_adpcm_sample_frame() Uint8 nib = adpcm.nibble; for (int i = 0; i < this->fmt.wChannels; i++) { - const Sint16 iCoef1 = adpcm.aCoef[headers[i].bPredictor].iCoef1; - const Sint16 iCoef2 = adpcm.aCoef[headers[i].bPredictor].iCoef2; + const Sint16 iCoef1 = adpcm.Coef1[headers[i].bPredictor]; + const Sint16 iCoef2 = adpcm.Coef2[headers[i].bPredictor]; const Sint32 lPredSamp = ((headers[i].iSamp[0] * iCoef1) + (headers[i].iSamp[1] * iCoef2)) / FIXED_POINT_COEF_BASE; diff --git a/stepmania/src/RageSoundReader_WAV.h b/stepmania/src/RageSoundReader_WAV.h index 4efe051b63..662cc1f231 100644 --- a/stepmania/src/RageSoundReader_WAV.h +++ b/stepmania/src/RageSoundReader_WAV.h @@ -4,10 +4,6 @@ #include "RageSoundReader_FileReader.h" #include "SDL_utils.h" -struct fmt_t; -struct ADPCMCOEFSET; -struct ADPCMBLOCKHEADER; - class RageSoundReader_WAV: public SoundReader_FileReader { FILE *rw; @@ -31,8 +27,7 @@ class RageSoundReader_WAV: public SoundReader_FileReader { Uint16 cbSize; Uint16 wSamplesPerBlock; - Uint16 wNumCoef; - ADPCMCOEFSET *aCoef; + vector Coef1, Coef2; ADPCMBLOCKHEADER blockheaders[2]; /* 2 channels */ Uint32 samples_left_in_block; @@ -40,12 +35,8 @@ class RageSoundReader_WAV: public SoundReader_FileReader Sint8 nibble; adpcm_t(); - ~adpcm_t() { Dealloc(); } - adpcm_t( const adpcm_t &cpy ); - void Alloc(); - void Dealloc(); }; - struct adpcm_t adpcm; + adpcm_t adpcm; CString filename; enum DataType_t { FORMAT_PCM=0, FORMAT_ADPCM=1 } DataType;