summaryrefslogtreecommitdiff
path: root/apps/plugins/pacbox/wsg3.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pacbox/wsg3.h')
-rw-r--r--apps/plugins/pacbox/wsg3.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/apps/plugins/pacbox/wsg3.h b/apps/plugins/pacbox/wsg3.h
new file mode 100644
index 0000000000..1ee385cdf9
--- /dev/null
+++ b/apps/plugins/pacbox/wsg3.h
@@ -0,0 +1,124 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Pacbox - a Pacman Emulator for Rockbox
11 *
12 * Based on PIE - Pacman Instructional Emulator
13 *
14 * Namco custom waveform sound generator 3 (Pacman hardware)
15 *
16 * Copyright (c) 2003,2004 Alessandro Scotti
17 * http://www.ascotti.org/
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
23 *
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
26 *
27 ****************************************************************************/
28#ifndef WSG3_H
29#define WSG3_H
30
31/**
32 Namco 3-channel sound generator voice properties.
33
34 This information is only needed by applications that want to do their own
35 sound rendering, as the playSound() function already plays and mixes all
36 three voices.
37
38 @see PacmanMachine::playSound
39*/
40struct wsg3_voice
41{
42 /** Volume (from 0 to 15) */
43 unsigned volume;
44 /** Index into the 4-bit 32-entry waveform table (0 to 7) */
45 unsigned waveform;
46 /** Frequency */
47 unsigned frequency;
48};
49
50
51struct wsg3
52{
53 unsigned master_clock;
54 unsigned sampling_rate;
55 unsigned char sound_regs[0x20];
56 unsigned char sound_prom[32*8];
57 unsigned resample_step;
58 unsigned wave_offset[3];
59 int sound_wave_data[32*8];
60};
61
62extern struct wsg3 wsg3;
63
64/**
65 Constructor.
66
67 @param masterClock clock frequency of sound chip (in Hertz)
68
69 @see #wsg3_play_sound
70*/
71void wsg3_init(unsigned master_clock);
72
73/**
74 Sets the 256 byte PROM that contains the waveform table used by the sound chip.
75*/
76void wsg3_set_sound_prom( const unsigned char * prom );
77
78/**
79 Sets the value of the specified register.
80*/
81static inline void wsg3_set_register(unsigned reg, unsigned char value)
82 { wsg3.sound_regs[reg] = value; }
83
84/**
85 Returns the value of the specified register.
86*/
87static inline unsigned char wsg3_get_register(unsigned reg)
88 { return wsg3.sound_regs[reg]; }
89
90/**
91 Reproduces the sound that is currently being generated by the sound
92 chip into the specified buffer.
93
94 The sound chip has three independent voices that generate 8-bit signed
95 PCM audio. This function resamples the voices at the currently specified
96 sampling rate and mixes them into the output buffer. The output buffer
97 can be converted to 8-bit (signed) PCM by dividing each sample by 3 (since
98 there are three voices) or it can be expanded to 16-bit by multiplying
99 each sample by 85 (i.e. 256 divided by 3). If necessary, it is possible
100 to approximate these values with 4 and 64 in order to use arithmetic
101 shifts that are usually faster to execute.
102
103 Note: this function does not clear the content of the output buffer before
104 mixing voices into it.
105
106 @param buf pointer to sound buffer that receives the audio samples
107 @param len length of the sound buffer
108*/
109void wsg3_play_sound(int * buf, int len);
110
111/**
112 Returns the sampling rate currently in use for rendering sound.
113*/
114static inline unsigned wsg3_get_sampling_rate(void)
115 { return wsg3.sampling_rate; }
116
117/**
118 Sets the output sampling rate for playSound().
119
120 @param samplingRate sampling rate in Hertz (samples per second)
121*/
122void wsg3_set_sampling_rate(unsigned sampling_rate);
123
124#endif /* WSG3_H */