2 * $Id: audio.h,v 1.3 2006-01-12 12:38:59 nkeynes Exp $
4 * Audio engine, ie the part that does the actual work.
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #define dream_audio_H 1
22 #include <glib/gtypes.h>
28 #define AUDIO_FMT_8BIT 0
29 #define AUDIO_FMT_16BIT 1
30 #define AUDIO_FMT_ADPCM 2
31 #define AUDIO_FMT_MONO 0
32 #define AUDIO_FMT_STEREO 4
33 #define AUDIO_FMT_SIGNED 0
34 #define AUDIO_FMT_UNSIGNED 8
37 typedef struct audio_channel {
45 int vol_left; /* 0..255 */
46 int vol_right; /* 0..255 */
49 /* Envelope etc stuff */
51 int adpcm_nibble; /* 0 = low nibble, 1 = high nibble */
57 typedef struct audio_buffer {
58 uint32_t length; /* Bytes */
59 uint32_t posn; /* Bytes */
66 gboolean (*set_output_format)( uint32_t sample_rate, uint32_t format );
67 gboolean (*process_buffer)( audio_buffer_t buffer );
70 typedef struct audio_driver *audio_driver_t;
72 extern struct audio_driver null_audio_driver;
73 extern struct audio_driver esd_audio_driver;
76 * Set the output driver, sample rate and format. Also initializes the
77 * output buffers, flushing any current data and reallocating as
78 * necessary. Must be called before attempting to generate any audio.
80 void audio_set_output( audio_driver_t driver, uint32_t samplerate,
84 * Mark the current write buffer as full and prepare the next buffer for
85 * writing. Returns the next buffer to write to.
86 * If all buffers are full, returns NULL.
88 audio_buffer_t audio_next_write_buffer();
91 * Mark the current read buffer as empty and return the next buffer for
92 * reading. If there is no next buffer yet, returns NULL.
94 audio_buffer_t audio_next_read_buffer();
97 * Mix a single output sample and append it to the output buffers
99 void audio_mix_samples( int num_samples );
102 * Retrieve the channel information for the channel, numbered 0..63.
104 audio_channel_t audio_get_channel( int channel );
106 void audio_start_channel( int channel );
107 void audio_stop_channel( int channel );
.