mixer.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright (C) 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MIXER_H
#define MIXER_H
#include <stdint.h>
#include <cstdlib>
#include <vector>
#include "event.h"
class sidemu;
class Mixer : private Event
{
private:
typedef short (Mixer::*mixer_func_t)() const;
public:
static const int_least32_t VOLUME_MAX = 1024;
private:
EventContext &event_context;
std::vector<sidemu*> m_chips;
std::vector<short*> m_buffers;
std::vector<int_least32_t> m_iSamples;
std::vector<int_least32_t> m_volume;
std::vector<mixer_func_t> m_mix;
int oldRandomValue;
int m_fastForwardFactor;
// Mixer settings
short *m_sampleBuffer;
uint_least32_t m_sampleCount;
uint_least32_t m_sampleIndex;
bool m_stereo;
private:
void updateParams();
int triangularDithering()
{
const int prevValue = oldRandomValue;
oldRandomValue = rand() & (VOLUME_MAX-1);
return oldRandomValue - prevValue;
}
short channel1MonoMix() const { return static_cast<short>((m_iSamples[0] + m_iSamples[1]) / 2); }
short channel1StereoMix() const { return static_cast<short>(m_iSamples[0]); }
short channel2FromMonoMix() const { return static_cast<short>(m_iSamples[0]); }
short channel2FromStereoMix() const { return static_cast<short>(m_iSamples[1]); }
public:
Mixer(EventContext *context) :
Event("Mixer"),
event_context(*context),
oldRandomValue(0),
m_fastForwardFactor(1),
m_sampleCount(0),
m_stereo(false)
{
m_mix.push_back(&Mixer::channel1MonoMix);
}
void event();
void reset();
void begin(short *buffer, uint_least32_t count);
void clearSids();
void addSid(sidemu *chip);
sidemu* getSid(unsigned int i) const { return (i < m_chips.size()) ? m_chips[i] : 0; }
bool setFastForward(int ff);
void setVolume(int_least32_t left, int_least32_t right);
void setStereo(bool stereo);
bool notFinished() const { return m_sampleIndex != m_sampleCount; }
uint_least32_t samplesGenerated() const { return m_sampleIndex; }
};
#endif // MIXER_H
Mixer::VOLUME_MAX
static const int_least32_t VOLUME_MAX
Definition: mixer.h:46
Mixer
Definition: mixer.h:39
Mixer::setStereo
void setStereo(bool stereo)
Definition: mixer.cpp:174
sidemu
Definition: sidemu.h:45
Mixer::notFinished
bool notFinished() const
Definition: mixer.h:169
EventContext
Definition: event.h:101
Mixer::setFastForward
bool setFastForward(int ff)
Definition: mixer.cpp:186
Mixer::setVolume
void setVolume(int_least32_t left, int_least32_t right)
Definition: mixer.cpp:195
Mixer::samplesGenerated
uint_least32_t samplesGenerated() const
Definition: mixer.h:174
Mixer::addSid
void addSid(sidemu *chip)
Definition: mixer.cpp:160
Mixer::getSid
sidemu * getSid(unsigned int i) const
Definition: mixer.h:141
Mixer::clearSids
void clearSids()
Definition: mixer.cpp:154
Mixer::reset
void reset()
Definition: mixer.cpp:135
Mixer::Mixer
Mixer(EventContext *context)
Definition: mixer.h:94
Mixer::begin
void begin(short *buffer, uint_least32_t count)
Definition: mixer.cpp:140
Event
Definition: event.h:50
Mixer::event
void event()
Definition: mixer.cpp:64