1 /* 2 * ============================================================================ 3 * Title: Sound Interface Abstraction 4 * Author: J. Zbiciak 5 * ============================================================================ 6 * 7 * ============================================================================ 8 * SND_TICK -- Update state of the sound universe. Drains audio data 9 * from the PSGs and prepares it for SDL's sound layer. 10 * SND_FILL -- Audio callback used by SDL for filling SDL's buffers. 11 * SND_REGISTER -- Registers a PSG with the SND module. 12 * SND_INIT -- Initialize a SND_T 13 * ============================================================================ 14 */ 15 #ifndef SND_H_ 16 #define SND_H_ 17 18 /* 19 * ============================================================================ 20 * SND_T -- Main sound interface object. 21 * SND_BUF_T -- Sound buffer abstraction. 22 * ============================================================================ 23 */ 24 25 struct avi_writer_t; /* forward decl */ 26 typedef struct snd_pvt_t *snd_pvt_p; 27 typedef struct snd_t *snd_p; 28 29 typedef struct snd_buf_t 30 { 31 /* Sound data */ 32 int16_t *buf; /* Audio data buffers. */ 33 34 int16_t **dirty; /* Array of dirty buffers. */ 35 int16_t **clean; /* Array of clean buffers. */ 36 37 int num_dirty; /* Number of dirty buffers */ 38 int num_clean; /* Number of clean buffers. */ 39 int tot_buf; /* Total number of buffers. */ 40 41 int drop; /* Request a frame drop. */ 42 int tot_drop; /* Total number of buffers dropped. */ 43 44 int top_dirty_ptr; /* Pointer into top dirty buffer */ 45 /* used by snd_fill in case a partial */ 46 /* buffer request is made (ick). */ 47 48 snd_p snd; /* parent pointer */ 49 } snd_buf_t; 50 51 typedef struct snd_t 52 { 53 periph_t periph; /* Yes, sound is a peripheral. */ 54 snd_buf_t **src; /* Input sound buffers. */ 55 int src_cnt; /* Number of input sources. */ 56 snd_buf_t mixbuf; /* Mixed audio data to go out. */ 57 uint64_t samples; /* Cumulative # of samples processed. */ 58 uint64_t tot_frame; /* Cumulative # of frames processed. */ 59 uint64_t tot_dirty; /* Cumulative # dirty from snd_fill. */ 60 uint32_t rate; /* Sample rate in Hz. */ 61 int cyc_per_sec; /* PAL vs. NTSC. */ 62 double time_scale; /* For --macho. */ 63 64 uint32_t change_vol; /* Requests to change volume */ 65 int atten; /* Attenuation. 0=full blast, 16=mute */ 66 67 FILE *raw_file; /* Raw audio data dump file. */ 68 int raw_start; /* FLAG: To suppress silence @ start */ 69 70 int buf_size; 71 int buf_cnt; 72 73 snd_pvt_p pvt; /* Private stuff (API specific) */ 74 } snd_t; 75 76 77 /* 78 * ============================================================================ 79 * SND_REGISTER -- Registers a sound input buffer with the sound object 80 * ============================================================================ 81 */ 82 int snd_register(periph_t *const snd, snd_buf_t *const src); 83 84 /* 85 * ============================================================================ 86 * SND_INIT -- Initialize a SND_T 87 * ============================================================================ 88 */ 89 int snd_init(snd_t *snd, int rate, char *raw_file, 90 int user_snd_buf_size, int user_snd_buf_cnt, 91 struct avi_writer_t *const avi, int pal_mode, 92 double time_scale); 93 94 /* 95 * ============================================================================ 96 * SND_PLAY_SILENCE -- Pump silent audio frame. (Used during reset.) 97 * ============================================================================ 98 */ 99 void snd_play_silence(snd_t *const snd); 100 101 /* 102 * ============================================================================ 103 * SND_PLAY_STATIC -- A silly bit of fun. 104 * ============================================================================ 105 */ 106 void snd_play_static(snd_t *const snd); 107 108 109 #endif 110 /* ======================================================================== */ 111 /* This program is free software; you can redistribute it and/or modify */ 112 /* it under the terms of the GNU General Public License as published by */ 113 /* the Free Software Foundation; either version 2 of the License, or */ 114 /* (at your option) any later version. */ 115 /* */ 116 /* This program is distributed in the hope that it will be useful, */ 117 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 118 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 119 /* General Public License for more details. */ 120 /* */ 121 /* You should have received a copy of the GNU General Public License along */ 122 /* with this program; if not, write to the Free Software Foundation, Inc., */ 123 /* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ 124 /* ======================================================================== */ 125 /* Copyright (c) 1998-1999, Joseph Zbiciak */ 126 /* ======================================================================== */ 127