annotate playsound/playsound.c @ 236:034b2e56f405

Fixed some tabs.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 19 Jan 2002 23:27:42 +0000
parents d6b24586822a
children c54eae85f5f1
rev   line source
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /**
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * This is a quick and dirty test of SDL_sound.
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
184
47cc2de2ae36 Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents: 176
diff changeset
23 * Please see the file COPYING in the source's root directory.
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <stdio.h>
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include <string.h>
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #include <assert.h>
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
31 #include <signal.h>
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #include "SDL.h"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include "SDL_sound.h"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
35 #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
36 #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
37
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #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
39 #define PLAYSOUND_VER_MINOR 1
196
9d436dbb1666 Sync version number to that of libSDL_sound.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
40 #define PLAYSOUND_VER_PATCH 4
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 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
43 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 Sound_Version compiled;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 Sound_Version linked;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 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
47 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
48
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 SOUND_VERSION(&compiled);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 Sound_GetLinkedVersion(&linked);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 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
52 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
53
176
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
54 printf("%s version %d.%d.%d\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
55 "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
56 "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
57 "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
58 "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
59 "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
60 "\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
61 " 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
62 " 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
63 " 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
64 " 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
65 argv0,
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 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
67 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
68 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
69 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
70 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
71 } /* output_versions */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 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
75 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 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
77 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
78 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
79
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
80 printf("Supported sound formats:\n");
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 if (rc == NULL)
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
82 printf(" * Apparently, NONE!\n");
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 else
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 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
86 {
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
87 printf(" * %s\n", (*i)->description);
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
88 for (ext = (*i)->extensions; *ext != NULL; ext++)
150
033afe96afbc Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
89 printf(" File extension \"%s\"\n", *ext);
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
90 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url);
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 } /* for */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 } /* else */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
94 printf("\n");
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 } /* output_decoders */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
176
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
98 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
99 {
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
100 fprintf(stderr,
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
101 "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
102 "\n"
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
103 " Options:\n"
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
104 " --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
105 " --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
106 " --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
107 " --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
108 " --audiobuf n Buffer n samples to audio device (default %d).\n"
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
109 " --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
110 " --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
111 " --predecode Decode entire sample before playback.\n"
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
112 " --loop Loop playback until SIGINT.\n"
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
113 " --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
114 " --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
115 "\n"
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
116 " 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
117 " 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
118 " 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
119 " 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
120 " 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
121 " 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
122 " S16MSB Signed 16-bit (most significant byte first).\n"
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
123 "\n",
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
124 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
125 } /* output_usage */
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
126
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
127
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
128 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
129 {
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
130 printf("playsound version %d.%d.%d\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
131 "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
132 "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
133 "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
134 "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
135 "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
136 "\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
137 " Written by Ryan C. Gordon, Torbjörn Andersson, Max Horn,\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
138 " Tsuyoshi Iguchi, Tyler Montbriand, and a cast of thousands.\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
139 "\n"
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
140 " 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
141 "\n",
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
142 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
143 } /* output_credits */
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
144
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
145
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
146
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 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
148
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
149
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
150 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
151 {
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
152 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
153 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
154
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
155 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
156
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
157 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
158 {
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
159 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
160 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
161 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
162 SDL_Quit();
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
163 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
164 } /* if */
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
165
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
166 else
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
167 {
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
168 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
169 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
170 } /* else */
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
171 } /* sigint_catcher */
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
172
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
173
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
174 static Uint8 *decoded_ptr = NULL;
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
175 static Uint32 decoded_bytes = 0;
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
176 static int predecode = 0;
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
177 static int looping = 0;
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
178
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
179 /*
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
180 * This updates (decoded_bytes) and (decoder_ptr) with more audio data,
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
181 * taking into account looping and/or predecoding.
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
182 */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
183 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
184 {
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
185 if (done_flag) /* probably a sigint; stop trying to read. */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
186 decoded_bytes = 0;
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
187
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
188 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
189 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
190
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
191 /* need more. See if there's more to be read... */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
192 if (!(sample->flags & (SOUND_SAMPLEFLAG_ERROR | SOUND_SAMPLEFLAG_EOF)))
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
193 {
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
194 decoded_bytes = Sound_Decode(sample);
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
195 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
196 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
197 } /* if */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
198
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
199 /* 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
200
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
201 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
202 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
203
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
204 /* 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
205 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
206 {
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
207 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
208 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
209 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
210 } /* if */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
211 else
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
212 {
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
213 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
214 return(read_more_data(sample));
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
215 } /* else */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
216
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
217 assert(0); /* shouldn't ever hit this point. */
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
218 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
219 } /* 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
220
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
221
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 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
223 {
112
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
224 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
225 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
226
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
227 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
228 {
150
033afe96afbc Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
229 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
230
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
231 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
232 {
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
233 /* ...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
234 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
235 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
236 return;
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
237 } /* if */
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
239 /* 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
240
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
241 cpysize = len - bw;
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
242 if (cpysize > decoded_bytes)
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
243 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
244
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
245 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
246 {
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
247 memcpy(stream + bw, decoded_ptr, cpysize);
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
248 bw += cpysize;
150
033afe96afbc Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
249 decoded_ptr += cpysize;
033afe96afbc Commenting and fixes for the audio callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
250 decoded_bytes -= cpysize;
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
251 } /* if */
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 } /* while */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 } /* audio_callback */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255
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
256 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
257 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270 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
271 } /* 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
272
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
273
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 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
275 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 int delay;
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
168
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
286 setbuf(stdout, NULL);
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
287 setbuf(stderr, NULL);
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
288
112
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
289 /* !!! FIXME: Move this to a parse_cmdline() function... */
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 if (argc < 2)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 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
293 return(42);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 } /* if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295
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
296 memset(&sound_desired, '\0', sizeof (sound_desired));
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
297
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 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
299 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 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
301 continue;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302
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
303 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
304 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 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
306 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
307 } /* 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
308
176
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
309 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
310 {
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
311 output_credits();
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
312 return(42);
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
313 } /* if */
69922f6a5c74 Added GNU disclaimers and a --credits option with our names.
Ryan C. Gordon <icculus@icculus.org>
parents: 168
diff changeset
314
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
315 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
316 {
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 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
318 return(42);
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 } /* 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
320
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
321 else if (strcmp(argv[i], "--rate") == 0 && argc > i + 1)
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
322 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
323 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
324 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
325 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
326 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
327 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
328 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
329 }
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
330 } /* 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
331
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
332 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
333 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
334 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
335 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
336 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
337 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
338 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
339 "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
340 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
341 }
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
342 } /* 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
343
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
344 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
345 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
346 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
347 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
348 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
349 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
350 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
351 "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
352 "(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
353 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
354 }
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
355 } /* else if */
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
357 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
358 {
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
359 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
360 } /* else if */
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
361
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
362 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
363 {
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
364 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
365 } /* else if */
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
366
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 else if (strcmp(argv[i], "--decoders") == 0)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 if (!Sound_Init())
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 fprintf(stderr, "Sound_Init() failed!\n"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 " reason: [%s].\n", Sound_GetError());
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 SDL_Quit();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 return(42);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 } /* if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 output_decoders();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 Sound_Quit();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379 return(0);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 } /* else if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381
168
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
382 else if (strcmp(argv[i], "--predecode") == 0)
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
383 {
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
384 predecode = 1;
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
385 } /* else if */
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
386
222
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
387 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
388 {
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
389 looping = 1;
d6b24586822a Support for looping sounds via a new --loop command line. Rewritten (again!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
390 } /* 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
391
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 else
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 return(42);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 } /* else */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 } /* for */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398
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
399 /* Pick sensible defaults for any value not explicitly specified. */
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
400 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
401 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
402 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
403 sound_desired.rate = 44100;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
404 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
405 sound_desired.format = AUDIO_S16SYS;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
406 if (sound_desired.channels == 0)
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
407 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
408 } /* 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
409
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 if (SDL_Init(SDL_INIT_AUDIO) == -1)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 fprintf(stderr, "SDL_Init(SDL_INIT_AUDIO) failed!\n"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 " reason: [%s].\n", SDL_GetError());
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 return(42);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 } /* if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 if (!Sound_Init())
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 fprintf(stderr, "Sound_Init() failed!\n"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 " reason: [%s].\n", Sound_GetError());
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 SDL_Quit();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 return(42);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 } /* if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424
148
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
425 signal(SIGINT, sigint_catcher);
d51546293fd1 Support for multiple file extensions in the decoders, and a SIGINT catcher.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
426
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 for (i = 1; i < argc; i++)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 {
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
429 /* !!! FIXME: This is ugly! */
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
430 if ( (strcmp(argv[i], "--rate") == 0) ||
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
431 (strcmp(argv[i], "--format") == 0) ||
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
432 (strcmp(argv[i], "--channels") == 0) ||
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
433 (strcmp(argv[i], "--audiobuf") == 0) ||
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
434 (strcmp(argv[i], "--decodebuf") == 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
435 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
436 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
437 continue;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
438 } /* 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
439
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 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
441 continue;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442
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
443 sample = Sound_NewSampleFromFile(argv[i],
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
444 use_specific_audiofmt ? &sound_desired : NULL,
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
445 decode_buffersize);
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
446
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 if (!sample)
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 {
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449 fprintf(stderr, "Couldn't load \"%s\"!\n"
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450 " reason: [%s].\n", argv[i], Sound_GetError());
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451 continue;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452 } /* if */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453
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
454 /*
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
455 * 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
456 * 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
457 */
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
458 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
459 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
460 sdl_desired.freq = sound_desired.rate;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
461 sdl_desired.format = sound_desired.format;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
462 sdl_desired.channels = sound_desired.channels;
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
463 } /* 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
464 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
465 {
69cd80e80363 Added Torbj�rn Andersson's command lines, and cleaned up the usage output.
Ryan C. Gordon <icculus@icculus.org>
parents: 112
diff changeset
466 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
467 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
468 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
469 } /* 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
470
187
bfe5031726e8 printf() fix (extra comma was in there), and --decodebuf/--audiobuf
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
471 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
472 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
473 sdl_desired.userdata = sample;
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
474
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
475 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
476 {
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
477 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
478 " 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
479 Sound_Quit();
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
480 SDL_Quit();
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
481 return(42);
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
482 } /* if */
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
483
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
484 printf("Now playing [%s]...\n", argv[i]);
3fcb23da06ba Made more robust; fixes most sample rate, etc incompatibilities.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
485
168
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
486 if (predecode)
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
487 {
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
488 printf(" predecoding...", argv[i]);
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
489 decoded_bytes = Sound_DecodeAll(sample);
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
490 decoded_ptr = sample->buffer;
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
491 if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
492 {
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
493 fprintf(stderr,
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
494 "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
495 " reason: [%s].\n"
168
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
496 " (playing first %lu bytes of decoded data...)\n",
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
497 argv[i], Sound_GetError(), decoded_bytes);
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
498 } /* if */
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
499 else
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
500 {
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
501 printf("done.\n");
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
502 } /* else */
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
503 } /* if */
87b00f023710 Added --predecode functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
504
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 done_flag = 0;
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 SDL_PauseAudio(0);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 while (!done_flag)
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
508 {
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 SDL_Delay(10);
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
510 } /* while */
58
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 SDL_PauseAudio(1);
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
512
236
034b2e56f405 Fixed some tabs.
Ryan C. Gordon <icculus@icculus.org>
parents: 222
diff changeset
513 /*
034b2e56f405 Fixed some tabs.
Ryan C. Gordon <icculus@icculus.org>
parents: 222
diff changeset
514 * Sleep two buffers' worth of audio before closing, in order
034b2e56f405 Fixed some tabs.
Ryan C. Gordon <icculus@icculus.org>
parents: 222
diff changeset
515 * 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
516 * 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
517 */
034b2e56f405 Fixed some tabs.
Ryan C. Gordon <icculus@icculus.org>
parents: 222
diff changeset
518 delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq;
034b2e56f405 Fixed some tabs.
Ryan C. Gordon <icculus@icculus.org>
parents: 222
diff changeset
519 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
520
146
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
521 if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
522 {
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
523 fprintf(stderr, "Error in decoding sound file!\n"
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
524 " reason: [%s].\n", Sound_GetError());
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
diff changeset
525 } /* if */
023c3e7f028b Cleaned up the overflow buffer hack.
Ryan C. Gordon <icculus@icculus.org>
parents: 144
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 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
528 Sound_FreeSample(sample);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 } /* for */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 Sound_Quit();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532 SDL_Quit();
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 return(0);
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 } /* main */
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535
4a51162099e0 Renamed from test/test_sdlsound.c ... lots of other updates, too.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 /* 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
537