00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MIXER_H
00025 #define MIXER_H
00026
00027 #include <stdlib.h>
00028
00029 #include "event.h"
00030 #include "sidbuilder.h"
00031
00035 class Mixer : private Event
00036 {
00037 private:
00041 static const int MIXER_EVENT_RATE = 5000;
00042
00043 public:
00045 static const int_least32_t VOLUME_MAX = 1024;
00046
00047 private:
00051 EventContext &event_context;
00052
00053 sidemu *m_chip1;
00054 sidemu *m_chip2;
00055
00056 int oldRandomValue;
00057 int m_fastForwardFactor;
00058
00059 int_least32_t m_leftVolume;
00060 int_least32_t m_rightVolume;
00061 bool m_stereo;
00062
00063
00064 uint_least32_t m_sampleCount;
00065 uint_least32_t m_sampleIndex;
00066 short *m_sampleBuffer;
00067
00068 private:
00069 int triangularDithering()
00070 {
00071 const int prevValue = oldRandomValue;
00072 oldRandomValue = rand() & (VOLUME_MAX-1);
00073 return oldRandomValue - prevValue;
00074 }
00075
00076 public:
00082 Mixer(EventContext *context) :
00083 Event("Mixer"),
00084 event_context(*context),
00085 oldRandomValue(0),
00086 m_fastForwardFactor(1),
00087 m_sampleCount(0) {}
00088
00092 void event();
00093
00094 void reset() { event_context.schedule(*this, MIXER_EVENT_RATE, EVENT_CLOCK_PHI1); }
00095
00096 void begin(short *buffer, uint_least32_t count);
00097
00098 void setSids(sidemu *chip1, sidemu *chip2);
00099 bool setFastForward(int ff);
00100 void setVolume(int_least32_t left, int_least32_t right);
00101 void setStereo(bool stereo) { m_stereo = stereo; }
00102
00103 bool notFinished() const { return m_sampleIndex != m_sampleCount; }
00104 uint_least32_t samplesGenerated() const { return m_sampleIndex; }
00105 uint_least32_t sampleCount() const { return m_sampleCount; }
00106 };
00107
00108 #endif // MIXER_H