Move paths.[ch] to firmware
[kugel-rb.git] / apps / plugins / pacbox / wsg3.h
blobfa71cd44f0617edd9a347b1c98f8df297d502947
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Pacbox - a Pacman Emulator for Rockbox
12 * Based on PIE - Pacman Instructional Emulator
14 * Namco custom waveform sound generator 3 (Pacman hardware)
16 * Copyright (c) 2003,2004 Alessandro Scotti
17 * http://www.ascotti.org/
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.
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
27 ****************************************************************************/
28 #ifndef WSG3_H
29 #define WSG3_H
31 /**
32 Namco 3-channel sound generator voice properties.
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.
38 @see PacmanMachine::playSound
40 struct wsg3_voice
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;
51 struct wsg3
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 int16_t sound_wave_data[32*8]; /* sign-extended 4-bit, prenormalized */
62 extern struct wsg3 wsg3;
64 /**
65 Constructor.
67 @param masterClock clock frequency of sound chip (in Hertz)
69 @see #wsg3_play_sound
71 void wsg3_init(unsigned master_clock);
73 /**
74 Sets the 256 byte PROM that contains the waveform table used by the sound chip.
76 void wsg3_set_sound_prom( const unsigned char * prom );
78 /**
79 Sets the value of the specified register.
81 static inline void wsg3_set_register(unsigned reg, unsigned char value)
82 { wsg3.sound_regs[reg] = value; }
84 /**
85 Returns the value of the specified register.
87 static inline unsigned char wsg3_get_register(unsigned reg)
88 { return wsg3.sound_regs[reg]; }
90 /**
91 Reproduces the sound that is currently being generated by the sound
92 chip into the specified buffer.
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.
103 Note: this function does not clear the content of the output buffer before
104 mixing voices into it.
106 @param buf pointer to sound buffer that receives the audio samples
107 @param len length of the sound buffer
109 void wsg3_play_sound(int16_t * buf, int len);
112 Returns the sampling rate currently in use for rendering sound.
114 static inline unsigned wsg3_get_sampling_rate(void)
115 { return wsg3.sampling_rate; }
118 Sets the output sampling rate for playSound().
120 @param samplingRate sampling rate in Hertz (samples per second)
122 void wsg3_set_sampling_rate(unsigned sampling_rate);
124 #endif /* WSG3_H */