project64/Source/Project64-audio/Driver/SoundBase.h

46 lines
1.4 KiB
C
Raw Normal View History

2021-03-02 02:13:17 +00:00
// Project64 - A Nintendo 64 emulator
// http://www.pj64-emu.com/
// Copyright(C) 2001-2021 Project64
// Copyright(C) 2000-2015 Azimer
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
2017-09-12 07:58:35 +00:00
#pragma once
2017-09-21 13:20:36 +00:00
#include <Common/SyncEvent.h>
#include <Common/CriticalSection.h>
2017-09-12 07:58:35 +00:00
class SoundDriverBase
{
public:
2017-09-21 13:20:36 +00:00
SoundDriverBase();
2017-10-13 00:45:41 +00:00
void AI_SetFrequency(uint32_t Frequency, uint32_t BufferSize);
2017-09-21 13:20:36 +00:00
void AI_LenChanged(uint8_t *start, uint32_t length);
void AI_Startup();
void AI_Shutdown();
void AI_Update(bool Wait);
2017-09-22 21:35:09 +00:00
uint32_t AI_ReadLength();
2017-09-21 13:20:36 +00:00
2017-10-13 00:45:41 +00:00
virtual void SetFrequency(uint32_t Frequency, uint32_t BufferSize);
2017-09-21 13:20:36 +00:00
virtual void StartAudio();
virtual void StopAudio();
protected:
enum { MAX_SIZE = 48000 * 2 * 2 }; // Max buffer size (44100Hz * 16-bit * stereo)
2017-09-21 13:20:36 +00:00
virtual bool Initialize();
void LoadAiBuffer(uint8_t *start, uint32_t length); // Reads in length amount of audio bytes
uint32_t m_MaxBufferSize; // Variable size determined by playback rate
2017-09-21 13:20:36 +00:00
CriticalSection m_CS;
private:
void BufferAudio();
SyncEvent m_AiUpdateEvent;
uint8_t *m_AI_DMAPrimaryBuffer, *m_AI_DMASecondaryBuffer;
uint32_t m_AI_DMAPrimaryBytes, m_AI_DMASecondaryBytes;
uint32_t m_BufferRemaining; // Buffer remaining
uint32_t m_CurrentReadLoc; // Currently playing buffer
uint32_t m_CurrentWriteLoc; // Currently writing buffer
2017-09-21 13:20:36 +00:00
uint8_t m_Buffer[MAX_SIZE]; // Emulated buffers
2017-09-22 21:35:09 +00:00
};