3 * $Id: au.h,v 1.1 2002/02/02 19:16:28 mdw Exp $
7 * (c) 2002 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Jog: Programming for a jogging machine.
14 * Jog is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Jog is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Jog; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 2002/02/02 19:16:28 mdw
33 * New audio subsystem.
44 /*----- Header files ------------------------------------------------------*/
48 #include <mLib/bits.h>
51 /*----- Data structures ---------------------------------------------------*/
53 /* --- An audio sample --- *
55 * We maintain a cache of sample data, keyed by textual tags. An entry in
56 * the cache may indicate one of three states:
58 * * a tag for a sample which doesn't exist (negative answer);
60 * * a sample whose data is currently resident; or
62 * * sample with nonresident data.
64 * A negative answer is indicated by the @AUF_NOMATCH@ flag. If an entry has
65 * resident data, the @a@ pointer is non-null.
68 typedef struct au_sample {
69 sym_base s; /* Base structure for name lookup */
70 unsigned f; /* Flags for this entry */
71 struct au_data *a; /* Sample data, if present */
74 #define AUF_NOMATCH 1u /* Cached non-match for this tag */
76 /* --- Audio data --- *
78 * The actual sample data, in an internal representation chosen by the
79 * system-specific layer.
81 * The sample data can be in one of two states: in-use or spare. Sample data
82 * is considered to be in-use if the @ref@ field is nonzero. Spare sample
83 * data is left in-memory for efficiency's sake, but will be discarded
84 * (least-recently-used first) when the total size of sample data (as
85 * measured by the @sz@ fields) exceeds @AU_CACHEMAX@.
88 typedef struct au_data {
89 struct au_data *next, *prev; /* Other samples in this list */
90 unsigned ref; /* Reference count for sample data */
91 struct au_sample *s; /* Parent sample node */
92 octet *p; /* Pointer to sample file data */
93 size_t sz; /* Size of sample file data */
96 #define AU_CACHEMAX 0x01000000 /* Maximum resident sample data */
98 /*----- Functions provided ------------------------------------------------*/
100 /* --- @au_init@ --- *
102 * Arguments: @const char *dir@ = samples directory, or null
103 * @size_t max@ = maximum cache size
107 * Use: Initializes the audio subsystem.
110 extern void au_init(const char */*dir*/, size_t /*max*/);
112 /* --- @au_shutdown@ --- *
118 * Use: Shuts down the audio subsystem.
121 extern void au_shutdown(void);
123 /* --- @au_find@ --- *
125 * Arguments: @const char *tag@ = sample tag string
127 * Returns: A pointer to the sample corresponding to the tag, or null if
128 * the sample wasn't found.
130 * Use: Looks up a sample by its name.
133 extern au_sample *au_find(const char */*tag*/);
135 /* --- @au_fetch@ --- *
137 * Arguments: @au_sample *s@ = sample pointer
139 * Returns: A pointer to the audio data for the sample.
141 * Use: Fetches a sample, and decodes it, if necessary. The decoded
142 * sample data is left with an outstanding reference to it, so
143 * it won't be freed. This is used internally by @au_queue@,
144 * before passing the fetched sample data to the system-specific
145 * layer for playback. It can also be used to lock sample data
146 * in memory (e.g., for the `abort' error message), or (by
147 * freeing it immediately afterwards) to prefetch a sample which
148 * will be used soon, to reduce the latency before the sample is
152 extern au_data *au_fetch(au_sample */*s*/);
154 /* --- @au_queue@ --- *
156 * Arguments: @au_sample *s@ = sample pointer
158 * Returns: Zero on success, nonzero on failure.
160 * Use: Queues a sample to be played.
163 extern int au_queue(au_sample */*s*/);
165 /* --- @au_free@, @au_free_unlocked@ --- *
167 * Arguments: @au_data *a@ = pointer to audio data block
171 * Use: Frees a sample data block when it's no longer required.
174 extern void au_free(au_data */*a*/);
175 extern void au_free_unlocked(au_data */*a*/);
177 /* --- @au_play@, @au_tryplay@ --- *
179 * Arguments: @const char *tag@ = sample tag string
181 * Returns: Zero on success, nonzero on failure.
183 * Use: Convenience functions for queueing samples by tag.
184 * If @au_tryplay@ cannot find the requested sample, it returns
185 * a zero value; if @au_play@ cannot find the sample, it aborts
189 extern int au_play(const char */*tag*/);
190 extern int au_tryplay(const char */*tag*/);
192 /*----- That's all, folks -------------------------------------------------*/