annotate playsound/test_sdlsound.c @ 29:0e27c909c952 release-0.1.1

Upped version to 0.1.1
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 19 Sep 2001 14:34:52 +0000
parents 4acb5260d684
children 3d34b03167f2
rev   line source
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /**
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * This is a quick and dirty test of SDL_sound.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * Please see the file LICENSE in the source's root directory.
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <stdio.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include <assert.h>
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #include "SDL.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #include "SDL_sound.h"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #define TEST_VERSION_MAJOR 0
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #define TEST_VERSION_MINOR 1
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #define TEST_VERSION_PATCH 0
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 static void output_versions(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 Sound_Version compiled;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 Sound_Version linked;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 SDL_version sdl_compiled;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 const SDL_version *sdl_linked;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 SOUND_VERSION(&compiled);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 Sound_GetLinkedVersion(&linked);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 SDL_VERSION(&sdl_compiled);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 sdl_linked = SDL_Linked_Version();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 printf("test_sdlsound version %d.%d.%d.\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 " Compiled against SDL_sound version %d.%d.%d,\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 " and linked against %d.%d.%d.\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 " Compiled against SDL version %d.%d.%d,\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 " and linked against %d.%d.%d.\n\n",
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 compiled.major, compiled.minor, compiled.patch,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 linked.major, linked.minor, linked.patch,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 sdl_compiled.major, sdl_compiled.minor, sdl_compiled.patch,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 sdl_linked->major, sdl_linked->minor, sdl_linked->patch);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 } /* output_versions */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 static void output_decoders(void)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 const Sound_DecoderInfo **rc = Sound_AvailableDecoders();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 const Sound_DecoderInfo **i;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67
13
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
68 printf("Supported sound formats:\n");
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 if (*rc == NULL)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 printf(" * Apparently, NONE!\n");
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 else
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 for (i = rc; *i != NULL; i++)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 printf(" * %s: %s\n Written by %s.\n %s\n",
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 (*i)->extension, (*i)->description,
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 (*i)->author, (*i)->url);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 } /* for */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 } /* else */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 printf("\n");
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 } /* output_decoders */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 static volatile int done_flag = 0;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 void test_callback(void *userdata, Uint8 *stream, int len)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 {
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
89 static Uint8 overflow[16384]; /* this is a hack. */
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
90 static Uint32 overflowBytes = 0;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 Sound_Sample *sample = (Sound_Sample *) userdata;
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
92 Uint32 bw = 0; /* bytes written to stream*/
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
93 Uint32 rc; /* return code */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
95 if (overflowBytes > 0)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
96 {
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
97 memcpy(stream, overflow, overflowBytes);
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
98 bw = overflowBytes;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
99 overflowBytes = 0;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
100 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
102 while ((bw < len) && (!done_flag))
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 {
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
104 rc = Sound_Decode(sample);
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
105 if (rc > 0)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
106 {
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
107 if (bw + rc > len)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
108 {
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
109 overflowBytes = (bw + rc) - len;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
110 memcpy(overflow,
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
111 ((Uint8 *) sample->buffer) + (rc - overflowBytes),
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
112 overflowBytes);
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
113 rc -= overflowBytes;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
114 } /* if */
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
116 memcpy(stream + bw, sample->buffer, rc);
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
117 bw += rc;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
118 } /* if */
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
119
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
120 if (sample->flags & SOUND_SAMPLEFLAG_EOF)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
121 done_flag = 1;
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
25
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
123 else if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
124 {
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
125 printf("Error condition in decoding!\n");
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
126 done_flag = 1;
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
127 } /* else if */
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
128 } /* while */
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
129
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
130 assert(bw <= len);
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
131
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
132 if (bw < len)
4acb5260d684 Made the SDL audio callback much more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 13
diff changeset
133 memset(stream + bw, '\0', len - bw);
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 } /* test_callback */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 int main(int argc, char **argv)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 Sound_AudioInfo sound_desired;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 SDL_AudioSpec sdl_desired;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 Sound_Sample *sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 if (SDL_Init(SDL_INIT_AUDIO) == -1)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 printf("SDL_Init(SDL_INIT_AUDIO) failed!\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 " reason: [%s].\n", SDL_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 return(42);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 if (!Sound_Init())
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 printf("Sound_Init() failed!\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 " reason: [%s].\n", Sound_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 SDL_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 return(42);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 output_versions();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 output_decoders();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 if (argc != 2)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 printf("USAGE: %s <oneSupportedFile>\n", argv[0]);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 Sound_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 SDL_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 return(42);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 sound_desired.rate = 44100;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 sound_desired.channels = 2;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 sound_desired.format = AUDIO_S16;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 sample = Sound_NewSampleFromFile(argv[1], &sound_desired, 4096 * 4);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 if (!sample)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 printf("Sound_NewSampleFromFile(\"%s\") failed!\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 " reason: [%s].\n", argv[1], Sound_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 Sound_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 SDL_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 return(42);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 sdl_desired.freq = 44100;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 sdl_desired.format = AUDIO_S16;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 sdl_desired.channels = 2;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 sdl_desired.samples = 4096;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 sdl_desired.callback = test_callback;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 sdl_desired.userdata = sample;
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
13
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
190 #if 1
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 if ( SDL_OpenAudio(&sdl_desired, NULL) < 0 )
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 {
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 printf("SDL_OpenAudio() failed!\n"
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 " reason: [%s].\n", SDL_GetError());
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 Sound_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 SDL_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 return(42);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 } /* if */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 SDL_PauseAudio(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 while (!done_flag)
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 SDL_Delay(10);
13
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
203 SDL_PauseAudio(1);
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
204
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
205 /*
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
206 * This just decodes the file, and dumps the decoded waveform to
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
207 * stderr. Use with caution.
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
208 */
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
209 #else
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
210 {
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
211 Uint32 rc;
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
212 while ((rc = Sound_Decode(sample)) == sample->buffer_size)
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
213 fwrite(sample->buffer, rc, 1, stderr);
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
214 }
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
215 #endif
f2af6266775f Minor fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 4
diff changeset
216
4
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 Sound_FreeSample(sample);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 Sound_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 SDL_Quit();
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 return(0);
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 } /* main */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 /* end of test_sdlsound.c ... */
341cea3e13c6 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226