From e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Sat, 10 Sep 2011 02:52:12 +0000 Subject: Migrate some floating point code to fixed point in libgme. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30493 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libgme/emuadpcm.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'apps/codecs/libgme/emuadpcm.c') diff --git a/apps/codecs/libgme/emuadpcm.c b/apps/codecs/libgme/emuadpcm.c index d85aba3488..b426a74de5 100644 --- a/apps/codecs/libgme/emuadpcm.c +++ b/apps/codecs/libgme/emuadpcm.c @@ -117,7 +117,7 @@ void restart(struct Y8950Adpcm* this_) this_->diff = DDEF; this_->nextLeveling = 0; this_->sampleStep = 0; - this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); + this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP); } void ADPCM_writeReg(struct Y8950Adpcm* this_, byte rg, byte data) @@ -176,23 +176,22 @@ void ADPCM_writeReg(struct Y8950Adpcm* this_, byte rg, byte data) case 0x10: // DELTA-N (L) this_->delta = (this_->delta & 0xFF00) | data; this_->step = rate_adjust(this_->delta<sampleRate, this_->clockRate); - this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); + this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP); break; case 0x11: // DELTA-N (H) this_->delta = (this_->delta & 0x00FF) | (data << 8); this_->step = rate_adjust(this_->delta<sampleRate, this_->clockRate); - this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); + this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP); break; case 0x12: { // ENVELOP CONTROL int oldVol = this_->volume; this_->volume = (data * ADPCM_VOLUME) >> 8; if (oldVol != 0) { - double factor = (double)this_->volume / (double)oldVol; - this_->output = (int)((double)this_->output * factor); - this_->sampleStep = (int)((double)this_->sampleStep * factor); + this_->output = (int)(((long long)this_->output * this_->volume) / oldVol); + this_->sampleStep = (int)(((long long)this_->sampleStep * this_->volume) / oldVol); } - this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); + this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP); break; } case 0x0D: // PRESCALE (L) @@ -290,7 +289,7 @@ int ADPCM_calcSample(struct Y8950Adpcm* this_) /* TODO: Used fixed point math here */ #if !defined(ROCKBOX) - this_->output += (int)((double)this_->sampleStep * ((double)this_->nowStep/(double)this_->step)); + this_->output += (int)(((long long)this_->sampleStep * this_->nowStep) / this_->step); #endif } this_->output += this_->sampleStep; -- cgit v1.2.3