Tell AudioOutputMixer the rate for the next sample (#129)
* Tell the mixer at which rate to consume the next sample * Update SetRate method to include id parameter * Refactor SetRate to minimize redundant updates Optimize rate setting to avoid unnecessary calls. * Add newHz and lastHz variables to AudioOutputMixer --------- Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
This commit is contained in:
1 parent
297943c8a8
commit
b63c28449e
2 files changed
+10
-1
No files matched your search
@@ -25,6 +25,8 @@ AudioOutputMixerStub::AudioOutputMixerStub(AudioOutputMixer *sink, int id) : Aud
|
||||
this->id = id;
|
||||
this->parent = sink;
|
||||
SetGain(1.0);
|
||||
this->newHz = 44100;
|
||||
this->lastHz = -1;
|
||||
}
|
||||
|
||||
AudioOutputMixerStub::~AudioOutputMixerStub() {
|
||||
@@ -32,7 +34,8 @@ AudioOutputMixerStub::~AudioOutputMixerStub() {
|
||||
}
|
||||
|
||||
bool AudioOutputMixerStub::SetRate(int hz) {
|
||||
return parent->SetRate(hz, id);
|
||||
newHz = hz;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutputMixerStub::SetBitsPerSample(int bits) {
|
||||
@@ -51,6 +54,10 @@ bool AudioOutputMixerStub::ConsumeSample(int16_t sample[2]) {
|
||||
int16_t amp[2];
|
||||
amp[LEFTCHANNEL] = Amplify(sample[LEFTCHANNEL]);
|
||||
amp[RIGHTCHANNEL] = Amplify(sample[RIGHTCHANNEL]);
|
||||
if (newHz != lastHz) { // Avoid setting on each sample unless things change
|
||||
parent->SetRate(newHz, id);
|
||||
lastHz = newHz;
|
||||
}
|
||||
return parent->ConsumeSample(amp, id);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
protected:
|
||||
AudioOutputMixer *parent;
|
||||
int id;
|
||||
int newHz;
|
||||
int lastHz;
|
||||
};
|
||||
|
||||
// Single mixer object per output
|
||||
|
||||
Reference in new issue
Block a user