forked from len0rd/rockbox
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
This commit is contained in:
parent
559e0e10f8
commit
e8dc7a6d07
5 changed files with 14 additions and 15 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue