Mesen/Core/SoundMixer.h

86 lines
2.2 KiB
C
Raw Normal View History

#pragma once
#include "stdafx.h"
#include "EmulationSettings.h"
#include "../Utilities/LowPassFilter.h"
2016-05-22 12:14:55 +00:00
#include "../Utilities/blip_buf.h"
#include "../Utilities/SimpleLock.h"
#include "IAudioDevice.h"
#include "Snapshotable.h"
#include "StereoPanningFilter.h"
#include "StereoDelayFilter.h"
#include "ReverbFilter.h"
2016-12-10 02:23:20 +00:00
#include "CrossFeedFilter.h"
#include "WaveRecorder.h"
class SoundMixer : public Snapshotable
{
2016-01-30 19:57:50 +00:00
public:
static const uint32_t CycleLength = 1000;
2016-01-30 19:57:50 +00:00
static const uint32_t BitsPerSample = 16;
private:
static unique_ptr<WaveRecorder> _waveRecorder;
static SimpleLock _waveRecorderLock;
2016-06-26 00:46:54 +00:00
static double _fadeRatio;
static uint32_t _muteFrameCount;
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-12-10 02:23:20 +00:00
CrossFeedFilter _crossFeedFilter;
LowPassFilter _lowPassFilter;
StereoPanningFilter _stereoPanning;
StereoDelayFilter _stereoDelay;
ReverbFilter _reverbFilter;
2016-12-10 02:23:20 +00:00
int16_t _previousOutputLeft = 0;
int16_t _previousOutputRight = 0;
vector<uint32_t> _timestamps;
int16_t _channelOutput[MaxChannelCount][CycleLength];
int16_t _currentOutput[MaxChannelCount];
2016-12-10 02:23:20 +00:00
blip_t* _blipBufLeft;
blip_t* _blipBufRight;
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-06-12 22:11:31 +00:00
NesModel _model;
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);
void EndFrame(uint32_t time);
2016-06-12 22:11:31 +00:00
void UpdateRates(bool forceUpdate);
protected:
virtual void StreamState(bool saving);
public:
SoundMixer();
~SoundMixer();
void SetNesModel(NesModel model);
void Reset();
void PlayAudioBuffer(uint32_t cycle);
void AddDelta(AudioChannel channel, uint32_t time, int16_t delta);
2016-01-30 19:57:50 +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);
static void StopAudio(bool clearBuffer = false);
static void RegisterAudioDevice(IAudioDevice *audioDevice);
};