2014-06-23 02:15:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2016-01-15 00:33:16 +00:00
|
|
|
#include "../Core/IAudioDevice.h"
|
2014-06-23 02:15:35 +00:00
|
|
|
|
2016-01-18 03:16:20 +00:00
|
|
|
struct SoundDeviceInfo
|
|
|
|
{
|
|
|
|
string description;
|
|
|
|
GUID guid;
|
|
|
|
};
|
|
|
|
|
2014-06-23 02:15:35 +00:00
|
|
|
class SoundManager : public IAudioDevice
|
|
|
|
{
|
|
|
|
public:
|
2014-06-23 23:02:09 +00:00
|
|
|
SoundManager(HWND hWnd);
|
2014-06-23 02:15:35 +00:00
|
|
|
~SoundManager();
|
|
|
|
|
|
|
|
void Release();
|
2016-02-21 20:31:39 +00:00
|
|
|
void PlayBuffer(int16_t *soundBuffer, uint32_t bufferSize, uint32_t sampleRate, bool isStereo);
|
2014-06-23 17:52:53 +00:00
|
|
|
void Play();
|
|
|
|
void Pause();
|
2015-08-25 00:27:07 +00:00
|
|
|
void Stop();
|
2014-06-23 02:15:35 +00:00
|
|
|
|
2016-01-18 03:16:20 +00:00
|
|
|
string GetAvailableDevices();
|
|
|
|
void SetAudioDevice(string deviceName);
|
|
|
|
|
2014-06-23 02:15:35 +00:00
|
|
|
private:
|
2016-01-18 03:16:20 +00:00
|
|
|
vector<SoundDeviceInfo> GetAvailableDeviceInfo();
|
2016-02-19 18:05:04 +00:00
|
|
|
static bool CALLBACK DirectSoundEnumProc(LPGUID lpGUID, LPCWSTR lpszDesc, LPCSTR lpszDrvName, LPVOID lpContext);
|
2016-02-21 20:31:39 +00:00
|
|
|
bool InitializeDirectSound(uint32_t sampleRate, bool isStereo);
|
2014-06-23 02:15:35 +00:00
|
|
|
void ClearSecondaryBuffer();
|
|
|
|
void CopyToSecondaryBuffer(uint8_t *data, uint32_t size);
|
|
|
|
|
|
|
|
private:
|
2016-01-15 00:33:16 +00:00
|
|
|
HWND _hWnd;
|
2016-01-18 03:16:20 +00:00
|
|
|
GUID _audioDeviceID;
|
|
|
|
bool _needReset = false;
|
2016-01-15 00:33:16 +00:00
|
|
|
|
2014-06-23 17:52:53 +00:00
|
|
|
uint16_t _lastWriteOffset = 0;
|
2015-07-18 00:58:57 +00:00
|
|
|
uint16_t _previousLatency = 0;
|
2016-01-15 00:33:16 +00:00
|
|
|
uint32_t _sampleRate = 0;
|
2016-02-21 20:31:39 +00:00
|
|
|
bool _isStereo = false;
|
2017-12-04 05:09:11 +00:00
|
|
|
bool _playing = false;
|
|
|
|
uint32_t _emulationSpeed = 100;
|
2014-06-23 17:52:53 +00:00
|
|
|
|
2014-06-23 02:15:35 +00:00
|
|
|
IDirectSound8* _directSound;
|
|
|
|
IDirectSoundBuffer* _primaryBuffer;
|
|
|
|
IDirectSoundBuffer8* _secondaryBuffer;
|
|
|
|
};
|