summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-09-10 02:52:12 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-09-10 02:52:12 +0000
commite8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9 (patch)
tree2253b78ded296b28218f89c7045664ab065fa8ae
parent559e0e10f861fa559cf2d20c8267fc2650720565 (diff)
downloadrockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.tar.gz
rockbox-e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9.zip
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
-rw-r--r--apps/codecs/libgme/emu8950.c4
-rw-r--r--apps/codecs/libgme/emu8950.h6
-rw-r--r--apps/codecs/libgme/emuadpcm.c15
-rw-r--r--apps/codecs/nsf.c2
-rw-r--r--apps/codecs/vgm.c2
5 files changed, 14 insertions, 15 deletions
diff --git a/apps/codecs/libgme/emu8950.c b/apps/codecs/libgme/emu8950.c
index e75bf66d64..2f8a32044f 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)
494 makeDphaseARTable(sampleRate, clockRate); 494 makeDphaseARTable(sampleRate, clockRate);
495 makeDphaseDRTable(sampleRate, clockRate); 495 makeDphaseDRTable(sampleRate, clockRate);
496 makeDphaseNoiseTable(sampleRate, clockRate); 496 makeDphaseNoiseTable(sampleRate, clockRate);
497 this->pm_dphase = rate_adjust(PM_SPEED * PM_DP_WIDTH / (clockRate/72), sampleRate, clockRate); 497 this->pm_dphase = rate_adjust( (int)(PM_SPEED * PM_DP_WIDTH) / (clockRate/72), sampleRate, clockRate);
498 this->am_dphase = rate_adjust(AM_SPEED * AM_DP_WIDTH / (clockRate/72), sampleRate, clockRate); 498 this->am_dphase = rate_adjust( (int)(AM_SPEED * AM_DP_WIDTH) / (clockRate/72), sampleRate, clockRate);
499} 499}
500 500
501// Reset whole of opl except patch datas. 501// Reset whole of opl except patch datas.
diff --git a/apps/codecs/libgme/emu8950.h b/apps/codecs/libgme/emu8950.h
index 88d17b956e..02169050d2 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);
238 238
239 239
240// Adjust envelope speed which depends on sampling rate 240// Adjust envelope speed which depends on sampling rate
241static inline unsigned int rate_adjust(double x, int rate, int clk) 241static inline unsigned int rate_adjust(int x, int rate, int clk)
242{ 242{
243 double tmp = x * clk / 72 / rate + 0.5; // +0.5 to round 243 unsigned int tmp = (long long)x * clk / 72 / rate;
244// assert (tmp <= 4294967295U); 244// assert (tmp <= 4294967295U);
245 return (unsigned int)tmp; 245 return tmp;
246} 246}
247 247
248#endif 248#endif
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_)
117 this_->diff = DDEF; 117 this_->diff = DDEF;
118 this_->nextLeveling = 0; 118 this_->nextLeveling = 0;
119 this_->sampleStep = 0; 119 this_->sampleStep = 0;
120 this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); 120 this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP);
121} 121}
122 122
123void ADPCM_writeReg(struct Y8950Adpcm* this_, byte rg, byte data) 123void ADPCM_writeReg(struct Y8950Adpcm* this_, byte rg, byte data)
@@ -176,23 +176,22 @@ void ADPCM_writeReg(struct Y8950Adpcm* this_, byte rg, byte data)
176 case 0x10: // DELTA-N (L) 176 case 0x10: // DELTA-N (L)
177 this_->delta = (this_->delta & 0xFF00) | data; 177 this_->delta = (this_->delta & 0xFF00) | data;
178 this_->step = rate_adjust(this_->delta<<GETA_BITS, this_->sampleRate, this_->clockRate); 178 this_->step = rate_adjust(this_->delta<<GETA_BITS, this_->sampleRate, this_->clockRate);
179 this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); 179 this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP);
180 break; 180 break;
181 case 0x11: // DELTA-N (H) 181 case 0x11: // DELTA-N (H)
182 this_->delta = (this_->delta & 0x00FF) | (data << 8); 182 this_->delta = (this_->delta & 0x00FF) | (data << 8);
183 this_->step = rate_adjust(this_->delta<<GETA_BITS, this_->sampleRate, this_->clockRate); 183 this_->step = rate_adjust(this_->delta<<GETA_BITS, this_->sampleRate, this_->clockRate);
184 this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); 184 this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP);
185 break; 185 break;
186 186
187 case 0x12: { // ENVELOP CONTROL 187 case 0x12: { // ENVELOP CONTROL
188 int oldVol = this_->volume; 188 int oldVol = this_->volume;
189 this_->volume = (data * ADPCM_VOLUME) >> 8; 189 this_->volume = (data * ADPCM_VOLUME) >> 8;
190 if (oldVol != 0) { 190 if (oldVol != 0) {
191 double factor = (double)this_->volume / (double)oldVol; 191 this_->output = (int)(((long long)this_->output * this_->volume) / oldVol);
192 this_->output = (int)((double)this_->output * factor); 192 this_->sampleStep = (int)(((long long)this_->sampleStep * this_->volume) / oldVol);
193 this_->sampleStep = (int)((double)this_->sampleStep * factor);
194 } 193 }
195 this_->volumeWStep = (int)((double)this_->volume * this_->step / MAX_STEP); 194 this_->volumeWStep = (int)((long long)this_->volume * this_->step / MAX_STEP);
196 break; 195 break;
197 } 196 }
198 case 0x0D: // PRESCALE (L) 197 case 0x0D: // PRESCALE (L)
@@ -290,7 +289,7 @@ int ADPCM_calcSample(struct Y8950Adpcm* this_)
290 289
291 /* TODO: Used fixed point math here */ 290 /* TODO: Used fixed point math here */
292 #if !defined(ROCKBOX) 291 #if !defined(ROCKBOX)
293 this_->output += (int)((double)this_->sampleStep * ((double)this_->nowStep/(double)this_->step)); 292 this_->output += (int)(((long long)this_->sampleStep * this_->nowStep) / this_->step);
294 #endif 293 #endif
295 } 294 }
296 this_->output += this_->sampleStep; 295 this_->output += this_->sampleStep;
diff --git a/apps/codecs/nsf.c b/apps/codecs/nsf.c
index 7214b5d2a2..4c5b37c3fa 100644
--- a/apps/codecs/nsf.c
+++ b/apps/codecs/nsf.c
@@ -126,7 +126,7 @@ next_track:
126 126
127 /* Set elapsed time for one track files */ 127 /* Set elapsed time for one track files */
128 if (is_multitrack == 0) { 128 if (is_multitrack == 0) {
129 elapsed_time += (CHUNK_SIZE / 2) / 44.1; 129 elapsed_time += (CHUNK_SIZE / 2) * 10 / 441;
130 ci->set_elapsed(elapsed_time); 130 ci->set_elapsed(elapsed_time);
131 } 131 }
132 } 132 }
diff --git a/apps/codecs/vgm.c b/apps/codecs/vgm.c
index d7390291e1..416f772f1d 100644
--- a/apps/codecs/vgm.c
+++ b/apps/codecs/vgm.c
@@ -134,7 +134,7 @@ enum codec_status codec_run(void)
134 134
135 ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1); 135 ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1);
136 136
137 elapsed_time += (CHUNK_SIZE / 2) / 44.1; 137 elapsed_time += (CHUNK_SIZE / 2) * 10 / 441;
138 ci->set_elapsed(elapsed_time); 138 ci->set_elapsed(elapsed_time);
139 } 139 }
140 140