annotate playsound/playsound.c @ 377:cbb15ecf423a

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