Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/audio/dsound.hpp
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
#ifndef __AUDIO_D_SOUND_H__
18
#define __AUDIO_D_SOUND_H__
19
20
#include <stdint.h>
21
#include <istream>
22
#include <ostream>
23
24
namespace AMeteor
25
{
26
namespace Audio
27
{
28
class DSound
29
{
30
public :
31
static const int BUFFER_SIZE = 32;
32
33
DSound ();
34
35
void FillFifo (int8_t* buffer);
36
void FillFifo (int8_t sample);
37
38
void NextSample ()
39
{
40
// if the buffer is empty, there is nothing to do
41
if (m_size)
42
// if this was the last sample, we reset all and send 0 to all next
43
// GetSample()s until the buffer is refilled
44
if (--m_size == 0)
45
Reset();
46
// else, we go on to next sample and we go to the first if we got
47
// to the last
48
else if (++m_rpos >= BUFFER_SIZE)
49
m_rpos = 0;
50
}
51
52
void Reset ()
53
{
54
m_buffer[0] = m_size = m_rpos = m_wpos = 0;
55
}
56
57
int8_t GetSample()
58
{
59
return m_buffer[m_rpos];
60
}
61
62
uint8_t GetSize ()
63
{
64
return m_size;
65
};
66
67
bool SaveState (std::ostream& stream);
68
bool LoadState (std::istream& stream);
69
70
private :
71
int8_t m_buffer[BUFFER_SIZE];
72
uint8_t m_rpos, m_wpos;
73
uint8_t m_size;
74
};
75
}
76
}
77
78
#endif
79
80