Converting RhythmGame to float and other tidy ups
diff --git a/samples/shared/MixerMono.h b/samples/shared/Mixer.h
similarity index 69%
rename from samples/shared/MixerMono.h
rename to samples/shared/Mixer.h
index 425095d..52ccf37 100644
--- a/samples/shared/MixerMono.h
+++ b/samples/shared/Mixer.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef SHARED_MIXER_MONO_H
-#define SHARED_MIXER_MONO_H
+#ifndef SHARED_MIXER_H
+#define SHARED_MIXER_H
#include <array>
#include "IRenderableAudio.h"
@@ -24,20 +24,22 @@
constexpr uint8_t kMaxTracks = 100;
/**
- * A Mixer object which sums the output from multiple mono tracks into a single mono output
+ * A Mixer object which sums the output from multiple tracks into a single output. The number of
+ * input channels on each track must match the number of output channels (default 1=mono). This can
+ * be changed by calling `setChannelCount`.
*/
-class MixerMono : public IRenderableAudio {
+class Mixer : public IRenderableAudio {
public:
void renderAudio(float *audioData, int32_t numFrames) {
// Zero out the incoming container array
- memset(audioData, 0, sizeof(float) * numFrames);
+ memset(audioData, 0, sizeof(float) * numFrames * mChannelCount);
for (int i = 0; i < mNextFreeTrackIndex; ++i) {
mTracks[i]->renderAudio(mixingBuffer, numFrames);
- for (int j = 0; j < numFrames; ++j) {
+ for (int j = 0; j < numFrames * mChannelCount; ++j) {
audioData[j] += mixingBuffer[j];
}
}
@@ -47,11 +49,14 @@
mTracks[mNextFreeTrackIndex++] = renderer;
}
+ void setChannelCount(int32_t channelCount){ mChannelCount = channelCount; }
+
private:
float mixingBuffer[kBufferSize];
std::array<std::shared_ptr<IRenderableAudio>, kMaxTracks> mTracks;
uint8_t mNextFreeTrackIndex = 0;
+ int32_t mChannelCount = 1; // Default to mono
};
-#endif //SHARED_MIXER_MONO_H
+#endif //SHARED_MIXER_H