On 06/06/2010 01:24 PM, Shay wrote:
> So if you set gain() to 2.0, you get distorted output? How are you
> determining maximum amplitude? What sort of amplitudes do you see if
> you run one of the demos and examine the WAV file in a sound editor?
gain() doesn't affect nsf files (as noted in the source) but for .gym
files I see distortion at various values of gain. For
StreetsOfRage2-01.gym I get distortion at gain=4, but if I set gain=5
then it starts to sound normal again. Then at gain=6 and up it sounds
distorted some more. I looked at the waveforms with different gain
settings using the player included with the GME source. For higher
values of gain I get higher amplitudes for some channels but others
don't seem to be affected very much.
I was determining maximum amplitude with this code:
emulator->play(length / 2, (short*) stream);
short large = 0;
short small = 0;
for (int i = 0; i < length / 2; i++){
short z = ((short *) stream)[i];
if (z < small){
small = z;
}
if (z > large){
large = z;
}
}
Global::debug(0) << "Largest " << large << " Smallest " << small <<
std::endl;
Actually this code finds the highest and lowest amplitudes.
Anyway, if gain() doesn't affect all files equally (nsf) then I don't
think its the right parameter to use. Someone else recommended that I
figure out the maximum amplitude for a given file and scale every sample
by a constant such that the maximum amplitude from GME is the maximum
amplitude for my sound output.
int largestAmplitude = calculateLargest(gme_output);
double factor = (double) 0x7fff / largestAmplitude;
for (i = 0; i < length; i++){
gme_output[i] *= factor;
}