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