sidemu.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2024 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2000-2001 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 SIDEMU_H
#define SIDEMU_H
#include "sidplayfp/SidConfig.h"
#include "sidplayfp/siddefs.h"
#include "Event.h"
#include "EventScheduler.h"
#include "c64/c64sid.h"
#include "sidcxx11.h"
#include <string>
#include <bitset>
class sidbuilder;
namespace libsidplayfp
{
class sidemu : public c64sid
{
public:
static constexpr unsigned int OUTPUTBUFFERSIZE = 5000;
private:
sidbuilder* const m_builder;
protected:
static const char ERR_UNSUPPORTED_FREQ[];
static const char ERR_INVALID_SAMPLING[];
static const char ERR_INVALID_CHIP[];
protected:
EventScheduler *eventScheduler = nullptr;
event_clock_t m_accessClk = 0;
short *m_buffer = nullptr;
int m_bufferpos = 0;
bool m_status = true;
bool isLocked = false;
bool isFilterDisabled = false;
std::bitset<4> isMuted;
std::string m_error;
protected:
virtual void write(uint_least8_t addr, uint8_t data) = 0;
void writeReg(uint_least8_t addr, uint8_t data) override final;
public:
sidemu(sidbuilder *builder) :
m_builder(builder),
m_error("N/A")
{
isMuted.reset();
}
~sidemu() override = default;
virtual void clock() = 0;
virtual bool lock(EventScheduler *scheduler);
virtual void unlock();
// Standard SID functions
void voice(unsigned int voice, bool mute);
void filter(bool enable);
virtual void model(SidConfig::sid_model_t model, bool digiboost) = 0;
virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED,
SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED) {}
const char* error() const { return m_error.c_str(); }
sidbuilder* builder() const { return m_builder; }
int bufferpos() const { return m_bufferpos; }
void bufferpos(int pos) { m_bufferpos = pos; }
short *buffer() const { return m_buffer; }
};
}
#endif // SIDEMU_H
SidConfig::sid_model_t
sid_model_t
SID chip model.
Definition SidConfig.h:51
SidConfig::sampling_method_t
sampling_method_t
Sampling method.
Definition SidConfig.h:84
libsidplayfp::EventScheduler
Definition EventScheduler.h:62
libsidplayfp::c64sid
Definition c64sid.h:40
libsidplayfp::sidemu
Definition sidemu.h:47
libsidplayfp::sidemu::m_buffer
short * m_buffer
The sample buffer.
Definition sidemu.h:66
libsidplayfp::sidemu::lock
virtual bool lock(EventScheduler *scheduler)
Definition sidemu.cpp:73
libsidplayfp::sidemu::unlock
virtual void unlock()
Definition sidemu.cpp:84
libsidplayfp::sidemu::clock
virtual void clock()=0
libsidplayfp::sidemu::m_bufferpos
int m_bufferpos
Current position in buffer.
Definition sidemu.h:69
libsidplayfp::sidemu::error
const char * error() const
Definition sidemu.h:144
libsidplayfp::sidemu::sampling
virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED, SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED)
Definition sidemu.h:138
libsidplayfp::sidemu::filter
void filter(bool enable)
Definition sidemu.cpp:68
libsidplayfp::sidemu::bufferpos
int bufferpos() const
Definition sidemu.h:151
libsidplayfp::sidemu::bufferpos
void bufferpos(int pos)
Definition sidemu.h:156
libsidplayfp::sidemu::OUTPUTBUFFERSIZE
static constexpr unsigned int OUTPUTBUFFERSIZE
Buffer size. 5000 is roughly 5 ms at 96 kHz.
Definition sidemu.h:50
libsidplayfp::sidemu::voice
void voice(unsigned int voice, bool mute)
Definition sidemu.cpp:62
libsidplayfp::sidemu::model
virtual void model(SidConfig::sid_model_t model, bool digiboost)=0
libsidplayfp::sidemu::isMuted
std::bitset< 4 > isMuted
Flags for muted voices.
Definition sidemu.h:77
libsidplayfp::sidemu::buffer
short * buffer() const
Definition sidemu.h:161
sidbuilder
Definition sidbuilder.h:41