2016-01-14 01:21:09 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "EmulationSettings.h"
|
2016-01-31 13:53:17 -05:00
|
|
|
#include "../Utilities/LowPassFilter.h"
|
2016-01-14 01:21:09 -05:00
|
|
|
#include "../BlipBuffer/blip_buf.h"
|
2016-01-14 19:33:16 -05:00
|
|
|
#include "IAudioDevice.h"
|
2016-01-21 00:53:02 -05:00
|
|
|
#include "Snapshotable.h"
|
2016-01-14 01:21:09 -05:00
|
|
|
|
2016-01-21 00:53:02 -05:00
|
|
|
class SoundMixer : public Snapshotable
|
2016-01-14 01:21:09 -05:00
|
|
|
{
|
2016-01-30 14:57:50 -05:00
|
|
|
public:
|
|
|
|
static const uint32_t CycleLength = 10000;
|
|
|
|
static const uint32_t BitsPerSample = 16;
|
|
|
|
|
2016-01-14 01:21:09 -05:00
|
|
|
private:
|
2016-01-14 19:33:16 -05:00
|
|
|
static IAudioDevice* AudioDevice;
|
|
|
|
static const uint32_t MaxSampleRate = 48000;
|
|
|
|
static const uint32_t MaxSamplesPerFrame = MaxSampleRate / 60;
|
2016-01-30 14:57:50 -05:00
|
|
|
static const uint32_t MaxChannelCount = 6;
|
|
|
|
static const uint32_t ExpansionAudioIndex = MaxChannelCount - 1;
|
|
|
|
|
|
|
|
AudioChannel _expansionAudioType;
|
2016-01-31 13:53:17 -05:00
|
|
|
LowPassFilter _lowPassFilter;
|
2016-01-14 19:33:16 -05:00
|
|
|
|
2016-01-14 01:21:09 -05:00
|
|
|
int16_t _previousOutput = 0;
|
|
|
|
|
|
|
|
vector<uint32_t> _timestamps;
|
2016-01-30 14:57:50 -05:00
|
|
|
int8_t _channelOutput[MaxChannelCount][CycleLength];
|
|
|
|
int8_t _currentOutput[MaxChannelCount];
|
2016-01-14 01:21:09 -05:00
|
|
|
|
|
|
|
int16_t _lupSquare[31];
|
|
|
|
int16_t _lupTnd[203];
|
|
|
|
|
|
|
|
blip_t* _blipBuf;
|
|
|
|
int16_t *_outputBuffer;
|
2016-01-30 14:57:50 -05:00
|
|
|
double _volumes[MaxChannelCount];
|
2016-01-14 01:21:09 -05:00
|
|
|
|
2016-01-14 19:33:16 -05:00
|
|
|
uint32_t _sampleRate;
|
|
|
|
uint32_t _clockRate;
|
|
|
|
|
2016-01-14 01:21:09 -05:00
|
|
|
void InitializeLookupTables();
|
|
|
|
int16_t GetOutputVolume();
|
|
|
|
void EndFrame(uint32_t time);
|
|
|
|
|
2016-01-14 19:33:16 -05:00
|
|
|
void UpdateRates();
|
|
|
|
|
2016-01-21 00:53:02 -05:00
|
|
|
protected:
|
|
|
|
virtual void StreamState(bool saving);
|
|
|
|
|
2016-01-14 01:21:09 -05:00
|
|
|
public:
|
|
|
|
SoundMixer();
|
|
|
|
~SoundMixer();
|
|
|
|
|
|
|
|
void SetNesModel(NesModel model);
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
void PlayAudioBuffer(uint32_t cycle);
|
2016-01-30 14:57:50 -05:00
|
|
|
void AddDelta(AudioChannel channel, uint32_t time, int8_t delta);
|
|
|
|
|
|
|
|
void SetExpansionAudioType(AudioChannel channel);
|
|
|
|
void AddExpansionAudioDelta(uint32_t time, int8_t delta);
|
2016-01-21 00:53:02 -05:00
|
|
|
|
2016-01-14 19:33:16 -05:00
|
|
|
static void StopAudio(bool clearBuffer = false);
|
|
|
|
static void RegisterAudioDevice(IAudioDevice *audioDevice);
|
2016-01-14 01:21:09 -05:00
|
|
|
};
|