Mercurial > SDL_sound_CoreAudio
annotate playsound/playsound.c @ 509:5859ad32fc3b stable-1.0
Svn should ignore autom4te.cache.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 17 Dec 2005 18:55:32 +0000 |
parents | 0dbf37be0a5a |
children | 50bb9a6cebfe |
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 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
28 #if HAVE_CONFIG_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
29 # include <config.h> |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
30 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
31 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 #include <stdio.h> |
270 | 33 #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
|
34 #include <string.h> |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
35 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
36 #if HAVE_ASSERT_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
37 # include <assert.h> |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
38 #elif (!defined assert) |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
39 # define assert(x) |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
40 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
41 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
42 #if HAVE_SIGNAL_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
43 # include <signal.h> |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
44 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
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 #include "SDL.h" |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 #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
|
48 |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
49 #if SUPPORT_PHYSFS |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
50 #include "physfs.h" |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
51 #include "physfsrwops.h" |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
52 #endif |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
53 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
54 #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
|
55 #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
|
56 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 #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
|
58 #define PLAYSOUND_VER_MINOR 1 |
252
c54eae85f5f1
Upped version to 0.1.5.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
59 #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
|
60 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
61 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
62 static const char *option_list[] = |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
63 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
64 "--rate", "n Playback at sample rate of n HZ.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
65 "--format", "fmt Playback in fmt format (see below).", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
66 "--channels", "n Playback on n channels (1 or 2).", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
67 "--decodebuf", "n Buffer n decoded bytes at a time (default 16384).", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
68 "--audiobuf", "n Buffer n samples to audio device (default 4096).", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
69 "--volume", "n Playback volume multiplier (default 1.0).", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
70 "--stdin", "[ext] Read from stdin (treat data as format [ext])", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
71 "--version", " Display version information and exit.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
72 "--decoders", " List supported data formats and exit.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
73 "--predecode", " Decode entire sample before playback.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
74 "--loop", "n Loop playback n times.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
75 "--seek", "list List of seek points and playback durations.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
76 "--credits", " Shameless promotion.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
77 "--help", " Display this information and exit.", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
78 NULL, NULL |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
79 }; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
80 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
81 |
58
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_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
|
83 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 Sound_Version compiled; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 Sound_Version linked; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 SOUND_VERSION(&compiled); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 Sound_GetLinkedVersion(&linked); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 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
|
92 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
|
93 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
94 fprintf(stdout, |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
95 "%s version %d.%d.%d\n" |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
96 "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
|
97 "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
|
98 "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
|
99 "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
|
100 "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
|
101 "\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
|
102 " 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
|
103 " 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
|
104 " 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
|
105 " 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
|
106 argv0, |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 } /* output_versions */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 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
|
116 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
121 fprintf(stdout, "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
|
122 if (rc == NULL) |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
123 fprintf(stdout, " * 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
|
124 else |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 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
|
127 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
128 fprintf(stdout, " * %s\n", (*i)->description); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
129 |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
130 for (ext = (*i)->extensions; *ext != NULL; ext++) |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
131 fprintf(stdout, " File extension \"%s\"\n", *ext); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
132 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
133 fprintf(stdout, " Written by %s.\n %s\n\n", |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
134 (*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
|
135 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 } /* else */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
138 fprintf(stdout, "\n"); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 } /* output_decoders */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
142 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
|
143 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
144 const char **i = option_list; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
145 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
146 fprintf(stderr, |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
147 "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
|
148 "\n" |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
149 " Options:\n", |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
150 argv0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
151 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
152 while (*i != NULL) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
153 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
154 const char *option = *(i++); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
155 const char *optiondesc = *(i++); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
156 fprintf(stderr, " %s %s\n", option, optiondesc); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
157 } /* while */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
158 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
159 fprintf(stderr, |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
160 "\n" |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
161 " 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
|
162 " 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
|
163 " 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
|
164 " 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
|
165 " 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
|
166 " 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
|
167 " S16MSB Signed 16-bit (most significant byte first).\n" |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
168 "\n" |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
169 " Valid arguments to the --seek options look like:\n" |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
170 " --seek \"mm:SS:ss;mm:SS:ss;mm:SS:ss\"\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
171 " Where the first \"mm:SS:ss\" is the position, in minutes,\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
172 " seconds and milliseconds to seek to at start of playback. The\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
173 " next mm:SS:ss is how long to play audio from that point.\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
174 " The third mm:SS:ss is another seek after the duration of\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
175 " playback has completed. If the final playback duration is\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
176 " omitted, playback continues until the end of the file.\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
177 " The \"mm\" and \"SS\" portions may be omitted. --loop\n" |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
178 " and --seek can coexist.\n" |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
179 "\n"); |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
180 } /* output_usage */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
181 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
182 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
183 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
|
184 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
185 fprintf(stdout, |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
186 "playsound version %d.%d.%d\n" |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
187 "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
|
188 "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
|
189 "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
|
190 "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
|
191 "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
|
192 "\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
193 " Written by Ryan C. Gordon, Torbjörn Andersson, Max Horn,\n" |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
194 " Tsuyoshi Iguchi, Tyler Montbriand, Darrell Walisser,\n" |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
195 " and a cast of thousands.\n" |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
196 "\n" |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
197 " 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
|
198 "\n", |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
199 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
|
200 } /* output_credits */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
201 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
202 |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
203 |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
204 /* archive stuff... */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
205 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
206 static int init_archive(const char *argv0) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
207 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
208 int retval = 1; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
209 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
210 #if SUPPORT_PHYSFS |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
211 retval = PHYSFS_init(argv0); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
212 if (!retval) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
213 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
214 fprintf(stderr, "Couldn't init PhysicsFS: %s\n", |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
215 PHYSFS_getLastError()); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
216 } /* if */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
217 #endif |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
218 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
219 return(retval); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
220 } /* init_archive */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
221 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
222 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
223 #if SUPPORT_PHYSFS |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
224 static SDL_RWops *rwops_from_physfs(const char *filename) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
225 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
226 SDL_RWops *retval = NULL; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
227 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
228 char *path = (char *) malloc(strlen(filename) + 1); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
229 char *archive; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
230 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
231 if (path == NULL) |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
232 { |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
233 fprintf(stderr, "Out of memory!\n"); |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
234 return(NULL); |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
235 } /* if */ |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
236 |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
237 strcpy(path, filename); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
238 archive = strchr(path, '@'); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
239 if (archive != NULL) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
240 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
241 *(archive++) = '\0'; /* blank '@', point to archive name. */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
242 if (!PHYSFS_addToSearchPath(archive, 0)) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
243 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
244 fprintf(stderr, "Couldn't open archive: %s\n", |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
245 PHYSFS_getLastError()); |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
246 free(path); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
247 return(NULL); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
248 } /* if */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
249 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
250 retval = PHYSFSRWOPS_openRead(path); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
251 } /* if */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
252 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
253 free(path); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
254 return(retval); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
255 } /* rwops_from_physfs */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
256 #endif |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
257 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
258 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
259 static Sound_Sample *sample_from_archive(const char *fname, |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
260 Sound_AudioInfo *desired, |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
261 Uint32 decode_buffersize) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
262 { |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
263 Sound_Sample *retval = NULL; |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
264 |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
265 #if SUPPORT_PHYSFS |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
266 SDL_RWops *rw = rwops_from_physfs(fname); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
267 if (rw != NULL) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
268 { |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
269 char *path = (char *) malloc(strlen(fname) + 1); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
270 char *ptr; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
271 strcpy(path, fname); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
272 ptr = strchr(path, '@'); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
273 *ptr = '\0'; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
274 ptr = strrchr(path, '.'); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
275 if (ptr != NULL) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
276 ptr++; |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
277 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
278 retval = Sound_NewSample(rw, ptr, desired, decode_buffersize); |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
279 free(path); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
280 } /* if */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
281 #endif |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
282 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
283 return(retval); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
284 } /* sample_from_archive */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
285 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
286 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
287 static void close_archive(const char *filename) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
288 { |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
289 #if SUPPORT_PHYSFS |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
290 char *archive_name = strchr(filename, '@'); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
291 if (archive_name != NULL) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
292 PHYSFS_removeFromSearchPath(archive_name + 1); |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
293 #endif |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
294 } /* close_archive */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
295 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
296 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
297 static void deinit_archive(void) |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
298 { |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
299 #if SUPPORT_PHYSFS |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
300 PHYSFS_deinit(); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
301 #endif |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
302 } /* deinit_archive */ |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
303 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
304 |
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
305 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 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
|
307 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
308 #if HAVE_SIGNAL_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
|
309 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
|
310 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
311 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
|
312 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
|
313 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
314 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
|
315 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
316 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
|
317 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 SDL_Quit(); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
322 deinit_archive(); |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
323 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
|
324 } /* if */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
325 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
326 else |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
327 { |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
328 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
|
329 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
|
330 } /* else */ |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
331 } /* sigint_catcher */ |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
332 #endif |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
333 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
334 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
335 /* global decoding state. */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
336 typedef struct |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
337 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
338 Uint8 *decoded_ptr; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
339 Uint32 decoded_bytes; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
340 int predecode; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
341 int looping; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
342 int wants_volume_change; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
343 float volume; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
344 Uint32 total_seeks; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
345 Uint32 *seek_list; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
346 Uint32 seek_index; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
347 Sint32 bytes_before_next_seek; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
348 } playsound_global_state; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
349 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
350 static volatile playsound_global_state global_state; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
351 |
310 | 352 |
353 static Uint32 cvtMsToBytePos(Sound_AudioInfo *info, Uint32 ms) | |
354 { | |
355 /* "frames" == "sample frames" */ | |
356 float frames_per_ms = ((float) info->rate) / 1000.0; | |
357 Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms)); | |
358 Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels; | |
359 return(frame_offset * frame_size); | |
360 } /* cvtMsToBytePos */ | |
361 | |
362 | |
363 static void do_seek(Sound_Sample *sample) | |
364 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
365 Uint32 *seek_list = global_state.seek_list; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
366 Uint32 seek_index = global_state.seek_index; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
367 Uint32 total_seeks = global_state.total_seeks; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
368 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
369 fprintf(stdout, "Seeking to %.2d:%.2d:%.4d...\n", |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
370 (int) ((seek_list[seek_index] / 1000) / 60), |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
371 (int) ((seek_list[seek_index] / 1000) % 60), |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
372 (int) ((seek_list[seek_index] % 1000))); |
310 | 373 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
374 if (global_state.predecode) |
310 | 375 { |
376 Uint32 pos = cvtMsToBytePos(&sample->desired, seek_list[seek_index]); | |
377 if (pos > sample->buffer_size) | |
378 { | |
379 fprintf(stderr, "Seek past end of predecoded buffer.\n"); | |
380 done_flag = 1; | |
381 } /* if */ | |
382 else | |
383 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
384 global_state.decoded_ptr = (((Uint8 *) sample->buffer) + pos); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
385 global_state.decoded_bytes = sample->buffer_size - pos; |
310 | 386 } /* else */ |
387 } /* if */ | |
388 else | |
389 { | |
390 if (!Sound_Seek(sample, seek_list[seek_index])) | |
391 { | |
392 fprintf(stderr, "Sound_Seek() failed: %s\n", Sound_GetError()); | |
393 done_flag = 1; | |
394 } /* if */ | |
395 } /* else */ | |
396 | |
397 seek_index++; | |
398 if (seek_index >= total_seeks) | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
399 global_state.bytes_before_next_seek = -1; /* no more seeks. */ |
310 | 400 else |
401 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
402 global_state.bytes_before_next_seek = cvtMsToBytePos(&sample->desired, |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
403 seek_list[seek_index]); |
310 | 404 seek_index++; |
405 } /* else */ | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
406 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
407 global_state.seek_index = seek_index; |
310 | 408 } /* do_seek */ |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
409 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
410 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
411 /* |
310 | 412 * This updates (decoded_bytes) and (decoded_ptr) with more audio data, |
413 * taking into account potential looping, seeking and predecoding. | |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
414 */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
415 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
|
416 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
417 if (done_flag) /* probably a sigint; stop trying to read. */ |
310 | 418 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
419 global_state.decoded_bytes = 0; |
310 | 420 return(0); |
421 } /* if */ | |
422 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
423 if ((global_state.bytes_before_next_seek >= 0) && |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
424 (global_state.decoded_bytes > global_state.bytes_before_next_seek)) |
310 | 425 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
426 global_state.decoded_bytes = global_state.bytes_before_next_seek; |
310 | 427 } /* if */ |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
428 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
429 if (global_state.decoded_bytes > 0) /* don't need more data; just return. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
430 return(global_state.decoded_bytes); |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
431 |
310 | 432 /* Need more audio data. See if we're supposed to seek... */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
433 if ((global_state.bytes_before_next_seek == 0) && |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
434 (global_state.seek_index < global_state.total_seeks)) |
310 | 435 { |
436 do_seek(sample); /* do it, baby! */ | |
437 return(read_more_data(sample)); /* handle loops conditions. */ | |
438 } /* if */ | |
439 | |
440 /* See if there's more to be read... */ | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
441 if ( (global_state.bytes_before_next_seek != 0) && |
310 | 442 (!(sample->flags & (SOUND_SAMPLEFLAG_ERROR | SOUND_SAMPLEFLAG_EOF))) ) |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
443 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
444 global_state.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
|
445 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
|
446 { |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
447 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
|
448 " 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
|
449 } /* if */ |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
450 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
451 global_state.decoded_ptr = sample->buffer; |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
452 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
|
453 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
454 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
455 /* 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
|
456 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
457 if (!global_state.looping) |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
458 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
|
459 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
460 global_state.looping--; |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
461 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
462 global_state.seek_index = 0; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
463 global_state.bytes_before_next_seek = |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
464 (global_state.total_seeks > 0) ? 0 : -1; |
310 | 465 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
466 /* we just need to point predecoded samples to the start of the buffer. */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
467 if (global_state.predecode) |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
468 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
469 global_state.decoded_bytes = sample->buffer_size; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
470 global_state.decoded_ptr = sample->buffer; |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
471 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
472 else |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
473 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
474 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
|
475 } /* else */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
476 |
310 | 477 return(read_more_data(sample)); |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
478 } /* 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
|
479 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
480 |
270 | 481 static void memcpy_with_volume(Sound_Sample *sample, |
482 Uint8 *dst, Uint8 *src, int len) | |
483 { | |
484 int i; | |
485 Uint16 *u16src = NULL; | |
486 Uint16 *u16dst = NULL; | |
487 Sint16 *s16src = NULL; | |
488 Sint16 *s16dst = NULL; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
489 float volume = global_state.volume; |
270 | 490 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
491 if (!global_state.wants_volume_change) |
270 | 492 { |
493 memcpy(dst, src, len); | |
494 return; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
495 } /* if */ |
270 | 496 |
497 /* !!! FIXME: This would be more efficient with a lookup table. */ | |
498 switch (sample->desired.format) | |
499 { | |
500 case AUDIO_U8: | |
501 for (i = 0; i < len; i++, src++, dst++) | |
502 *dst = (Uint8) (((float) (*src)) * volume); | |
503 break; | |
504 | |
505 case AUDIO_S8: | |
506 for (i = 0; i < len; i++, src++, dst++) | |
507 *dst = (Sint8) (((float) (*src)) * volume); | |
508 break; | |
509 | |
510 case AUDIO_U16LSB: | |
511 u16src = (Uint16 *) src; | |
512 u16dst = (Uint16 *) dst; | |
513 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
514 { | |
515 *u16dst = (Uint16) (((float) (SDL_SwapLE16(*u16src))) * volume); | |
516 *u16dst = SDL_SwapLE16(*u16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
517 } /* for */ |
270 | 518 break; |
519 | |
520 case AUDIO_S16LSB: | |
521 s16src = (Sint16 *) src; | |
522 s16dst = (Sint16 *) dst; | |
523 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
524 { | |
525 *s16dst = (Sint16) (((float) (SDL_SwapLE16(*s16src))) * volume); | |
526 *s16dst = SDL_SwapLE16(*s16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
527 } /* for */ |
270 | 528 break; |
529 | |
530 case AUDIO_U16MSB: | |
531 u16src = (Uint16 *) src; | |
532 u16dst = (Uint16 *) dst; | |
533 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
534 { | |
535 *u16dst = (Uint16) (((float) (SDL_SwapBE16(*u16src))) * volume); | |
536 *u16dst = SDL_SwapBE16(*u16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
537 } /* for */ |
270 | 538 break; |
539 | |
540 case AUDIO_S16MSB: | |
541 s16src = (Sint16 *) src; | |
542 s16dst = (Sint16 *) dst; | |
543 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
544 { | |
545 *s16dst = (Sint16) (((float) (SDL_SwapBE16(*s16src))) * volume); | |
546 *s16dst = SDL_SwapBE16(*s16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
547 } /* for */ |
270 | 548 break; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
549 } /* switch */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
550 } /* memcpy_with_volume */ |
270 | 551 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
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 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
|
554 { |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
555 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
|
556 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
|
557 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
558 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
|
559 { |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
560 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
|
561 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
562 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
|
563 { |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
564 /* ...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
|
565 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
|
566 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
|
567 return; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
568 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
570 /* 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
|
571 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
572 cpysize = len - bw; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
573 if (cpysize > global_state.decoded_bytes) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
574 cpysize = global_state.decoded_bytes; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
575 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
576 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
|
577 { |
310 | 578 memcpy_with_volume(sample, stream + bw, |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
579 (Uint8 *) global_state.decoded_ptr, |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
580 cpysize); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
581 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
582 bw += cpysize; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
583 global_state.decoded_ptr += cpysize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
584 global_state.decoded_bytes -= cpysize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
585 if (global_state.bytes_before_next_seek >= 0) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
586 global_state.bytes_before_next_seek -= cpysize; |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
587 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 } /* while */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
589 } /* audio_callback */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
590 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 |
310 | 592 static int count_seek_list(const char *list) |
593 { | |
594 const char *ptr; | |
595 int retval = 0; | |
596 | |
597 for (ptr = list; ptr != NULL; ptr = strchr(ptr + 1, ';')) | |
598 retval++; | |
599 | |
600 return(retval); | |
601 } /* count_seek_list */ | |
602 | |
603 | |
604 static Uint32 parse_time_str(char *str) | |
605 { | |
606 Uint32 minutes = 0; | |
607 Uint32 seconds = 0; | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
608 Uint32 ms = 0; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
609 |
310 | 610 char *ptr = strchr(str, ':'); |
611 if (ptr != NULL) | |
612 { | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
613 char *ptr2; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
614 |
310 | 615 *ptr = '\0'; |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
616 ptr2 = strchr(ptr + 1, ':'); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
617 if (ptr2 != NULL) |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
618 { |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
619 *ptr2 = '\0'; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
620 minutes = atoi(str); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
621 str = ptr + 1; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
622 ptr = ptr2; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
623 } /* if */ |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
624 |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
625 seconds = atoi(str); |
310 | 626 str = ptr + 1; |
627 } /* if */ | |
628 | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
629 ms = atoi(str); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
630 return( (((minutes * 60) + seconds) * 1000) + ms ); |
310 | 631 } /* parse_time_str */ |
632 | |
633 | |
634 static void parse_seek_list(const char *_list) | |
635 { | |
636 Uint32 i; | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
637 |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
638 char *list = (char*) malloc(strlen(_list) + 1); |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
639 char *save_list = list; |
310 | 640 if (list == NULL) |
641 { | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
642 fprintf(stderr, "malloc() failed. Skipping seek list.\n"); |
310 | 643 return; |
644 } /* if */ | |
645 | |
646 strcpy(list, _list); | |
647 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
648 if (global_state.seek_list != NULL) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
649 free((void *) global_state.seek_list); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
650 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
651 global_state.total_seeks = count_seek_list(list); |
310 | 652 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
653 global_state.seek_list = |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
654 (Uint32 *) malloc(global_state.total_seeks * sizeof (Uint32)); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
655 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
656 if (global_state.seek_list == NULL) |
310 | 657 { |
658 fprintf(stderr, "malloc() failed. Skipping seek list.\n"); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
659 global_state.total_seeks = 0; |
310 | 660 return; |
661 } /* if */ | |
662 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
663 for (i = 0; i < global_state.total_seeks; i++) |
310 | 664 { |
665 char *ptr = strchr(list, ';'); | |
666 if (ptr != NULL) | |
667 *ptr = '\0'; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
668 global_state.seek_list[i] = parse_time_str(list); |
310 | 669 list = ptr + 1; |
670 } /* for */ | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
671 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
672 global_state.bytes_before_next_seek = 0; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
673 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
674 free(save_list); |
310 | 675 } /* parse_seek_list */ |
676 | |
677 | |
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
|
678 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
|
679 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 } /* 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
|
694 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
695 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
696 static int valid_cmdline(int argc, char **argv) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
697 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
698 int i; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
699 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
700 if (argc < 2) /* no command line? Show help text and quit. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
701 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
702 output_usage(argv[0]); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
703 return(0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
704 } /* if */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
705 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
706 /* Make sure all command line options are valid. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
707 for (i = 1; i < argc; i++) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
708 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
709 const char **opts = option_list; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
710 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
711 if (strncmp(argv[i], "--", 2) != 0) /* not an option; skip it. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
712 continue; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
713 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
714 while (*opts != NULL) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
715 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
716 if (strcmp(argv[i], *(opts++)) == 0) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
717 break; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
718 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
719 opts++; /* skip option description. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
720 } /* else */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
721 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
722 if (*opts == NULL) /* didn't find it in option_list... */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
723 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
724 fprintf(stderr, "unknown option: \"%s\"\n", argv[i]); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
725 return(0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
726 } /* if */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
727 } /* for */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
728 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
729 return(1); /* everything appears to be in order. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
730 } /* valid_cmdline */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
731 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
732 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
733 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
|
734 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
735 Sound_AudioInfo sound_desired; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
736 SDL_AudioSpec sdl_desired; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
737 Uint32 audio_buffersize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
738 Uint32 decode_buffersize; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 int delay; |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
743 int new_sample = 1; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
744 Uint32 sdl_init_flags = SDL_INIT_AUDIO; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
745 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
746 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
747 SDL_Surface *screen = NULL; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
748 SDL_Event event; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
749 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
750 sdl_init_flags |= SDL_INIT_VIDEO; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
751 #endif |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
752 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
753 #ifdef HAVE_SETBUF |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
754 setbuf(stdout, NULL); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
755 setbuf(stderr, NULL); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
756 #endif |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
757 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
758 if (!valid_cmdline(argc, argv)) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
759 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
760 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
761 /* Handle some command lines upfront. */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
762 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
|
763 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
764 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
|
765 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
766 |
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
|
767 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
|
768 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
769 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
|
770 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
|
771 } /* 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
|
772 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
773 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
|
774 { |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
775 output_credits(); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
776 return(42); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
777 } /* if */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
778 |
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
|
779 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
|
780 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
781 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
|
782 return(42); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
783 } /* if */ |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
784 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
785 else if (strcmp(argv[i], "--decoders") == 0) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
786 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
787 if (!Sound_Init()) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
788 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
789 fprintf(stderr, "Sound_Init() failed!\n" |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
790 " reason: [%s].\n", Sound_GetError()); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
791 SDL_Quit(); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
792 return(42); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
793 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
794 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
795 output_decoders(); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
796 Sound_Quit(); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
797 return(0); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
798 } /* else if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
799 } /* for */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
800 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
801 if (!init_archive(argv[0])) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
802 return(42); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
803 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
804 if (SDL_Init(sdl_init_flags) == -1) |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
805 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
806 fprintf(stderr, "SDL_Init() failed!\n" |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
807 " reason: [%s].\n", SDL_GetError()); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
808 return(42); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
809 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
810 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
811 if (!Sound_Init()) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
812 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
813 fprintf(stderr, "Sound_Init() failed!\n" |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
814 " reason: [%s].\n", Sound_GetError()); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
815 SDL_Quit(); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
816 return(42); |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
817 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
818 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
819 #if HAVE_SIGNAL_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
820 signal(SIGINT, sigint_catcher); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
821 #endif |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
822 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
823 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
824 screen = SDL_SetVideoMode(320, 240, 8, 0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
825 assert(screen != NULL); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
826 #endif |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
827 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
828 for (i = 1; i < argc; i++) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
829 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
830 char *filename = NULL; |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
831 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
832 /* set variables back to defaults for next file... */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
833 if (new_sample) |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
834 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
835 if (global_state.seek_list != NULL) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
836 free((void *) global_state.seek_list); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
837 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
838 memset((void *) &global_state, '\0', sizeof (global_state)); |
409 | 839 memset(&sdl_desired, '\0', sizeof (SDL_AudioSpec)); |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
840 global_state.volume = 1.0; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
841 global_state.bytes_before_next_seek = -1; |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
842 audio_buffersize = DEFAULT_AUDIOBUF; |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
843 decode_buffersize = DEFAULT_DECODEBUF; |
391
3bd96d2d553c
Fixed looping and other settings that were being reinitialized incorrectly.
Ryan C. Gordon <icculus@icculus.org>
parents:
383
diff
changeset
|
844 new_sample = 0; |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
845 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
846 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
847 if (strcmp(argv[i], "--rate") == 0 && argc > i + 1) |
135
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
848 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
849 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
|
850 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
|
851 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
|
852 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
853 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
|
854 return(42); |
310 | 855 } /* 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
|
856 } /* 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
|
857 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
858 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
|
859 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
860 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
|
861 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
|
862 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
|
863 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
864 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
|
865 "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
|
866 return(42); |
310 | 867 } /* 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
|
868 } /* 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
|
869 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
870 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
|
871 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
872 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
|
873 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
|
874 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
|
875 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
876 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
|
877 "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
|
878 "(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
|
879 return(42); |
310 | 880 } /* 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
|
881 } /* else if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
882 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
883 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
|
884 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
885 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
|
886 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
887 |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
888 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
|
889 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
890 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
|
891 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
892 |
270 | 893 else if (strcmp(argv[i], "--volume") == 0 && argc > i + 1) |
894 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
895 global_state.volume = atof(argv[++i]); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
896 if (global_state.volume != 1.0) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
897 global_state.wants_volume_change = 1; |
270 | 898 } /* else if */ |
899 | |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
900 else if (strcmp(argv[i], "--predecode") == 0) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
901 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
902 global_state.predecode = 1; |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
903 } /* else if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
904 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
905 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
|
906 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
907 global_state.looping = atoi(argv[++i]); |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
908 } /* 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
|
909 |
310 | 910 else if (strcmp(argv[i], "--seek") == 0) |
911 { | |
912 parse_seek_list(argv[++i]); | |
913 } /* else if */ | |
914 | |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
915 else if (strcmp(argv[i], "--stdin") == 0) |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
916 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
917 SDL_RWops *rw = SDL_RWFromFP(stdin, 1); |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
918 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
|
919 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
920 /* |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
921 * 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
|
922 * 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
|
923 */ |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
924 sample = Sound_NewSample(rw, argv[++i], |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
925 use_specific_audiofmt ? &sound_desired : NULL, |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
926 decode_buffersize); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
927 } /* if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
928 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
929 else if (strncmp(argv[i], "--", 2) == 0) |
310 | 930 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
931 /* ignore it, since it was handled at startup. */ |
310 | 932 } /* else if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
933 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
934 else |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
935 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
936 filename = argv[i]; |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
937 sample = sample_from_archive(filename, |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
938 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
939 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
940 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
941 if (sample == NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
942 { |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
943 sample = Sound_NewSampleFromFile(filename, |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
944 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
945 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
946 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
947 } /* 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
|
948 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
949 if (filename == NULL) /* still parsing command line stuff? */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
950 continue; |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
951 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
952 new_sample = 1; |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
953 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
954 if (sample == NULL) |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
955 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
956 fprintf(stderr, "Couldn't load \"%s\"!\n" |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
957 " reason: [%s].\n", |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
958 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
|
959 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
960 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
961 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
962 if (global_state.total_seeks > 0) |
310 | 963 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
964 if ((!global_state.predecode) && |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
965 (!(sample->flags & SOUND_SAMPLEFLAG_CANSEEK))) |
310 | 966 { |
967 fprintf(stderr, "Want seeks, but sample cannot handle it!\n"); | |
968 Sound_FreeSample(sample); | |
969 close_archive(filename); | |
970 continue; | |
971 } /* if */ | |
972 } /* if */ | |
973 | |
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
|
974 /* |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
975 * 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
|
976 * 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
|
977 */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
978 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
|
979 { |
343
03f47480200f
Now works correctly when specifying not all three of the --rate, --channels,
Ryan C. Gordon <icculus@icculus.org>
parents:
334
diff
changeset
|
980 sdl_desired.freq = sample->desired.rate; |
03f47480200f
Now works correctly when specifying not all three of the --rate, --channels,
Ryan C. Gordon <icculus@icculus.org>
parents:
334
diff
changeset
|
981 sdl_desired.format = sample->desired.format; |
03f47480200f
Now works correctly when specifying not all three of the --rate, --channels,
Ryan C. Gordon <icculus@icculus.org>
parents:
334
diff
changeset
|
982 sdl_desired.channels = sample->desired.channels; |
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
|
983 } /* 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
|
984 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
|
985 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
986 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
|
987 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
|
988 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
|
989 } /* 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
|
990 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
991 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
|
992 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
|
993 sdl_desired.userdata = sample; |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
994 |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
995 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
|
996 { |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
997 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
|
998 " 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
|
999 Sound_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1000 SDL_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1001 return(42); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1002 } /* if */ |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1003 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
1004 fprintf(stdout, "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
|
1005 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1006 if (global_state.predecode) |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1007 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
1008 fprintf(stdout, " predecoding..."); |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1009 global_state.decoded_bytes = Sound_DecodeAll(sample); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1010 global_state.decoded_ptr = sample->buffer; |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1011 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1012 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1013 fprintf(stderr, |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1014 "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
|
1015 " reason: [%s].\n" |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1016 " (playing first %lu bytes of decoded data...)\n", |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1017 filename, Sound_GetError(), global_state.decoded_bytes); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1018 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1019 else |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1020 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
1021 fprintf(stdout, "done.\n"); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1022 } /* else */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1023 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1024 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1025 SDL_PauseAudio(0); |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
1026 |
406
325af3e2cbb3
Reset done_flag between files so everything plays correctly.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
1027 done_flag = 0; /* the audio callback will flip this flag. */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1028 while (!done_flag) |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1029 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1030 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1031 SDL_PollEvent(&event); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1032 if ((event.type == SDL_KEYDOWN) || (event.type == SDL_QUIT)) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1033 done_flag = 1; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1034 #endif |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1035 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1036 SDL_Delay(10); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1037 } /* while */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1038 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1039 SDL_PauseAudio(1); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1040 |
236 | 1041 /* |
1042 * Sleep two buffers' worth of audio before closing, in order | |
1043 * to allow the playback to finish. This isn't always enough; | |
1044 * perhaps SDL needs a way to explicitly wait for device drain? | |
1045 */ | |
1046 delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq; | |
1047 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
|
1048 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1049 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
|
1050 Sound_FreeSample(sample); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
1051 |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
1052 close_archive(filename); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1053 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1054 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1055 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1056 SDL_Quit(); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
1057 deinit_archive(); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1058 return(0); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1059 } /* main */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1060 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1061 /* 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
|
1062 |