Mercurial > SDL_sound_CoreAudio
annotate playsound/playsound.c @ 168:87b00f023710
Added --predecode functionality.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 26 Nov 2001 04:33:50 +0000 |
parents | 033afe96afbc |
children | 69922f6a5c74 |
rev | line source |
---|---|
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 * SDL_sound -- An abstract sound format decoding API. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 * Copyright (C) 2001 Ryan C. Gordon. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 * |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 * |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 * |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 /** |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 * This is a quick and dirty test of SDL_sound. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 * |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 * Please see the file LICENSE in the source's root directory. |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 * |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 #include <stdio.h> |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 #include <string.h> |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include <assert.h> |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
31 #include <signal.h> |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 #include "SDL.h" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 #include "SDL_sound.h" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 #define PLAYSOUND_VER_MAJOR 0 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 #define PLAYSOUND_VER_MINOR 1 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
37 #define PLAYSOUND_VER_PATCH 3 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 static void output_versions(const char *argv0) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 Sound_Version compiled; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 Sound_Version linked; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 SDL_version sdl_compiled; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 const SDL_version *sdl_linked; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 SOUND_VERSION(&compiled); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 Sound_GetLinkedVersion(&linked); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 SDL_VERSION(&sdl_compiled); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 sdl_linked = SDL_Linked_Version(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
52 printf("%s version %d.%d.%d.\n" |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
53 " Compiled against SDL_sound version %d.%d.%d,\n" |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
54 " and linked against %d.%d.%d.\n" |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
55 " Compiled against SDL version %d.%d.%d,\n" |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
56 " and linked against %d.%d.%d.\n\n", |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 argv0, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 compiled.major, compiled.minor, compiled.patch, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 linked.major, linked.minor, linked.patch, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 sdl_compiled.major, sdl_compiled.minor, sdl_compiled.patch, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 sdl_linked->major, sdl_linked->minor, sdl_linked->patch); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 } /* output_versions */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 static void output_decoders(void) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 const Sound_DecoderInfo **i; |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
70 const char **ext; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
72 printf("Supported sound formats:\n"); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 if (rc == NULL) |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
74 printf(" * Apparently, NONE!\n"); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 else |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 for (i = rc; *i != NULL; i++) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 { |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
79 printf(" * %s\n", (*i)->description); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
80 for (ext = (*i)->extensions; *ext != NULL; ext++) |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
81 printf(" File extension \"%s\"\n", *ext); |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
82 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 } /* else */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
86 printf("\n"); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 } /* output_decoders */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 static volatile int done_flag = 0; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
92 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
93 void sigint_catcher(int signum) |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
94 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
95 static Uint32 last_sigint = 0; |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
96 Uint32 ticks = SDL_GetTicks(); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
97 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
98 assert(signum == SIGINT); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
99 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
100 if ((last_sigint != 0) && (ticks - last_sigint < 500)) |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
101 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
102 SDL_PauseAudio(1); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
103 SDL_CloseAudio(); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
104 Sound_Quit(); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
105 SDL_Quit(); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
106 exit(1); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
107 } /* if */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
108 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
109 else |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
110 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
111 last_sigint = ticks; |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
112 done_flag = 1; |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
113 } /* else */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
114 } /* sigint_catcher */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
115 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
116 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
117 static Uint8 *decoded_ptr = NULL; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
118 static Uint32 decoded_bytes = 0; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
119 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 static void audio_callback(void *userdata, Uint8 *stream, int len) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 { |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
122 Sound_Sample *sample = (Sound_Sample *) userdata; |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
123 int bw = 0; /* bytes written to stream this time through the callback */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
125 while (bw < len) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 { |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
127 int cpysize; /* bytes to copy on this iteration of the loop. */ |
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
128 |
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
129 if (!decoded_bytes) /* need more data decoded from sample? */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 { |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
131 if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF)) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 { |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
133 /* ...but there isn't any more data to decode! */ |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
134 memset(stream + bw, '\0', len - bw); |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
135 done_flag = 1; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
136 return; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
139 decoded_bytes = Sound_Decode(sample); |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
140 decoded_ptr = sample->buffer; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
143 cpysize = len - bw; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
144 if (cpysize > decoded_bytes) |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
145 cpysize = decoded_bytes; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
147 if (cpysize > 0) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 { |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
149 memcpy(stream + bw, decoded_ptr, cpysize); |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
150 bw += cpysize; |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
151 decoded_ptr += cpysize; |
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
152 decoded_bytes -= cpysize; |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
153 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 } /* while */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 } /* audio_callback */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 static void output_usage(const char *argv0) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 { |
82
7505dcf8d3b7
Fixes some Visual C++ 6.0 compiler complaints.
Ryan C. Gordon <icculus@icculus.org>
parents:
58
diff
changeset
|
160 fprintf(stderr, |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
161 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
162 "\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
163 " Options:\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
164 " --rate x Playback at sample rate of x HZ.\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
165 " --format fmt Playback in fmt format (see below).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
166 " --channels n Playback on n channels (1 or 2).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
167 " --version Display version information and exit.\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
168 " --decoders List supported sound formats and exit.\n" |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
169 " --predecode Decode entire sample before playback.\n" |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
170 " --help Display this information and exit.\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
171 "\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
172 " Valid arguments to the --format option are:\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
173 " U8 Unsigned 8-bit.\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
174 " S8 Signed 8-bit.\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
175 " U16LSB Unsigned 16-bit (least significant byte first).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
176 " U16MSB Unsigned 16-bit (most significant byte first).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
177 " S16LSB Signed 16-bit (least significant byte first).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
178 " S16MSB Signed 16-bit (most significant byte first).\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
179 "\n", |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 argv0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 } /* output_usage */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
184 static int str_to_fmt(char *str) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
185 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
186 if (strcmp(str, "U8") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
187 return AUDIO_U8; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
188 if (strcmp(str, "S8") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
189 return AUDIO_S8; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
190 if (strcmp(str, "U16LSB") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
191 return AUDIO_U16LSB; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
192 if (strcmp(str, "S16LSB") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
193 return AUDIO_S16LSB; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
194 if (strcmp(str, "U16MSB") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
195 return AUDIO_U16MSB; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
196 if (strcmp(str, "S16MSB") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
197 return AUDIO_S16MSB; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
198 return 0; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
199 } /* str_to_fmt */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
200 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
201 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 int main(int argc, char **argv) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 Sound_AudioInfo sound_desired; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 SDL_AudioSpec sdl_desired; |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
206 SDL_AudioSpec sdl_actual; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 Sound_Sample *sample; |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
208 int predecode = 0; |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
209 int use_specific_audiofmt = 0; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 int i; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
212 setbuf(stdout, NULL); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
213 setbuf(stderr, NULL); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
214 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
215 /* !!! FIXME: Move this to a parse_cmdline() function... */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 if (argc < 2) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 output_usage(argv[0]); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
222 memset(&sound_desired, '\0', sizeof (sound_desired)); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
223 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 for (i = 0; i < argc; i++) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 if (strncmp(argv[i], "--", 2) != 0) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
229 if (strcmp(argv[i], "--version") == 0) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 output_versions(argv[0]); |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
232 return(42); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
233 } /* if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
234 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
235 else if (strcmp(argv[i], "--help") == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
236 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 output_usage(argv[0]); |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
238 return(42); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 } /* if */ |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
240 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
241 else if (strcmp(argv[i], "--rate") == 0 && argc > i + 1) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
242 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
243 use_specific_audiofmt = 1; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
244 sound_desired.rate = atoi(argv[++i]); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
245 if (sound_desired.rate <= 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
246 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
247 fprintf(stderr, "Bad argument to --rate!\n"); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
248 return(42); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
249 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
250 } /* else if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
251 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
252 else if (strcmp(argv[i], "--format") == 0 && argc > i + 1) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
253 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
254 use_specific_audiofmt = 1; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
255 sound_desired.format = str_to_fmt(argv[++i]); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
256 if (sound_desired.format == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
257 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
258 fprintf(stderr, "Bad argument to --format! Try one of:\n" |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
259 "U8, S8, U16LSB, S16LSB, U16MSB, S16MSB\n"); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
260 return(42); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
261 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
262 } /* else if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
263 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
264 else if (strcmp(argv[i], "--channels") == 0 && argc > i + 1) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
265 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
266 use_specific_audiofmt = 1; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
267 sound_desired.channels = atoi(argv[++i]); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
268 if (sound_desired.channels < 1 || sound_desired.channels > 2) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
269 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
270 fprintf(stderr, |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
271 "Bad argument to --channels! Try 1 (mono) or 2 " |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
272 "(stereo).\n"); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
273 return(42); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
274 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
275 } /* else if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 else if (strcmp(argv[i], "--decoders") == 0) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 if (!Sound_Init()) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 fprintf(stderr, "Sound_Init() failed!\n" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 " reason: [%s].\n", Sound_GetError()); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 output_decoders(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 return(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 } /* else if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
292 else if (strcmp(argv[i], "--predecode") == 0) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
293 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
294 predecode = 1; |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
295 } /* else if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
296 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 else |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 fprintf(stderr, "unknown option: \"%s\"\n", argv[i]); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 } /* else */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
304 /* Pick sensible defaults for any value not explicitly specified. */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
305 if (use_specific_audiofmt) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
306 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
307 if (sound_desired.rate == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
308 sound_desired.rate = 44100; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
309 if (sound_desired.format == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
310 sound_desired.format = AUDIO_S16SYS; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
311 if (sound_desired.channels == 0) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
312 sound_desired.channels = 2; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
313 } /* if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
314 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 if (SDL_Init(SDL_INIT_AUDIO) == -1) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 fprintf(stderr, "SDL_Init(SDL_INIT_AUDIO) failed!\n" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 " reason: [%s].\n", SDL_GetError()); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 if (!Sound_Init()) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 fprintf(stderr, "Sound_Init() failed!\n" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 " reason: [%s].\n", Sound_GetError()); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
330 signal(SIGINT, sigint_catcher); |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
331 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 for (i = 1; i < argc; i++) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 { |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
334 /* !!! FIXME: This is ugly! */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
335 if ( (strcmp(argv[i], "--rate") == 0) || |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
336 (strcmp(argv[i], "--format") == 0) || |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
337 (strcmp(argv[i], "--channels") == 0) ) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
338 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
339 i++; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
340 continue; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
341 } /* if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
342 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 if (strncmp(argv[i], "--", 2) == 0) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
346 sample = Sound_NewSampleFromFile(argv[i], |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
347 use_specific_audiofmt ? &sound_desired : NULL, 4096 * 4); |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
348 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 if (!sample) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 fprintf(stderr, "Couldn't load \"%s\"!\n" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 " reason: [%s].\n", argv[i], Sound_GetError()); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
356 /* |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
357 * Unless explicitly specified, pick the format from the sound |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
358 * to be played. |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
359 */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
360 if (use_specific_audiofmt) |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
361 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
362 sdl_desired.freq = sound_desired.rate; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
363 sdl_desired.format = sound_desired.format; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
364 sdl_desired.channels = sound_desired.channels; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
365 } /* if */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
366 else |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
367 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
368 sdl_desired.freq = sample->actual.rate; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
369 sdl_desired.format = sample->actual.format; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
370 sdl_desired.channels = sample->actual.channels; |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
371 } /* else */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
372 |
137
e3f4767d6037
Removed an experiment.
Ryan C. Gordon <icculus@icculus.org>
parents:
135
diff
changeset
|
373 sdl_desired.samples = 4096; |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
374 sdl_desired.callback = audio_callback; |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
375 sdl_desired.userdata = sample; |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
376 |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
377 if (SDL_OpenAudio(&sdl_desired, NULL) < 0) |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
378 { |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
379 fprintf(stderr, "Couldn't open audio device!\n" |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
380 " reason: [%s].\n", SDL_GetError()); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
381 Sound_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
382 SDL_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
383 return(42); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
384 } /* if */ |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
385 |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
386 printf("Now playing [%s]...\n", argv[i]); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
387 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
388 if (predecode) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
389 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
390 printf(" predecoding...", argv[i]); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
391 decoded_bytes = Sound_DecodeAll(sample); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
392 decoded_ptr = sample->buffer; |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
393 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
394 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
395 fprintf(stderr, |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
396 "Couldn't fully decode \"%s\"!\n" |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
397 " reason: [%s].\n", |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
398 " (playing first %lu bytes of decoded data...)\n", |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
399 argv[i], Sound_GetError(), decoded_bytes); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
400 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
401 else |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
402 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
403 printf("done.\n"); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
404 } /* else */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
405 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
406 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 done_flag = 0; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 SDL_PauseAudio(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 while (!done_flag) |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
410 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 SDL_Delay(10); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
412 } /* while */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 SDL_PauseAudio(1); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
414 |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
415 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
416 { |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
417 fprintf(stderr, "Error in decoding sound file!\n" |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
418 " reason: [%s].\n", Sound_GetError()); |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
419 } /* if */ |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
420 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
421 SDL_CloseAudio(); /* reopen with next sample's format if possible */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 Sound_FreeSample(sample); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 return(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 } /* main */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 /* end of playsound.c ... */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
431 |