Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/source/audio/dsound.cpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#include "ameteor/audio/dsound.hpp"
18
#include "../globals.hpp"
19
#include <cstring>
20
21
namespace AMeteor
22
{
23
namespace Audio
24
{
25
DSound::DSound () :
26
m_rpos(0),
27
m_wpos(0),
28
m_size(0)
29
{
30
std::memset(m_buffer, 0, sizeof(m_buffer));
31
}
32
33
void DSound::FillFifo (int8_t* buffer)
34
{
35
int8_t* pmbuf = m_buffer + m_wpos;
36
// we copy 16 bytes of data
37
for (int8_t* pbuf = buffer;
38
pbuf < buffer + BUFFER_SIZE/2 && m_size < 32; ++pbuf, ++pmbuf)
39
{
40
if (pmbuf >= m_buffer + BUFFER_SIZE)
41
pmbuf = m_buffer;
42
43
*pmbuf = *pbuf;
44
++m_size;
45
}
46
47
m_wpos = pmbuf - m_buffer;
48
}
49
50
void DSound::FillFifo (int8_t sample)
51
{
52
if (m_size == 32)
53
return;
54
if (m_wpos == BUFFER_SIZE)
55
m_wpos = 0;
56
m_buffer[m_wpos++] = sample;
57
++m_size;
58
}
59
60
bool DSound::SaveState (std::ostream& stream)
61
{
62
SS_WRITE_VAR(m_rpos);
63
SS_WRITE_VAR(m_wpos);
64
SS_WRITE_VAR(m_size);
65
66
SS_WRITE_ARRAY(m_buffer);
67
68
return true;
69
}
70
71
bool DSound::LoadState (std::istream& stream)
72
{
73
SS_READ_VAR(m_rpos);
74
SS_READ_VAR(m_wpos);
75
SS_READ_VAR(m_size);
76
77
SS_READ_ARRAY(m_buffer);
78
79
return true;
80
}
81
}
82
}
83
84