New audio subsystem.
[jog] / ausys-fake.c
CommitLineData
e9060e7e 1/* -*-c-*-
2 *
3 * $Id: ausys-fake.c,v 1.1 2002/02/02 19:16:28 mdw Exp $
4 *
5 * Fake not-audio-at-all audio driver
6 *
7 * (c) 2002 Mark Wooding
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Jog: Programming for a jogging machine.
13 *
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.
18 *
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.
23 *
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.
27 */
28
29/*----- Revision history --------------------------------------------------*
30 *
31 * $Log: ausys-fake.c,v $
32 * Revision 1.1 2002/02/02 19:16:28 mdw
33 * New audio subsystem.
34 *
35 */
36
37/*----- Header files ------------------------------------------------------*/
38
39#ifdef HAVE_CONFIG_H
40# include "config.h"
41#endif
42
43#include <stdio.h>
44#include <string.h>
45
46#include <mLib/alloc.h>
47#include <mLib/sub.h>
48#include <mLib/trace.h>
49
50#include "au.h"
51#include "ausys.h"
52#include "jog.h"
53
54/*----- Global variables --------------------------------------------------*/
55
56const char *const ausys_suffix = "txt";
57
58/*----- Main code ---------------------------------------------------------*/
59
60/* --- @ausys_init@ --- *
61 *
62 * Arguments: ---
63 *
64 * Returns: ---
65 *
66 * Use: Does any initialization required by the system-specific audio
67 * handler.
68 */
69
70void ausys_init(void)
71{
72 T( trace(T_AUSYS, "ausys: initalized ok"); )
73}
74
75/* --- @ausys_shutdown@ --- *
76 *
77 * Arguments: ---
78 *
79 * Returns: ---
80 *
81 * Use: Does any tidying up required.
82 */
83
84void ausys_shutdown(void)
85{
86 T( trace(T_AUSYS, "ausys: shut down ok"); )
87}
88
89/* --- @ausys_lock@, @ausys_unlock@ --- *
90 *
91 * Arguments: ---
92 *
93 * Returns: ---
94 *
95 * Use: Locks or unlocks the audio subsystem. This protects the
96 * audio queue from becoming corrupted during all the tedious
97 * asynchronous stuff.
98 */
99
100void ausys_lock(void) { T( trace(T_AUSYS, "ausys: acquired lock"); ) ; }
101void ausys_unlock(void) { T( trace(T_AUSYS, "ausys: released lock"); ) ; }
102
103/* --- @ausys_decode@ --- *
104 *
105 * Arguments: @au_sample *s@ = pointer to sample block
106 * @const void *p@ = pointer to sample file contents
107 * @size_t sz@ = size of sample file contents
108 *
109 * Returns: Pointer to a sample data structure.
110 *
111 * Use: Decodes a WAV file into something the system-specific layer
112 * actually wants to deal with.
113 */
114
115au_data *ausys_decode(au_sample *s, const void *p, size_t sz)
116{
117 au_data *a = CREATE(au_data);
118 const octet *pp = p;
119 const octet *qq = memchr(pp, '\n', sz);
120
121 if (qq)
122 sz = qq - pp;
123 else
124 sz++;
125 a->p = xmalloc(sz);
126 a->sz = sz;
127 memcpy(a->p, p, sz);
128 a->p[sz] = 0;
129 T( trace(T_AUSYS, "ausys: decoded `%s' ok", SYM_NAME(s)); )
130 return (a);
131}
132
133/* --- @ausys_queue@ --- *
134 *
135 * Arguments: @au_data *a@ = an audio thingy to play
136 *
137 * Returns: ---
138 *
139 * Use: Queues an audio sample to be played. The sample should be
140 * freed (with @au_free@) when it's no longer wanted.
141 */
142
143void ausys_queue(au_data *a)
144{
145 T( trace(T_AUSYS, "ausys: queuing `%s'", SYM_NAME(a->s)); )
146 printf("[%s]\n", a->p);
147 au_free(a);
148}
149
150/* --- @ausys_free@ --- *
151 *
152 * Arguments: @au_data *a@ = an audio thingy to free
153 *
154 * Returns: ---
155 *
156 * Use: Frees a decoded audio sample.
157 */
158
159void ausys_free(au_data *a)
160{
161 T( trace(T_AUSYS, "ausys: freeing data for `%s' ok", SYM_NAME(a->s)); )
162 xfree(a->p);
163 DESTROY(a);
164}
165
166/*----- That's all, folks -------------------------------------------------*/