diff options
| author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 02:52:12 +0000 |
|---|---|---|
| committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 02:52:12 +0000 |
| commit | e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9 (patch) | |
| tree | 2253b78ded296b28218f89c7045664ab065fa8ae /apps/codecs | |
| parent | 559e0e10f861fa559cf2d20c8267fc2650720565 (diff) | |
| download | rockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.zip rockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.tar.gz rockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.tar.bz2 rockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.tar.xz | |
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
Diffstat (limited to 'apps/codecs')
| -rw-r--r-- | apps/codecs/libgme/emu8950.c | 4 | ||||
| -rw-r--r-- | apps/codecs/libgme/emu8950.h | 6 | ||||
| -rw-r--r-- | apps/codecs/libgme/emuadpcm.c | 15 | ||||
| -rw-r--r-- | apps/codecs/nsf.c | 2 | ||||
| -rw-r--r-- | apps/codecs/vgm.c | 2 |
5 files changed, 14 insertions, 15 deletions
diff --git a/apps/codecs/libgme/emu8950.c b/apps/codecs/libgme/emu8950.c index e75bf66..2f8a320 100644 --- a/apps/codecs/libgme/emu8950.c +++ b/apps/codecs/libgme/emu8950.c @@ -494,8 +494,8 @@ void OPL_setSampleRate(struct Y8950* this, int sampleRate, int clockRate) makeDphaseARTable(sampleRate, clockRate); makeDphaseDRTable(sampleRate, clockRate); makeDphaseNoiseTable(sampleRate, clockRate); - this->pm_dphase = rate_adjust(PM_SPEED * PM_DP_WIDTH / (clockRate/72), sampleRate, clockRate); - this->am_dphase = rate_adjust(AM_SPEED * AM_DP_WIDTH / (clockRate/72), sampleRate, clockRate); + this->pm_dphase = rate_adjust( (int)(PM_SPEED * PM_DP_WIDTH) / (clockRate/72), sampleRate, clockRate); + this->am_dphase = rate_adjust( (int)(AM_SPEED * AM_DP_WIDTH) / (clockRate/72), sampleRate, clockRate); } // Reset whole of opl except patch datas. diff --git a/apps/codecs/libgme/emu8950.h b/apps/codecs/libgme/emu8950.h index 88d17b9..0216905 100644 --- a/apps/codecs/libgme/emu8950.h +++ b/apps/codecs/libgme/emu8950.h @@ -238,11 +238,11 @@ void OPL_changeStatusMask(struct Y8950* this_, byte newMask); // Adjust envelope speed which depends on sampling rate -static inline unsigned int rate_adjust(double x, int rate, int clk) +static inline unsigned int rate_adjust(int x, int rate, int clk) { - double tmp = x * clk / 72 / rate + 0.5; // +0.5 to round + unsigned int tmp = (long long)x * clk / 72 / rate; // assert (tmp <= 4294967295U); - return (unsigned int)tmp; + return tmp; } #endif diff --git a/apps/codecs/libgme/emuadpcm.c b/apps/codecs/libgme/emuadpcm.c index d85aba3..b426a74 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<<GETA_BITS, this_->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<<GETA_BITS, this_->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; diff --git a/apps/codecs/nsf.c b/apps/codecs/nsf.c index 7214b5d2..4c5b37c 100644 --- a/apps/codecs/nsf.c +++ b/apps/codecs/nsf.c @@ -126,7 +126,7 @@ next_track: /* Set elapsed time for one track files */ if (is_multitrack == 0) { - elapsed_time += (CHUNK_SIZE / 2) / 44.1; + elapsed_time += (CHUNK_SIZE / 2) * 10 / 441; ci->set_elapsed(elapsed_time); } } diff --git a/apps/codecs/vgm.c b/apps/codecs/vgm.c index d739029..416f772 100644 --- a/apps/codecs/vgm.c +++ b/apps/codecs/vgm.c @@ -134,7 +134,7 @@ enum codec_status codec_run(void) ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1); - elapsed_time += (CHUNK_SIZE / 2) / 44.1; + elapsed_time += (CHUNK_SIZE / 2) * 10 / 441; ci->set_elapsed(elapsed_time); } |