filename | src/aica/audio.h |
changeset | 1089:a3984d242909 |
prev | 1024:c67f2d61ab97 |
next | 1296:30ecee61f811 |
author | nkeynes |
date | Sun Oct 24 15:22:59 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Eliminate GL_REPLACE tex mode in favour of GL_MODULATE (by setting colour values to 1.0) - one less case for shaders to care about later |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Audio engine, ie the part that does the actual work.
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
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.
12 *
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.
17 */
18 #ifndef lxdream_audio_H
19 #define lxdream_audio_H 1
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <glib/gtypes.h>
24 #include "gettext.h"
25 #include "plugin.h"
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
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)
46 #define AUDIO_MEM_MASK 0x1FFFFF
48 #define DEFAULT_SAMPLE_RATE 44100
49 #define DEFAULT_SAMPLE_FORMAT AUDIO_FMT_16ST
51 typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
53 typedef struct audio_channel {
54 gboolean active;
55 uint32_t posn; /* current sample #, 0 = first sample */
56 uint32_t posn_left;
57 uint32_t start;
58 uint32_t end;
59 loop_t loop;
60 uint32_t loop_start;
61 int vol; /* 0..255 */
62 int pan; /* 0 (left) .. 31 (right) */
63 uint32_t sample_rate;
64 int sample_format;
65 /* Envelope etc stuff */
66 /* ADPCM */
67 int adpcm_step;
68 int adpcm_predict;
69 } *audio_channel_t;
72 typedef struct audio_buffer {
73 uint32_t length; /* Bytes */
74 uint32_t posn; /* Bytes */
75 int status;
76 char data[0];
77 } *audio_buffer_t;
79 typedef struct audio_driver {
80 const char *name;
81 const char *description;
82 int priority; /* Lower == higher priority */
83 uint32_t sample_rate;
84 uint32_t sample_format;
85 gboolean (*init)( );
86 void (*start)( );
87 gboolean (*process_buffer)( audio_buffer_t buffer );
88 void (*stop)( );
89 gboolean (*shutdown)( );
90 } *audio_driver_t;
93 /**
94 * Print the configured audio drivers to the output stream, one to a line.
95 */
96 void print_audio_drivers( FILE *out );
98 audio_driver_t get_audio_driver_by_name( const char *name );
100 /**
101 * Set the output driver, sample rate and format. Also initializes the
102 * output buffers, flushing any current data and reallocating as
103 * necessary. Must be called before attempting to generate any audio.
104 */
105 gboolean audio_set_driver( audio_driver_t driver );
107 /**
108 * Initialize the audio driver, using the specified driver if available.
109 */
110 audio_driver_t audio_init_driver( const char *preferred_driver );
112 /**
113 * Add a new audio driver to the available drivers list
114 */
115 gboolean audio_register_driver( audio_driver_t driver );
117 /**
118 * Signal the audio driver that playback is beginning
119 */
120 void audio_start_driver();
122 /**
123 * Signal the audio driver that playback is stopping
124 */
125 void audio_stop_driver();
127 /**
128 * Mark the current write buffer as full and prepare the next buffer for
129 * writing. Returns the next buffer to write to.
130 * If all buffers are full, returns NULL.
131 */
132 audio_buffer_t audio_next_write_buffer();
134 /**
135 * Mark the current read buffer as empty and return the next buffer for
136 * reading. If there is no next buffer yet, returns NULL.
137 */
138 audio_buffer_t audio_next_read_buffer();
140 /**
141 * Mix a single output sample and append it to the output buffers
142 */
143 void audio_mix_samples( int num_samples );
145 /**
146 * Retrieve the channel information for the channel, numbered 0..63.
147 */
148 audio_channel_t audio_get_channel( int channel );
150 void audio_start_stop_channel( int channel, gboolean start );
151 void audio_start_channel( int channel );
152 void audio_stop_channel( int channel );
154 void audio_save_state( FILE *f );
155 int audio_load_state( FILE *f );
157 #ifdef __cplusplus
158 }
159 #endif
161 #endif /* !lxdream_audio_H */
.