Mercurial > SDL_sound_CoreAudio
annotate playsound/playsound.c @ 287:2444b4128efd
Updated.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 16 Mar 2002 08:47:29 +0000 |
parents | 95082495d437 |
children | 259daddc2d6b |
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 * |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
176
diff
changeset
|
23 * Please see the file COPYING in the source's root directory. |
58
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> |
270 | 29 #include <stdlib.h> |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include <string.h> |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 #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
|
32 #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
|
33 #include "SDL.h" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 #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
|
35 |
285 | 36 #define SUPPORT_PHYSFS 0 |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
37 #if SUPPORT_PHYSFS |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
38 #include <alloca.h> |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
39 #include "physfs.h" |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
40 #include "physfsrwops.h" |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
41 #endif |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
42 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
43 #define DEFAULT_DECODEBUF 16384 |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
44 #define DEFAULT_AUDIOBUF 4096 |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
45 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 #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
|
47 #define PLAYSOUND_VER_MINOR 1 |
252
c54eae85f5f1
Upped version to 0.1.5.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
48 #define PLAYSOUND_VER_PATCH 5 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 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
|
51 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 Sound_Version compiled; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 Sound_Version linked; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 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
|
55 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
|
56 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 SOUND_VERSION(&compiled); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 Sound_GetLinkedVersion(&linked); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 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
|
60 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
|
61 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
62 printf("%s version %d.%d.%d\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
63 "Copyright 2001 Ryan C. Gordon\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
64 "This program is free software, covered by the GNU Lesser General\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
65 "Public License, and you are welcome to change it and/or\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
66 "distribute copies of it under certain conditions. There is\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
67 "absolutely NO WARRANTY for this program.\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
68 "\n" |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
69 " 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
|
70 " 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
|
71 " 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
|
72 " 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
|
73 argv0, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 } /* output_versions */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 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
|
83 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 else |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 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
|
94 { |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 } /* else */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
102 printf("\n"); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 } /* output_decoders */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
106 static void output_usage(const char *argv0) |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
107 { |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
108 fprintf(stderr, |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
109 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
110 "\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
111 " Options:\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
112 " --rate n Playback at sample rate of n HZ.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
113 " --format fmt Playback in fmt format (see below).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
114 " --channels n Playback on n channels (1 or 2).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
115 " --decodebuf n Buffer n decoded bytes at a time (default %d).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
116 " --audiobuf n Buffer n samples to audio device (default %d).\n" |
270 | 117 " --volume n Playback volume multiplier (default 1.0).\n" |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
118 " --stdin [ext] Read from stdin (treat data as format [ext])\n" |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
119 " --version Display version information and exit.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
120 " --decoders List supported data formats and exit.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
121 " --predecode Decode entire sample before playback.\n" |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
122 " --loop Loop playback until SIGINT.\n" |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
123 " --credits Shameless promotion.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
124 " --help Display this information and exit.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
125 "\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
126 " Valid arguments to the --format option are:\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
127 " U8 Unsigned 8-bit.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
128 " S8 Signed 8-bit.\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
129 " U16LSB Unsigned 16-bit (least significant byte first).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
130 " U16MSB Unsigned 16-bit (most significant byte first).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
131 " S16LSB Signed 16-bit (least significant byte first).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
132 " S16MSB Signed 16-bit (most significant byte first).\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
133 "\n", |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
134 argv0, DEFAULT_DECODEBUF, DEFAULT_AUDIOBUF); |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
135 } /* output_usage */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
136 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
137 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
138 static void output_credits(void) |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
139 { |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
140 printf("playsound version %d.%d.%d\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
141 "Copyright 2001 Ryan C. Gordon\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
142 "playsound is free software, covered by the GNU Lesser General\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
143 "Public License, and you are welcome to change it and/or\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
144 "distribute copies of it under certain conditions. There is\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
145 "absolutely NO WARRANTY for playsound.\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
146 "\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
147 " Written by Ryan C. Gordon, Torbjörn Andersson, Max Horn,\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
148 " Tsuyoshi Iguchi, Tyler Montbriand, and a cast of thousands.\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
149 "\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
150 " Website and source code: http://icculus.org/SDL_sound/\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
151 "\n", |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
152 PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
153 } /* output_credits */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
154 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
155 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
156 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 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
|
158 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
159 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
160 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
|
161 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
162 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
|
163 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
|
164 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
165 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
|
166 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
167 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
|
168 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 } /* if */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
175 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
176 else |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
177 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
178 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
|
179 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
|
180 } /* else */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
181 } /* 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
|
182 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
183 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
184 static Uint8 *decoded_ptr = NULL; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
185 static Uint32 decoded_bytes = 0; |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
186 static int predecode = 0; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
187 static int looping = 0; |
270 | 188 static int wants_volume_change = 0; |
189 static float volume = 1.0; | |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
190 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
191 /* |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
192 * This updates (decoded_bytes) and (decoder_ptr) with more audio data, |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
193 * taking into account looping and/or predecoding. |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
194 */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
195 static int read_more_data(Sound_Sample *sample) |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
196 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
197 if (done_flag) /* probably a sigint; stop trying to read. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
198 decoded_bytes = 0; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
199 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
200 if (decoded_bytes > 0) /* don't need more data; just return. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
201 return(decoded_bytes); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
202 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
203 /* need more. See if there's more to be read... */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
204 if (!(sample->flags & (SOUND_SAMPLEFLAG_ERROR | SOUND_SAMPLEFLAG_EOF))) |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
205 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
206 decoded_bytes = Sound_Decode(sample); |
272
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
207 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
208 { |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
209 fprintf(stderr, "Error in decoding sound file!\n" |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
210 " reason: [%s].\n", Sound_GetError()); |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
211 } /* if */ |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
212 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
213 decoded_ptr = sample->buffer; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
214 return(read_more_data(sample)); /* handle loops conditions. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
215 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
216 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
217 /* No more to be read from stream, but we may want to loop the sample. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
218 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
219 if (!looping) |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
220 return(0); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
221 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
222 /* we just need to point predecoded samples to the start of the buffer. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
223 if (predecode) |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
224 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
225 decoded_bytes = sample->buffer_size; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
226 decoded_ptr = sample->buffer; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
227 return(decoded_bytes); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
228 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
229 else |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
230 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
231 Sound_Rewind(sample); /* error is checked in recursion. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
232 return(read_more_data(sample)); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
233 } /* else */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
234 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
235 assert(0); /* shouldn't ever hit this point. */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
236 return(0); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
237 } /* read_more_data */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
238 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
239 |
270 | 240 static void memcpy_with_volume(Sound_Sample *sample, |
241 Uint8 *dst, Uint8 *src, int len) | |
242 { | |
243 int i; | |
244 Uint16 *u16src = NULL; | |
245 Uint16 *u16dst = NULL; | |
246 Sint16 *s16src = NULL; | |
247 Sint16 *s16dst = NULL; | |
248 | |
249 if (!wants_volume_change) | |
250 { | |
251 memcpy(dst, src, len); | |
252 return; | |
253 } | |
254 | |
255 /* !!! FIXME: This would be more efficient with a lookup table. */ | |
256 switch (sample->desired.format) | |
257 { | |
258 case AUDIO_U8: | |
259 for (i = 0; i < len; i++, src++, dst++) | |
260 *dst = (Uint8) (((float) (*src)) * volume); | |
261 break; | |
262 | |
263 case AUDIO_S8: | |
264 for (i = 0; i < len; i++, src++, dst++) | |
265 *dst = (Sint8) (((float) (*src)) * volume); | |
266 break; | |
267 | |
268 case AUDIO_U16LSB: | |
269 u16src = (Uint16 *) src; | |
270 u16dst = (Uint16 *) dst; | |
271 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
272 { | |
273 *u16dst = (Uint16) (((float) (SDL_SwapLE16(*u16src))) * volume); | |
274 *u16dst = SDL_SwapLE16(*u16dst); | |
275 } | |
276 break; | |
277 | |
278 case AUDIO_S16LSB: | |
279 s16src = (Sint16 *) src; | |
280 s16dst = (Sint16 *) dst; | |
281 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
282 { | |
283 *s16dst = (Sint16) (((float) (SDL_SwapLE16(*s16src))) * volume); | |
284 *s16dst = SDL_SwapLE16(*s16dst); | |
285 } | |
286 break; | |
287 | |
288 case AUDIO_U16MSB: | |
289 u16src = (Uint16 *) src; | |
290 u16dst = (Uint16 *) dst; | |
291 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
292 { | |
293 *u16dst = (Uint16) (((float) (SDL_SwapBE16(*u16src))) * volume); | |
294 *u16dst = SDL_SwapBE16(*u16dst); | |
295 } | |
296 break; | |
297 | |
298 case AUDIO_S16MSB: | |
299 s16src = (Sint16 *) src; | |
300 s16dst = (Sint16 *) dst; | |
301 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
302 { | |
303 *s16dst = (Sint16) (((float) (SDL_SwapBE16(*s16src))) * volume); | |
304 *s16dst = SDL_SwapBE16(*s16dst); | |
305 } | |
306 break; | |
307 } | |
308 } | |
309 | |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 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
|
311 { |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
312 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
|
313 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
|
314 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
315 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
|
316 { |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
317 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
|
318 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
319 if (!read_more_data(sample)) /* read more data, if needed. */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 { |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
321 /* ...there isn't any more data to read! */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
322 memset(stream + bw, '\0', len - bw); |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
323 done_flag = 1; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
324 return; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
325 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
327 /* decoded_bytes and decoder_ptr are updated as necessary... */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
329 cpysize = len - bw; |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
330 if (cpysize > decoded_bytes) |
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
331 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
|
332 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
333 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
|
334 { |
270 | 335 memcpy_with_volume(sample, stream + bw, decoded_ptr, cpysize); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
336 bw += cpysize; |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
337 decoded_ptr += cpysize; |
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
338 decoded_bytes -= cpysize; |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
339 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 } /* while */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 } /* audio_callback */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
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
|
344 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
|
345 { |
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 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 } /* 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
|
360 |
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 |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
362 #if SUPPORT_PHYSFS |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
363 static SDL_RWops *rwops_from_physfs(const char *argv0, const char *filename) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
364 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
365 SDL_RWops *retval = NULL; |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
366 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
367 char *path = (char *) alloca(strlen(filename) + 1); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
368 char *archive; |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
369 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
370 strcpy(path, filename); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
371 archive = strchr(path, '@'); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
372 if (archive != NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
373 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
374 *(archive++) = '\0'; /* blank '@', point to archive name. */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
375 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
376 if (!PHYSFS_init(argv0)) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
377 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
378 fprintf(stderr, "Couldn't init PhysicsFS: %s\n", |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
379 PHYSFS_getLastError()); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
380 return(NULL); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
381 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
382 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
383 if (!PHYSFS_addToSearchPath(archive, 0)) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
384 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
385 fprintf(stderr, "Couldn't open archive: %s\n", |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
386 PHYSFS_getLastError()); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
387 return(NULL); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
388 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
389 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
390 retval = PHYSFSRWOPS_openRead(path); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
391 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
392 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
393 return(retval); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
394 } /* rwops_from_physfs */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
395 #endif |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
396 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
397 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
398 static Sound_Sample *sample_from_archive(const char *argv0, const char *fname, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
399 Sound_AudioInfo *desired, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
400 Uint32 decode_buffersize) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
401 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
402 #if SUPPORT_PHYSFS |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
403 SDL_RWops *rw = rwops_from_physfs(argv0, fname); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
404 if (rw != NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
405 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
406 char *path = (char *) alloca(strlen(fname) + 1); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
407 char *ptr; |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
408 strcpy(path, fname); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
409 ptr = strchr(path, '@'); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
410 *ptr = '\0'; |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
411 ptr = strrchr(path, '.'); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
412 if (ptr != NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
413 ptr++; |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
414 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
415 return(Sound_NewSample(rw, ptr, desired, decode_buffersize)); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
416 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
417 #endif |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
418 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
419 return(NULL); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
420 } /* sample_from_archive */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
421 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
422 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 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
|
424 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 Sound_AudioInfo sound_desired; |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
426 Uint32 audio_buffersize = DEFAULT_AUDIOBUF; |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
427 Uint32 decode_buffersize = DEFAULT_DECODEBUF; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 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
|
429 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
|
430 Sound_Sample *sample; |
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
|
431 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
|
432 int i; |
214
e27b33a6d5fe
Now attempts to wait for SDL to finish playing the end of the buffered
Ryan C. Gordon <icculus@icculus.org>
parents:
196
diff
changeset
|
433 int delay; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
435 setbuf(stdout, NULL); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
436 setbuf(stderr, NULL); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
437 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
438 /* !!! 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
|
439 if (argc < 2) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 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
|
442 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
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
|
445 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
|
446 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 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
|
448 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 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
|
450 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
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
|
452 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
|
453 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 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
|
455 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
|
456 } /* 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
|
457 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
458 if (strcmp(argv[i], "--credits") == 0) |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
459 { |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
460 output_credits(); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
461 return(42); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
462 } /* if */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
463 |
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
|
464 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
|
465 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 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
|
467 return(42); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 } /* 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
|
469 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
470 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
|
471 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
476 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
|
477 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
|
478 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
479 } /* 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
|
480 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
481 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
|
482 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
487 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
|
488 "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
|
489 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
|
490 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
491 } /* 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
|
492 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
493 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
|
494 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
499 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
|
500 "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
|
501 "(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
|
502 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
|
503 } |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
504 } /* else if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
505 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
506 else if (strcmp(argv[i], "--audiobuf") == 0 && argc > i + 1) |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
507 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
508 audio_buffersize = atoi(argv[++i]); |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
509 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
510 |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
511 else if (strcmp(argv[i], "--decodebuf") == 0 && argc > i + 1) |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
512 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
513 decode_buffersize = atoi(argv[++i]); |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
514 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
515 |
270 | 516 else if (strcmp(argv[i], "--volume") == 0 && argc > i + 1) |
517 { | |
518 volume = atof(argv[++i]); | |
519 if (volume != 1.0) | |
520 wants_volume_change = 1; | |
521 } /* else if */ | |
522 | |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
523 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
|
524 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 if (!Sound_Init()) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
526 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
527 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
|
528 " 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
|
529 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
530 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
532 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 output_decoders(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
535 return(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 } /* else if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
538 else if (strcmp(argv[i], "--predecode") == 0) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
539 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
540 predecode = 1; |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
541 } /* else if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
542 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
543 else if (strcmp(argv[i], "--loop") == 0) |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
544 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
545 looping = 1; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
546 } /* else if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
547 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
548 else if (strcmp(argv[i], "--stdin") == 0) |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
549 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
550 /* deal with it at Sound_Sample creation time... */ |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
551 } /* else if */ |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
552 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
553 else |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
554 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
555 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
|
556 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
557 } /* else */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 |
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
|
560 /* 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
|
561 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
|
562 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 } /* 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
|
570 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
571 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
|
572 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
573 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
|
574 " 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
|
575 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
576 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
577 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 if (!Sound_Init()) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 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
|
581 " 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
|
582 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
586 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
|
587 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 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
|
589 { |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
590 char *filename = NULL; |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
591 |
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
|
592 /* !!! 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
|
593 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
|
594 (strcmp(argv[i], "--format") == 0) || |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
595 (strcmp(argv[i], "--channels") == 0) || |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
596 (strcmp(argv[i], "--audiobuf") == 0) || |
270 | 597 (strcmp(argv[i], "--decodebuf") == 0) || |
598 (strcmp(argv[i], "--volume") == 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
|
599 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
600 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
|
601 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
|
602 } /* 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
|
603 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
604 if (strcmp(argv[i], "--stdin") == 0) |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
605 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
606 SDL_RWops *rw = SDL_RWFromFP(stdin, 1); |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
607 filename = "...from stdin..."; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
608 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
609 /* |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
610 * The second argument will be NULL if --stdin is the last |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
611 * thing on the command line. This is correct behaviour. |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
612 */ |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
613 sample = Sound_NewSample(rw, argv[++i], |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
614 use_specific_audiofmt ? &sound_desired : NULL, |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
615 decode_buffersize); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
616 } /* if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
617 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
618 else if (strncmp(argv[i], "--", 2) == 0) |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
619 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
620 continue; |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
621 } /* else if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
622 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
623 else |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
624 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
625 filename = argv[i]; |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
626 sample = sample_from_archive(argv[0], filename, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
627 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
628 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
629 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
630 if (sample == NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
631 { |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
632 sample = Sound_NewSampleFromFile(argv[i], |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
633 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
634 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
635 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
636 } /* else */ |
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
|
637 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
638 if (!sample) |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
639 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 fprintf(stderr, "Couldn't load \"%s\"!\n" |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
641 " reason: [%s].\n", filename, Sound_GetError()); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
642 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
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
|
645 /* |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
646 * 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
|
647 * 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
|
648 */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
649 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
|
650 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 } /* 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
|
655 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
|
656 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
657 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
|
658 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
|
659 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
|
660 } /* 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
|
661 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
662 sdl_desired.samples = audio_buffersize; |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
663 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
|
664 sdl_desired.userdata = sample; |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
665 |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
666 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
|
667 { |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
668 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
|
669 " 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
|
670 Sound_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
671 SDL_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
672 return(42); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
673 } /* if */ |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
674 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
675 printf("Now playing [%s]...\n", filename); |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
676 |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
677 if (predecode) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
678 { |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
679 printf(" predecoding..."); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
680 decoded_bytes = Sound_DecodeAll(sample); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
681 decoded_ptr = sample->buffer; |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
682 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
683 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
684 fprintf(stderr, |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
685 "Couldn't fully decode \"%s\"!\n" |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
686 " reason: [%s].\n" |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
687 " (playing first %lu bytes of decoded data...)\n", |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
688 filename, Sound_GetError(), decoded_bytes); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
689 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
690 else |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
691 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
692 printf("done.\n"); |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
693 } /* else */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
694 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
695 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 done_flag = 0; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 SDL_PauseAudio(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 while (!done_flag) |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
699 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
700 SDL_Delay(10); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
701 } /* while */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
702 SDL_PauseAudio(1); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
703 |
236 | 704 /* |
705 * Sleep two buffers' worth of audio before closing, in order | |
706 * to allow the playback to finish. This isn't always enough; | |
707 * perhaps SDL needs a way to explicitly wait for device drain? | |
708 */ | |
709 delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq; | |
710 SDL_Delay(delay); | |
214
e27b33a6d5fe
Now attempts to wait for SDL to finish playing the end of the buffered
Ryan C. Gordon <icculus@icculus.org>
parents:
196
diff
changeset
|
711 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
712 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
|
713 Sound_FreeSample(sample); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
714 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
715 #if SUPPORT_PHYSFS |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
716 PHYSFS_deinit(); /* !!! FIXME: move this somewhere? */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
717 #endif |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
718 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
719 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
720 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
721 SDL_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
722 return(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
723 } /* main */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
724 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
725 /* 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
|
726 |