2016-01-14 06:21:09 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "EmulationSettings.h"
|
2016-01-31 18:53:17 +00:00
|
|
|
#include "../Utilities/LowPassFilter.h"
|
2016-05-22 12:14:55 +00:00
|
|
|
#include "../Utilities/blip_buf.h"
|
2016-06-05 18:36:20 +00:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2016-01-15 00:33:16 +00:00
|
|
|
#include "IAudioDevice.h"
|
2016-01-21 05:53:02 +00:00
|
|
|
#include "Snapshotable.h"
|
2016-02-21 20:31:39 +00:00
|
|
|
#include "StereoPanningFilter.h"
|
|
|
|
#include "StereoDelayFilter.h"
|
|
|
|
#include "ReverbFilter.h"
|
2016-12-10 02:23:20 +00:00
|
|
|
#include "CrossFeedFilter.h"
|
2016-06-05 18:36:20 +00:00
|
|
|
#include "WaveRecorder.h"
|
2016-01-14 06:21:09 +00:00
|
|
|
|
2016-01-21 05:53:02 +00:00
|
|
|
class SoundMixer : public Snapshotable
|
2016-01-14 06:21:09 +00:00
|
|
|
{
|
2016-01-30 19:57:50 +00:00
|
|
|
public:
|
2016-12-09 15:30:09 +00:00
|
|
|
static const uint32_t CycleLength = 1000;
|
2016-01-30 19:57:50 +00:00
|
|
|
static const uint32_t BitsPerSample = 16;
|
|
|
|
|
2016-01-14 06:21:09 +00:00
|
|
|
private:
|
2016-06-05 18:36:20 +00:00
|
|
|
static unique_ptr<WaveRecorder> _waveRecorder;
|
|
|
|
static SimpleLock _waveRecorderLock;
|
2016-06-26 00:46:54 +00:00
|
|
|
static double _fadeRatio;
|
|
|
|
static uint32_t _muteFrameCount;
|
2016-06-05 18:36:20 +00:00
|
|
|
|
2016-01-15 00:33:16 +00:00
|
|
|
static IAudioDevice* AudioDevice;
|
|
|
|
static const uint32_t MaxSampleRate = 48000;
|
2016-12-10 02:23:20 +00:00
|
|
|
static const uint32_t MaxSamplesPerFrame = MaxSampleRate / 60 * 4 * 2; //x4 to allow CPU overclocking up to 10x, x2 for panning stereo
|
2016-06-26 00:46:54 +00:00
|
|
|
static const uint32_t MaxChannelCount = 11;
|
2016-06-05 18:36:20 +00:00
|
|
|
|
2016-12-10 02:23:20 +00:00
|
|
|
CrossFeedFilter _crossFeedFilter;
|
2016-01-31 18:53:17 +00:00
|
|
|
LowPassFilter _lowPassFilter;
|
2016-02-21 20:31:39 +00:00
|
|
|
StereoPanningFilter _stereoPanning;
|
|
|
|
StereoDelayFilter _stereoDelay;
|
|
|
|
ReverbFilter _reverbFilter;
|
2016-01-15 00:33:16 +00:00
|
|
|
|
2016-12-10 02:23:20 +00:00
|
|
|
int16_t _previousOutputLeft = 0;
|
|
|
|
int16_t _previousOutputRight = 0;
|
2016-01-14 06:21:09 +00:00
|
|
|
|
|
|
|
vector<uint32_t> _timestamps;
|
2016-06-12 15:28:45 +00:00
|
|
|
int16_t _channelOutput[MaxChannelCount][CycleLength];
|
|
|
|
int16_t _currentOutput[MaxChannelCount];
|
2016-01-14 06:21:09 +00:00
|
|
|
|
2016-12-10 02:23:20 +00:00
|
|
|
blip_t* _blipBufLeft;
|
|
|
|
blip_t* _blipBufRight;
|
2016-01-14 06:21:09 +00:00
|
|
|
int16_t *_outputBuffer;
|
2016-01-30 19:57:50 +00:00
|
|
|
double _volumes[MaxChannelCount];
|
2016-12-10 02:23:20 +00:00
|
|
|
double _panning[MaxChannelCount];
|
2016-01-14 06:21:09 +00:00
|
|
|
|
2016-06-12 22:11:31 +00:00
|
|
|
NesModel _model;
|
2016-01-15 00:33:16 +00:00
|
|
|
uint32_t _sampleRate;
|
|
|
|
uint32_t _clockRate;
|
|
|
|
|
2016-12-10 02:23:20 +00:00
|
|
|
double GetChannelOutput(AudioChannel channel, bool forRightChannel);
|
|
|
|
int16_t GetOutputVolume(bool forRightChannel);
|
2016-01-14 06:21:09 +00:00
|
|
|
void EndFrame(uint32_t time);
|
|
|
|
|
2016-06-12 22:11:31 +00:00
|
|
|
void UpdateRates(bool forceUpdate);
|
2016-01-15 00:33:16 +00:00
|
|
|
|
2016-01-21 05:53:02 +00:00
|
|
|
protected:
|
|
|
|
virtual void StreamState(bool saving);
|
|
|
|
|
2016-01-14 06:21:09 +00:00
|
|
|
public:
|
|
|
|
SoundMixer();
|
|
|
|
~SoundMixer();
|
|
|
|
|
|
|
|
void SetNesModel(NesModel model);
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
void PlayAudioBuffer(uint32_t cycle);
|
2016-06-12 15:28:45 +00:00
|
|
|
void AddDelta(AudioChannel channel, uint32_t time, int16_t delta);
|
2016-01-30 19:57:50 +00:00
|
|
|
|
2016-06-05 18:36:20 +00:00
|
|
|
static void StartRecording(string filepath);
|
|
|
|
static void StopRecording();
|
|
|
|
static bool IsRecording();
|
|
|
|
|
2016-06-26 00:46:54 +00:00
|
|
|
//For NSF/NSFe
|
|
|
|
static uint32_t GetMuteFrameCount();
|
|
|
|
static void ResetMuteFrameCount();
|
|
|
|
static void SetFadeRatio(double fadeRatio);
|
|
|
|
|
2016-01-15 00:33:16 +00:00
|
|
|
static void StopAudio(bool clearBuffer = false);
|
|
|
|
static void RegisterAudioDevice(IAudioDevice *audioDevice);
|
2016-01-14 06:21:09 +00:00
|
|
|
};
|