1 #ifndef SOUND_H
2 #define SOUND_H
3 
4 // Sound emulation setup/options and GBA sound emulation
5 
6 #include "../System.h"
7 
8 //// Setup/options (these affect GBA and GB sound)
9 
10 // Initializes sound and returns true if successful. Sets sound quality to
11 // current value in soundQuality global.
12 bool soundInit();
13 
14 // sets the Sound throttle
15 void soundSetThrottle(unsigned short throttle);
16 
17 // Manages sound volume, where 1.0 is normal
18 void soundSetVolume( float );
19 float soundGetVolume();
20 
21 // Manages muting bitmask. The bits control the following channels:
22 // 0x001 Pulse 1
23 // 0x002 Pulse 2
24 // 0x004 Wave
25 // 0x008 Noise
26 // 0x100 PCM 1
27 // 0x200 PCM 2
28 void soundSetEnable( int mask );
29 int  soundGetEnable();
30 
31 // Pauses/resumes system sound output
32 void soundPause();
33 void soundResume();
34 extern bool soundPaused; // current paused state
35 
36 // Cleans up sound. Afterwards, soundInit() can be called again.
37 void soundShutdown();
38 
39 //// GBA sound options
40 
41 long soundGetSampleRate();
42 void soundSetSampleRate(long sampleRate);
43 
44 // Sound settings
45 extern bool soundInterpolation; // 1 if PCM should have low-pass filtering
46 extern float soundFiltering;    // 0.0 = none, 1.0 = max
47 
48 
49 //// GBA sound emulation
50 
51 // GBA sound registers
52 #define SGCNT0_H 0x82
53 #define FIFOA_L 0xa0
54 #define FIFOA_H 0xa2
55 #define FIFOB_L 0xa4
56 #define FIFOB_H 0xa6
57 
58 // Resets emulated sound hardware
59 void soundReset();
60 
61 // Emulates write to sound hardware
62 void soundEvent( u32 addr, u8  data );
63 void soundEvent( u32 addr, u16 data ); // TODO: error-prone to overload like this
64 
65 // Notifies emulator that a timer has overflowed
66 void soundTimerOverflow( int which );
67 
68 // Notifies emulator that PCM rate may have changed
69 void interp_rate();
70 
71 // Notifies emulator that SOUND_CLOCK_TICKS clocks have passed
72 void psoundTickfn();
73 extern int SOUND_CLOCK_TICKS;   // Number of 16.8 MHz clocks between calls to soundTick()
74 extern int soundTicks;          // Number of 16.8 MHz clocks until soundTick() will be called
75 
76 // Saves/loads emulator state
77 #ifdef __LIBRETRO__
78 void soundSaveGame( u8 *& );
79 void soundReadGame(const u8*& in, int version );
80 #else
81 void soundSaveGame( gzFile );
82 void soundReadGame( gzFile, int version );
83 #endif
84 
85 class Multi_Buffer;
86 
87 void flush_samples(Multi_Buffer * buffer);
88 
89 #endif // SOUND_H
90