filename | src/aica/audio.h |
changeset | 759:f16975739abc |
prev | 755:ab873907b00e |
next | 1024:c67f2d61ab97 |
author | nkeynes |
date | Tue Mar 24 11:15:57 2009 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Add preliminary implementation of the GDB remote debugging server - attaches to either or both the SH4 and ARM |
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"
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 #define AUDIO_CHANNEL_COUNT 64
32 #define AUDIO_FMT_8BIT 0
33 #define AUDIO_FMT_16BIT 1
34 #define AUDIO_FMT_ADPCM 2
35 #define AUDIO_FMT_FLOAT 3 // 32-bit -1.0 to 1.0
36 #define AUDIO_FMT_MONO 0
37 #define AUDIO_FMT_STEREO 4
38 #define AUDIO_FMT_SIGNED 0
39 #define AUDIO_FMT_UNSIGNED 8
41 #define AUDIO_FMT_SAMPLE_MASK 3
43 #define AUDIO_FMT_16ST (AUDIO_FMT_16BIT|AUDIO_FMT_STEREO)
44 #define AUDIO_FMT_FLOATST (AUDIO_FMT_FLOAT|AUDIO_FMT_STEREO)
46 #define DEFAULT_SAMPLE_RATE 44100
47 #define DEFAULT_SAMPLE_FORMAT AUDIO_FMT_16ST
49 typedef enum { LOOP_OFF = 0, LOOP_ON = 1, LOOP_LOOPED = 2 } loop_t;
51 typedef struct audio_channel {
52 gboolean active;
53 uint32_t posn; /* current sample #, 0 = first sample */
54 uint32_t posn_left;
55 uint32_t start;
56 uint32_t end;
57 loop_t loop;
58 uint32_t loop_start;
59 int vol; /* 0..255 */
60 int pan; /* 0 (left) .. 31 (right) */
61 uint32_t sample_rate;
62 int sample_format;
63 /* Envelope etc stuff */
64 /* ADPCM */
65 int adpcm_step;
66 int adpcm_predict;
67 } *audio_channel_t;
70 typedef struct audio_buffer {
71 uint32_t length; /* Bytes */
72 uint32_t posn; /* Bytes */
73 int status;
74 char data[0];
75 } *audio_buffer_t;
77 typedef struct audio_driver {
78 char *name;
79 char *description;
80 uint32_t sample_rate;
81 uint32_t sample_format;
82 gboolean (*init)( );
83 void (*start)( );
84 gboolean (*process_buffer)( audio_buffer_t buffer );
85 void (*stop)( );
86 gboolean (*shutdown)( );
87 } *audio_driver_t;
90 /**
91 * Print the configured audio drivers to the output stream, one to a line.
92 */
93 void print_audio_drivers( FILE *out );
95 audio_driver_t get_audio_driver_by_name( const char *name );
97 /**
98 * Set the output driver, sample rate and format. Also initializes the
99 * output buffers, flushing any current data and reallocating as
100 * necessary. Must be called before attempting to generate any audio.
101 */
102 gboolean audio_set_driver( audio_driver_t driver );
104 /**
105 * Initialize the audio driver, using the specified driver if available.
106 */
107 audio_driver_t audio_init_driver( const char *preferred_driver );
109 /**
110 * Mark the current write buffer as full and prepare the next buffer for
111 * writing. Returns the next buffer to write to.
112 * If all buffers are full, returns NULL.
113 */
114 audio_buffer_t audio_next_write_buffer();
116 /**
117 * Mark the current read buffer as empty and return the next buffer for
118 * reading. If there is no next buffer yet, returns NULL.
119 */
120 audio_buffer_t audio_next_read_buffer();
122 /**
123 * Mix a single output sample and append it to the output buffers
124 */
125 void audio_mix_samples( int num_samples );
127 /**
128 * Retrieve the channel information for the channel, numbered 0..63.
129 */
130 audio_channel_t audio_get_channel( int channel );
132 void audio_start_stop_channel( int channel, gboolean start );
133 void audio_start_channel( int channel );
134 void audio_stop_channel( int channel );
136 void audio_save_state( FILE *f );
137 int audio_load_state( FILE *f );
139 #ifdef __cplusplus
140 }
141 #endif
143 #endif /* !lxdream_audio_H */
.