Audio.h (1802B)
1/* 2 * Gearboy - Nintendo Game Boy Emulator 3 * Copyright (C) 2012 Ignacio Sanchez 4 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see http://www.gnu.org/licenses/ 17 * 18 */ 19 20#ifndef AUDIO_H 21#define AUDIO_H 22 23#include "definitions.h" 24#include "audio/Multi_Buffer.h" 25#include "audio/Gb_Apu.h" 26 27class Audio 28{ 29public: 30 Audio(); 31 ~Audio(); 32 void Init(); 33 void Reset(bool bCGB); 34 void SetSampleRate(int rate); 35 void SetVolume(float volume); 36 u8 ReadAudioRegister(u16 address); 37 void WriteAudioRegister(u16 address, u8 value); 38 void Tick(unsigned int clockCycles); 39 void EndFrame(s16* pSampleBuffer, int* pSampleCount); 40 void SaveState(std::ostream& stream); 41 void LoadState(std::istream& stream); 42 Gb_Apu* GetApu(); 43 44private: 45 Gb_Apu* m_pApu; 46 Stereo_Buffer* m_pBuffer; 47 int m_ElapsedCycles; 48 int m_SampleRate; 49 blip_sample_t* m_pSampleBuffer; 50 bool m_bCGB; 51}; 52 53inline void Audio::Tick(unsigned int clockCycles) 54{ 55 m_ElapsedCycles += clockCycles; 56} 57 58inline u8 Audio::ReadAudioRegister(u16 address) 59{ 60 return m_pApu->read_register(m_ElapsedCycles, address); 61} 62 63inline void Audio::WriteAudioRegister(u16 address, u8 value) 64{ 65 m_pApu->write_register(m_ElapsedCycles, address, value); 66} 67 68#endif /* AUDIO_H */