Path: blob/master/libmeteor/include/ameteor/audio/dsound.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_D_SOUND_H__17#define __AUDIO_D_SOUND_H__1819#include <stdint.h>20#include <istream>21#include <ostream>2223namespace AMeteor24{25namespace Audio26{27class DSound28{29public :30static const int BUFFER_SIZE = 32;3132DSound ();3334void FillFifo (int8_t* buffer);35void FillFifo (int8_t sample);3637void NextSample ()38{39// if the buffer is empty, there is nothing to do40if (m_size)41// if this was the last sample, we reset all and send 0 to all next42// GetSample()s until the buffer is refilled43if (--m_size == 0)44Reset();45// else, we go on to next sample and we go to the first if we got46// to the last47else if (++m_rpos >= BUFFER_SIZE)48m_rpos = 0;49}5051void Reset ()52{53m_buffer[0] = m_size = m_rpos = m_wpos = 0;54}5556int8_t GetSample()57{58return m_buffer[m_rpos];59}6061uint8_t GetSize ()62{63return m_size;64};6566bool SaveState (std::ostream& stream);67bool LoadState (std::istream& stream);6869private :70int8_t m_buffer[BUFFER_SIZE];71uint8_t m_rpos, m_wpos;72uint8_t m_size;73};74}75}7677#endif787980