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
23 #include <glib/gtypes.h>
24 #include <glib/gi18n.h>
31 #define AUDIO_CHANNEL_COUNT 64
33 #define AUDIO_FMT_8BIT 0
34 #define AUDIO_FMT_16BIT 1
35 #define AUDIO_FMT_ADPCM 2
36 #define AUDIO_FMT_FLOAT 3 // 32-bit -1.0 to 1.0
37 #define AUDIO_FMT_MONO 0
38 #define AUDIO_FMT_STEREO 4
39 #define AUDIO_FMT_SIGNED 0
40 #define AUDIO_FMT_UNSIGNED 8
42 #define AUDIO_FMT_SAMPLE_MASK 3
44 #define AUDIO_FMT_16ST (AUDIO_FMT_16BIT|AUDIO_FMT_STEREO)
45 #define AUDIO_FMT_FLOATST (AUDIO_FMT_FLOAT|AUDIO_FMT_STEREO)
47 #define DEFAULT_SAMPLE_RATE 44100
48 #define DEFAULT_SAMPLE_FORMAT AUDIO_FMT_16ST
50 typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
52 typedef struct audio_channel {
54 uint32_t posn; /* current sample #, 0 = first sample */
61 int pan; /* 0 (left) .. 31 (right) */
64 /* Envelope etc stuff */
71 typedef struct audio_buffer {
72 uint32_t length; /* Bytes */
73 uint32_t posn; /* Bytes */
78 typedef struct audio_driver {
82 uint32_t sample_format;
85 gboolean (*process_buffer)( audio_buffer_t buffer );
87 gboolean (*shutdown)( );
92 * Print the configured audio drivers to the output stream, one to a line.
94 void print_audio_drivers( FILE *out );
96 audio_driver_t get_audio_driver_by_name( const char *name );
99 * Set the output driver, sample rate and format. Also initializes the
100 * output buffers, flushing any current data and reallocating as
101 * necessary. Must be called before attempting to generate any audio.
103 gboolean audio_set_driver( audio_driver_t driver );
106 * Mark the current write buffer as full and prepare the next buffer for
107 * writing. Returns the next buffer to write to.
108 * If all buffers are full, returns NULL.
110 audio_buffer_t audio_next_write_buffer();
113 * Mark the current read buffer as empty and return the next buffer for
114 * reading. If there is no next buffer yet, returns NULL.
116 audio_buffer_t audio_next_read_buffer();
119 * Mix a single output sample and append it to the output buffers
121 void audio_mix_samples( int num_samples );
124 * Retrieve the channel information for the channel, numbered 0..63.
126 audio_channel_t audio_get_channel( int channel );
128 void audio_start_stop_channel( int channel, gboolean start );
129 void audio_start_channel( int channel );
130 void audio_stop_channel( int channel );
132 void audio_save_state( FILE *f );
133 int audio_load_state( FILE *f );
.