- Volume tweaking.

This commit is contained in:
Christoph Oelckers 2018-02-21 19:05:14 +01:00
parent e6bae25423
commit 59352af486
2 changed files with 13 additions and 2 deletions

View file

@ -70,6 +70,8 @@ public:
instruments = nullptr; instruments = nullptr;
} }
double test[3] = { 0, 0, 0 };
protected: protected:
TimidityPlus::Player *Renderer; TimidityPlus::Player *Renderer;
@ -161,6 +163,7 @@ int TimidityPPMIDIDevice::Open(MidiCallback callback, void *userdata)
} }
// No instruments loaded means we cannot play... // No instruments loaded means we cannot play...
if (instruments == nullptr) return 0; if (instruments == nullptr) return 0;
TimidityVolumeChanged();
return ret; return ret;
} }
@ -216,6 +219,14 @@ void TimidityPPMIDIDevice::ComputeOutput(float *buffer, int len)
if (Renderer != nullptr) if (Renderer != nullptr)
Renderer->compute_data(buffer, len); Renderer->compute_data(buffer, len);
sampletime += len; sampletime += len;
for (int i = 0; i < len * 2; i++)
{
if (buffer[i] < test[0]) test[0] = buffer[i];
if (buffer[i] > test[1]) test[1] = buffer[i];
test[2] += fabs(buffer[i]);
}
Printf("Min = %f, Max = %f, Avg = %f\n", test[0], test[1], test[2] / sampletime);
} }
//========================================================================== //==========================================================================

View file

@ -230,7 +230,7 @@ double Player::cnv_Hz_to_vib_ratio(double freq)
void Player::adjust_amplification(void) void Player::adjust_amplification(void)
{ {
static const double compensation_ratio = 1.0; static const double compensation_ratio = 5.0;
/* compensate master volume */ /* compensate master volume */
master_volume = (double)(amplification) / 100.0 * master_volume = (double)(amplification) / 100.0 *
((double)master_volume_ratio * (compensation_ratio/0xFFFF)); ((double)master_volume_ratio * (compensation_ratio/0xFFFF));
@ -5033,7 +5033,7 @@ int Player::compute_data(float *buffer, int32_t count)
// pass to caller // pass to caller
for (int i = 0; i < process*2; i++) for (int i = 0; i < process*2; i++)
{ {
*buffer++ = (common_buffer[i])*(5.f / 0x80000000u); *buffer++ = (common_buffer[i])*(1.f / 0x80000000u);
} }
} }
return RC_OK; return RC_OK;