Mercurial > SDL_sound_CoreAudio
annotate playsound/playsound.c @ 573:1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 24 Jan 2010 14:01:39 -0500 |
parents | 7815c90ba552 |
children |
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 * |
552
2e8907ff98e9
Replaced references to COPYING with references to LICENSE.txt ...
Ryan C. Gordon <icculus@icculus.org>
parents:
536
diff
changeset
|
23 * Please see the file LICENSE.txt 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 * |
526
2df1f5c62d38
Updated my email address.
Ryan C. Gordon <icculus@icculus.org>
parents:
409
diff
changeset
|
25 * This file written by Ryan C. Gordon. (icculus@icculus.org) |
58
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 |
563
11bb8cb8ebc8
I think we can call playsound a 1.0 release by now. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
552
diff
changeset
|
57 #define PLAYSOUND_VER_MAJOR 1 |
11bb8cb8ebc8
I think we can call playsound a 1.0 release by now. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
552
diff
changeset
|
58 #define PLAYSOUND_VER_MINOR 0 |
11bb8cb8ebc8
I think we can call playsound a 1.0 release by now. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
552
diff
changeset
|
59 #define PLAYSOUND_VER_PATCH 0 |
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" |
536
8a814bbbedfa
Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
Ryan C. Gordon <icculus@icculus.org>
parents:
526
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); |
572
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
315 if (done_flag < 0) |
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
316 return; /* mashing CTRL-C, we get it already. */ |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
317 |
572
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
318 done_flag = ((last_sigint != 0) && (ticks - last_sigint < 500)) ? -1 : 1; |
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
319 last_sigint = ticks; |
148
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
320 } /* sigint_catcher */ |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
321 #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
|
322 |
d51546293fd1
Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
323 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
324 /* global decoding state. */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
325 typedef struct |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
326 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
327 Uint8 *decoded_ptr; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
328 Uint32 decoded_bytes; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
329 int predecode; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
330 int looping; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
331 int wants_volume_change; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
332 float volume; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
333 Uint32 total_seeks; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
334 Uint32 *seek_list; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
335 Uint32 seek_index; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
336 Sint32 bytes_before_next_seek; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
337 } playsound_global_state; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
338 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
339 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
|
340 |
310 | 341 |
342 static Uint32 cvtMsToBytePos(Sound_AudioInfo *info, Uint32 ms) | |
343 { | |
344 /* "frames" == "sample frames" */ | |
345 float frames_per_ms = ((float) info->rate) / 1000.0; | |
346 Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms)); | |
347 Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels; | |
348 return(frame_offset * frame_size); | |
349 } /* cvtMsToBytePos */ | |
350 | |
351 | |
352 static void do_seek(Sound_Sample *sample) | |
353 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
358 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
|
359 (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
|
360 (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
|
361 (int) ((seek_list[seek_index] % 1000))); |
310 | 362 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
363 if (global_state.predecode) |
310 | 364 { |
365 Uint32 pos = cvtMsToBytePos(&sample->desired, seek_list[seek_index]); | |
366 if (pos > sample->buffer_size) | |
367 { | |
368 fprintf(stderr, "Seek past end of predecoded buffer.\n"); | |
369 done_flag = 1; | |
370 } /* if */ | |
371 else | |
372 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
373 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
|
374 global_state.decoded_bytes = sample->buffer_size - pos; |
310 | 375 } /* else */ |
376 } /* if */ | |
377 else | |
378 { | |
379 if (!Sound_Seek(sample, seek_list[seek_index])) | |
380 { | |
381 fprintf(stderr, "Sound_Seek() failed: %s\n", Sound_GetError()); | |
382 done_flag = 1; | |
383 } /* if */ | |
384 } /* else */ | |
385 | |
386 seek_index++; | |
387 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
|
388 global_state.bytes_before_next_seek = -1; /* no more seeks. */ |
310 | 389 else |
390 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
391 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
|
392 seek_list[seek_index]); |
310 | 393 seek_index++; |
394 } /* else */ | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
395 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
396 global_state.seek_index = seek_index; |
310 | 397 } /* 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
|
398 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
399 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
400 /* |
310 | 401 * This updates (decoded_bytes) and (decoded_ptr) with more audio data, |
402 * 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
|
403 */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
404 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
|
405 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
406 if (done_flag) /* probably a sigint; stop trying to read. */ |
310 | 407 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
408 global_state.decoded_bytes = 0; |
310 | 409 return(0); |
410 } /* if */ | |
411 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
412 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
|
413 (global_state.decoded_bytes > global_state.bytes_before_next_seek)) |
310 | 414 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
415 global_state.decoded_bytes = global_state.bytes_before_next_seek; |
310 | 416 } /* 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
|
417 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
418 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
|
419 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
|
420 |
310 | 421 /* 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
|
422 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
|
423 (global_state.seek_index < global_state.total_seeks)) |
310 | 424 { |
425 do_seek(sample); /* do it, baby! */ | |
426 return(read_more_data(sample)); /* handle loops conditions. */ | |
427 } /* if */ | |
428 | |
429 /* 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
|
430 if ( (global_state.bytes_before_next_seek != 0) && |
310 | 431 (!(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
|
432 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
433 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
|
434 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
|
435 { |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
436 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
|
437 " 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
|
438 } /* if */ |
0ac181b5adc6
Corrected error reporting to respect Sound_GetError()'s new thread
Ryan C. Gordon <icculus@icculus.org>
parents:
270
diff
changeset
|
439 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
440 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
|
441 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
|
442 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
443 |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
444 /* 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
|
445 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
446 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
|
447 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
|
448 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
449 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
|
450 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
451 global_state.seek_index = 0; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
452 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
|
453 (global_state.total_seeks > 0) ? 0 : -1; |
310 | 454 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
455 /* 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
|
456 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
|
457 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
458 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
|
459 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
|
460 } /* if */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
461 else |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
462 { |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
463 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
|
464 } /* else */ |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
465 |
310 | 466 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
|
467 } /* 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
|
468 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
469 |
270 | 470 static void memcpy_with_volume(Sound_Sample *sample, |
471 Uint8 *dst, Uint8 *src, int len) | |
472 { | |
473 int i; | |
474 Uint16 *u16src = NULL; | |
475 Uint16 *u16dst = NULL; | |
476 Sint16 *s16src = NULL; | |
477 Sint16 *s16dst = NULL; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
478 float volume = global_state.volume; |
270 | 479 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
480 if (!global_state.wants_volume_change) |
270 | 481 { |
482 memcpy(dst, src, len); | |
483 return; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
484 } /* if */ |
270 | 485 |
486 /* !!! FIXME: This would be more efficient with a lookup table. */ | |
487 switch (sample->desired.format) | |
488 { | |
489 case AUDIO_U8: | |
490 for (i = 0; i < len; i++, src++, dst++) | |
491 *dst = (Uint8) (((float) (*src)) * volume); | |
492 break; | |
493 | |
494 case AUDIO_S8: | |
495 for (i = 0; i < len; i++, src++, dst++) | |
496 *dst = (Sint8) (((float) (*src)) * volume); | |
497 break; | |
498 | |
499 case AUDIO_U16LSB: | |
500 u16src = (Uint16 *) src; | |
501 u16dst = (Uint16 *) dst; | |
502 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
503 { | |
504 *u16dst = (Uint16) (((float) (SDL_SwapLE16(*u16src))) * volume); | |
505 *u16dst = SDL_SwapLE16(*u16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
506 } /* for */ |
270 | 507 break; |
508 | |
509 case AUDIO_S16LSB: | |
510 s16src = (Sint16 *) src; | |
511 s16dst = (Sint16 *) dst; | |
512 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
513 { | |
514 *s16dst = (Sint16) (((float) (SDL_SwapLE16(*s16src))) * volume); | |
515 *s16dst = SDL_SwapLE16(*s16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
516 } /* for */ |
270 | 517 break; |
518 | |
519 case AUDIO_U16MSB: | |
520 u16src = (Uint16 *) src; | |
521 u16dst = (Uint16 *) dst; | |
522 for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) | |
523 { | |
524 *u16dst = (Uint16) (((float) (SDL_SwapBE16(*u16src))) * volume); | |
525 *u16dst = SDL_SwapBE16(*u16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
526 } /* for */ |
270 | 527 break; |
528 | |
529 case AUDIO_S16MSB: | |
530 s16src = (Sint16 *) src; | |
531 s16dst = (Sint16 *) dst; | |
532 for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) | |
533 { | |
534 *s16dst = (Sint16) (((float) (SDL_SwapBE16(*s16src))) * volume); | |
535 *s16dst = SDL_SwapBE16(*s16dst); | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
536 } /* for */ |
270 | 537 break; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
538 } /* switch */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
539 } /* memcpy_with_volume */ |
270 | 540 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
541 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 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
|
543 { |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
544 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
|
545 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
|
546 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
547 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
|
548 { |
150
033afe96afbc
Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
549 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
|
550 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
551 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
|
552 { |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
553 /* ...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
|
554 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
|
555 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
|
556 return; |
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
557 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
559 /* 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
|
560 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
561 cpysize = len - bw; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
562 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
|
563 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
|
564 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
565 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
|
566 { |
310 | 567 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
|
568 (Uint8 *) global_state.decoded_ptr, |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
569 cpysize); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
570 |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
571 bw += cpysize; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
572 global_state.decoded_ptr += cpysize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
573 global_state.decoded_bytes -= cpysize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
574 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
|
575 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
|
576 } /* if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
577 } /* while */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 } /* audio_callback */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 |
310 | 581 static int count_seek_list(const char *list) |
582 { | |
583 const char *ptr; | |
584 int retval = 0; | |
585 | |
586 for (ptr = list; ptr != NULL; ptr = strchr(ptr + 1, ';')) | |
587 retval++; | |
588 | |
589 return(retval); | |
590 } /* count_seek_list */ | |
591 | |
592 | |
593 static Uint32 parse_time_str(char *str) | |
594 { | |
595 Uint32 minutes = 0; | |
596 Uint32 seconds = 0; | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
597 Uint32 ms = 0; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
598 |
310 | 599 char *ptr = strchr(str, ':'); |
600 if (ptr != NULL) | |
601 { | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
602 char *ptr2; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
603 |
310 | 604 *ptr = '\0'; |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
605 ptr2 = strchr(ptr + 1, ':'); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
606 if (ptr2 != NULL) |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
607 { |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
608 *ptr2 = '\0'; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
609 minutes = atoi(str); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
610 str = ptr + 1; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
611 ptr = ptr2; |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
612 } /* if */ |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
613 |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
614 seconds = atoi(str); |
310 | 615 str = ptr + 1; |
616 } /* if */ | |
617 | |
334
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
618 ms = atoi(str); |
f0f894d897bf
--seek argument now specifies minutes, seconds, and milliseconds.
Ryan C. Gordon <icculus@icculus.org>
parents:
320
diff
changeset
|
619 return( (((minutes * 60) + seconds) * 1000) + ms ); |
310 | 620 } /* parse_time_str */ |
621 | |
622 | |
623 static void parse_seek_list(const char *_list) | |
624 { | |
625 Uint32 i; | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
626 |
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
627 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
|
628 char *save_list = list; |
310 | 629 if (list == NULL) |
630 { | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
631 fprintf(stderr, "malloc() failed. Skipping seek list.\n"); |
310 | 632 return; |
633 } /* if */ | |
634 | |
635 strcpy(list, _list); | |
636 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
637 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
|
638 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
|
639 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
640 global_state.total_seeks = count_seek_list(list); |
310 | 641 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
642 global_state.seek_list = |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
643 (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
|
644 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
645 if (global_state.seek_list == NULL) |
310 | 646 { |
647 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
|
648 global_state.total_seeks = 0; |
310 | 649 return; |
650 } /* if */ | |
651 | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
652 for (i = 0; i < global_state.total_seeks; i++) |
310 | 653 { |
654 char *ptr = strchr(list, ';'); | |
655 if (ptr != NULL) | |
656 *ptr = '\0'; | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
657 global_state.seek_list[i] = parse_time_str(list); |
310 | 658 list = ptr + 1; |
659 } /* for */ | |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
660 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
661 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
|
662 |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
663 free(save_list); |
310 | 664 } /* parse_seek_list */ |
665 | |
666 | |
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
|
667 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
|
668 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 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
|
682 } /* 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
|
683 |
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 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
685 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
|
686 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
687 int i; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
688 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
689 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
|
690 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
691 output_usage(argv[0]); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
692 return(0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
693 } /* if */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
694 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
695 /* 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
|
696 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
|
697 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
698 const char **opts = option_list; |
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 (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
|
701 continue; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
702 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
703 while (*opts != NULL) |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
704 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
705 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
|
706 break; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
707 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
708 opts++; /* skip option description. */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
709 } /* else */ |
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 (*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
|
712 { |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
713 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
|
714 return(0); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
715 } /* if */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
716 } /* for */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
717 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
718 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
|
719 } /* valid_cmdline */ |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
720 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
721 |
573
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
722 static void report_filename(const char *filename) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
723 { |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
724 const char *icon = "playsound"; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
725 size_t len = 0; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
726 char *buf = NULL; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
727 char *ptr = NULL; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
728 |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
729 fprintf(stdout, "%s: Now playing [%s]...\n", icon, filename); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
730 |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
731 /* |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
732 * Bleeding edge versions of SDL 1.2 can use this to set the |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
733 * PulseAudio application name. It's a harmless no-op elsewhere, |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
734 * and 1.3 will probably have a formal API for this. |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
735 */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
736 ptr = strrchr(filename, '/'); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
737 if (ptr != NULL) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
738 filename = ptr + 1; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
739 ptr = strrchr(filename, '\\'); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
740 if (ptr != NULL) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
741 filename = ptr + 1; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
742 |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
743 len = strlen(filename) + strlen(icon) + 3; |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
744 buf = (char *) malloc(len); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
745 if (buf == NULL) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
746 SDL_WM_SetCaption(icon, icon); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
747 else |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
748 { |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
749 snprintf(buf, len, "%s: %s", icon, filename); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
750 SDL_WM_SetCaption(buf, icon); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
751 free(buf); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
752 } /* else */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
753 } /* report_filename */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
754 |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
755 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
756 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
|
757 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
758 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
|
759 SDL_AudioSpec sdl_desired; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
760 Uint32 audio_buffersize; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
761 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
|
762 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
|
763 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
|
764 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
|
765 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
|
766 int new_sample = 1; |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
767 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
|
768 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
769 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
770 SDL_Surface *screen = NULL; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
771 SDL_Event event; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
772 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
773 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
|
774 #endif |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
775 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
776 #ifdef HAVE_SETBUF |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
777 setbuf(stdout, NULL); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
778 setbuf(stderr, NULL); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
779 #endif |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
780 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
781 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
|
782 return(42); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
783 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
784 /* 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
|
785 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
|
786 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
787 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
|
788 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
789 |
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
|
790 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
|
791 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
792 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
|
793 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
|
794 } /* 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
|
795 |
176
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
796 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
|
797 { |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
798 output_credits(); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
799 return(42); |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
800 } /* if */ |
69922f6a5c74
Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents:
168
diff
changeset
|
801 |
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
|
802 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
|
803 { |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
804 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
|
805 return(42); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
806 } /* 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
|
807 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
808 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
|
809 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
810 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
|
811 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
812 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
|
813 " 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
|
814 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
|
815 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
|
816 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
817 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
818 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
|
819 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
|
820 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
|
821 } /* 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
|
822 } /* for */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
823 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
824 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
|
825 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
|
826 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
827 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
|
828 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
829 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
|
830 " 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
|
831 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
|
832 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
833 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
834 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
|
835 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
836 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
|
837 " 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
|
838 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
|
839 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
|
840 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
841 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
842 #if HAVE_SIGNAL_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
843 signal(SIGINT, sigint_catcher); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
844 #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
|
845 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
846 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
847 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
|
848 assert(screen != NULL); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
849 #endif |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
850 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
851 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
|
852 { |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
853 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
|
854 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
855 /* 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
|
856 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
|
857 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
858 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
|
859 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
|
860 |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
861 memset((void *) &global_state, '\0', sizeof (global_state)); |
409 | 862 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
|
863 global_state.volume = 1.0; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 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
|
868 } /* if */ |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
869 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
870 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
|
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.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
|
874 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
|
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, "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
|
877 return(42); |
310 | 878 } /* 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
|
879 } /* 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
|
880 |
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 (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
|
882 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
883 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
|
884 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
|
885 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
|
886 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
887 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
|
888 "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
|
889 return(42); |
310 | 890 } /* 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
|
891 } /* 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
|
892 |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
893 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
|
894 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
899 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
|
900 "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
|
901 "(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
|
902 return(42); |
310 | 903 } /* 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
|
904 } /* else if */ |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
905 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
906 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
|
907 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
908 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
|
909 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
910 |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
911 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
|
912 { |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
913 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
|
914 } /* else if */ |
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
915 |
270 | 916 else if (strcmp(argv[i], "--volume") == 0 && argc > i + 1) |
917 { | |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
918 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
|
919 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
|
920 global_state.wants_volume_change = 1; |
270 | 921 } /* else if */ |
922 | |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
923 else if (strcmp(argv[i], "--predecode") == 0) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
924 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
925 global_state.predecode = 1; |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
926 } /* else if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
927 |
222
d6b24586822a
Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents:
214
diff
changeset
|
928 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
|
929 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
930 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
|
931 } /* 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
|
932 |
310 | 933 else if (strcmp(argv[i], "--seek") == 0) |
934 { | |
935 parse_seek_list(argv[++i]); | |
936 } /* else if */ | |
937 | |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
938 else if (strcmp(argv[i], "--stdin") == 0) |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
939 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
940 SDL_RWops *rw = SDL_RWFromFP(stdin, 1); |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
941 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
|
942 |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
943 /* |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
944 * 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
|
945 * 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
|
946 */ |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
947 sample = Sound_NewSample(rw, argv[++i], |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
948 use_specific_audiofmt ? &sound_desired : NULL, |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
949 decode_buffersize); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
950 } /* if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
951 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
952 else if (strncmp(argv[i], "--", 2) == 0) |
310 | 953 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
954 /* ignore it, since it was handled at startup. */ |
310 | 955 } /* else if */ |
280
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
956 |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
957 else |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
958 { |
06fbb106a554
Can now read from stdin.
Ryan C. Gordon <icculus@icculus.org>
parents:
272
diff
changeset
|
959 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
|
960 sample = sample_from_archive(filename, |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
961 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
962 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
963 |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
964 if (sample == NULL) |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
965 { |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
966 sample = Sound_NewSampleFromFile(filename, |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
967 use_specific_audiofmt ? &sound_desired : NULL, |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
968 decode_buffersize); |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
969 } /* if */ |
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
970 } /* 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
|
971 |
308
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
972 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
|
973 continue; |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
974 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
975 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
|
976 |
6a80b2f9c47c
Command line updates, added Darrell to the credits, and cleaned up other
Ryan C. Gordon <icculus@icculus.org>
parents:
302
diff
changeset
|
977 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
|
978 { |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
979 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
|
980 " 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
|
981 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
|
982 continue; |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
983 } /* if */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
984 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
985 if (global_state.total_seeks > 0) |
310 | 986 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
987 if ((!global_state.predecode) && |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
988 (!(sample->flags & SOUND_SAMPLEFLAG_CANSEEK))) |
310 | 989 { |
990 fprintf(stderr, "Want seeks, but sample cannot handle it!\n"); | |
991 Sound_FreeSample(sample); | |
992 close_archive(filename); | |
993 continue; | |
994 } /* if */ | |
995 } /* if */ | |
996 | |
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
|
997 /* |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
998 * 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
|
999 * 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
|
1000 */ |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
1001 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
|
1002 { |
343
03f47480200f
Now works correctly when specifying not all three of the --rate, --channels,
Ryan C. Gordon <icculus@icculus.org>
parents:
334
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 } /* 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
|
1007 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
|
1008 { |
69cd80e80363
Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents:
112
diff
changeset
|
1009 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
|
1010 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
|
1011 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
|
1012 } /* 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
|
1013 |
187
bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
1014 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
|
1015 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
|
1016 sdl_desired.userdata = sample; |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1017 |
573
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1018 /* grr, SDL_CloseAudio() calls SDL_QuitSubSystem internally. */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1019 if (!SDL_WasInit(SDL_INIT_AUDIO)) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1020 { |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1021 if (SDL_Init(SDL_INIT_AUDIO) == -1) |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1022 { |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1023 fprintf(stderr, "SDL_Init() failed!\n" |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1024 " reason: [%s].\n", SDL_GetError()); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1025 Sound_Quit(); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1026 SDL_Quit(); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1027 return(42); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1028 } /* if */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1029 } /* if */ |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1030 |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1031 report_filename(filename); |
1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
1032 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1033 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
|
1034 { |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1035 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
|
1036 " 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
|
1037 Sound_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1038 SDL_Quit(); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1039 return(42); |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1040 } /* if */ |
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1041 |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1042 if (global_state.predecode) |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1043 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
1044 fprintf(stdout, " predecoding..."); |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1045 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
|
1046 global_state.decoded_ptr = sample->buffer; |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1047 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1048 { |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1049 fprintf(stderr, |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1050 "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
|
1051 " reason: [%s].\n" |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1052 " (playing first %lu bytes of decoded data...)\n", |
571
3b8748455aff
Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents:
563
diff
changeset
|
1053 filename, Sound_GetError(), |
3b8748455aff
Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents:
563
diff
changeset
|
1054 (unsigned long) global_state.decoded_bytes); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1055 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1056 else |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1057 { |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
343
diff
changeset
|
1058 fprintf(stdout, "done.\n"); |
168
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1059 } /* else */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1060 } /* if */ |
87b00f023710
Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
1061 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1062 SDL_PauseAudio(0); |
320
8195b86207bb
Mac fixes, and removed all alloca() calls.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
1063 |
406
325af3e2cbb3
Reset done_flag between files so everything plays correctly.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
1064 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
|
1065 while (!done_flag) |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1066 { |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1067 #if ENABLE_EVENTS |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1068 SDL_PollEvent(&event); |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1069 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
|
1070 done_flag = 1; |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1071 #endif |
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1072 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1073 SDL_Delay(10); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1074 } /* while */ |
383
818f9af97a19
Cleanups, FIXME removals, and better command line handling.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
1075 |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1076 SDL_PauseAudio(1); |
146
023c3e7f028b
Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents:
144
diff
changeset
|
1077 |
236 | 1078 /* |
1079 * Sleep two buffers' worth of audio before closing, in order | |
1080 * to allow the playback to finish. This isn't always enough; | |
1081 * perhaps SDL needs a way to explicitly wait for device drain? | |
1082 */ | |
1083 delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq; | |
1084 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
|
1085 |
112
3fcb23da06ba
Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents:
82
diff
changeset
|
1086 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
|
1087 Sound_FreeSample(sample); |
283
6c059c4d2cea
Added PhysicsFS support.
Ryan C. Gordon <icculus@icculus.org>
parents:
280
diff
changeset
|
1088 |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
1089 close_archive(filename); |
572
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
1090 |
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
1091 if (done_flag < 0) |
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
1092 break; |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1093 } /* for */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1094 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1095 Sound_Quit(); |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1096 SDL_Quit(); |
302
414cfef0978e
Cleaned up archive support. Fixes segfault when playing non-archived
Ryan C. Gordon <icculus@icculus.org>
parents:
288
diff
changeset
|
1097 deinit_archive(); |
572
7815c90ba552
Don't force quit in signal handler, since we might double-free things.
Ryan C. Gordon <icculus@icculus.org>
parents:
571
diff
changeset
|
1098 return((done_flag < 0) ? 1 : 0); |
58
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1099 } /* main */ |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1100 |
4a51162099e0
Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1101 /* 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
|
1102 |