// 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#include "ameteor/audio/dsound.hpp"17#include "../globals.hpp"18#include <cstring>1920namespace AMeteor21{22namespace Audio23{24DSound::DSound () :25m_rpos(0),26m_wpos(0),27m_size(0)28{29std::memset(m_buffer, 0, sizeof(m_buffer));30}3132void DSound::FillFifo (int8_t* buffer)33{34int8_t* pmbuf = m_buffer + m_wpos;35// we copy 16 bytes of data36for (int8_t* pbuf = buffer;37pbuf < buffer + BUFFER_SIZE/2 && m_size < 32; ++pbuf, ++pmbuf)38{39if (pmbuf >= m_buffer + BUFFER_SIZE)40pmbuf = m_buffer;4142*pmbuf = *pbuf;43++m_size;44}4546m_wpos = pmbuf - m_buffer;47}4849void DSound::FillFifo (int8_t sample)50{51if (m_size == 32)52return;53if (m_wpos == BUFFER_SIZE)54m_wpos = 0;55m_buffer[m_wpos++] = sample;56++m_size;57}5859bool DSound::SaveState (std::ostream& stream)60{61SS_WRITE_VAR(m_rpos);62SS_WRITE_VAR(m_wpos);63SS_WRITE_VAR(m_size);6465SS_WRITE_ARRAY(m_buffer);6667return true;68}6970bool DSound::LoadState (std::istream& stream)71{72SS_READ_VAR(m_rpos);73SS_READ_VAR(m_wpos);74SS_READ_VAR(m_size);7576SS_READ_ARRAY(m_buffer);7778return true;79}80}81}828384