Path: blob/master/libmeteor/include/ameteor/audio/speaker.hpp
2 views
// Meteor - A Nintendo Gameboy Advance emulator1// Copyright (C) 2009-2011 Philippe Daouadi2//3// This program is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// This program is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with this program. If not, see <http://www.gnu.org/licenses/>.1516#ifndef __AUDIO_SPEAKER_H__17#define __AUDIO_SPEAKER_H__1819#include <stdint.h>20#include <istream>21#include <ostream>22#include <syg/signal.hpp>23#include "sound1.hpp"24#include "sound2.hpp"25#include "sound4.hpp"26#include "dsound.hpp"2728namespace AMeteor29{30namespace Audio31{32class Speaker33{34public :35typedef syg::slot1<void, const int16_t*> FrameSlot;3637Speaker (uint16_t& cnt1l, uint16_t& cnt1h, uint16_t& cnt1x,38uint16_t& cnt2l, uint16_t& cnt2h,39uint16_t& cnt4l, uint16_t& cnt4h,40uint16_t& cntl, uint16_t& cnth, uint16_t& cntx, uint16_t& bias);41~Speaker ();4243inline void SetFrameSlot (const FrameSlot& slot);4445void Reset ();4647inline void ResetSound1 ();48inline void ResetSound2 ();49inline void ResetSound4 ();50inline void ResetSound1Envelope ();51inline void ResetSound2Envelope ();52inline void ResetSound4Envelope ();5354inline void FillFifoA (int8_t* buffer);55inline void FillFifoB (int8_t* buffer);56inline void FillFifoA (int8_t sample);57inline void FillFifoB (int8_t sample);5859inline void ResetFifoA ();60inline void ResetFifoB ();6162inline void NextSampleA ();63inline void NextSampleB ();6465inline uint8_t GetSizeA();66inline uint8_t GetSizeB();6768void SoundTick ();6970bool SaveState (std::ostream& stream);71bool LoadState (std::istream& stream);7273private :74Sound1 m_sound1;75Sound2 m_sound2;76Sound4 m_sound4;77DSound m_dsa, m_dsb;78uint16_t &m_cntl, &m_cnth, &m_cntx, &m_bias;7980FrameSlot m_sig_frame;8182int16_t MixSample (uint16_t cntl, uint8_t cnth);83};8485inline void Speaker::SetFrameSlot (const FrameSlot& slot)86{87m_sig_frame = slot;88}8990inline void Speaker::ResetSound1 ()91{92m_sound1.ResetSound ();93}9495inline void Speaker::ResetSound2 ()96{97m_sound2.ResetSound ();98}99100inline void Speaker::ResetSound4 ()101{102m_sound4.ResetSound ();103}104105inline void Speaker::ResetSound1Envelope ()106{107m_sound1.ResetEnvelope();108}109110inline void Speaker::ResetSound2Envelope ()111{112m_sound2.ResetEnvelope();113}114115inline void Speaker::ResetSound4Envelope ()116{117m_sound4.ResetEnvelope();118}119120inline void Speaker::FillFifoA (int8_t* buffer)121{122m_dsa.FillFifo(buffer);123}124125inline void Speaker::FillFifoB (int8_t* buffer)126{127m_dsb.FillFifo(buffer);128}129130inline void Speaker::FillFifoA (int8_t sample)131{132m_dsa.FillFifo(sample);133}134135inline void Speaker::FillFifoB (int8_t sample)136{137m_dsb.FillFifo(sample);138}139140inline void Speaker::ResetFifoA ()141{142m_dsa.Reset();143}144145inline void Speaker::ResetFifoB ()146{147m_dsb.Reset();148}149150inline void Speaker::NextSampleA ()151{152m_dsa.NextSample();153}154155inline void Speaker::NextSampleB ()156{157m_dsb.NextSample();158}159160inline uint8_t Speaker::GetSizeA()161{162return m_dsa.GetSize();163}164165inline uint8_t Speaker::GetSizeB()166{167return m_dsb.GetSize();168}169}170}171172#endif173174175