2
PLAYMUS: A test application for the SDL mixer library.
3
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
/* $Id: playmus.c,v 1.14 2001/12/18 16:43:35 slouken Exp $ */
34
#include "SDL_mixer.h"
37
static int audio_open = 0;
38
static Mix_Music *music = NULL;
39
static int next_track = 0;
43
if( Mix_PlayingMusic() ) {
44
Mix_FadeOutMusic(1500);
58
void Usage(char *argv0)
60
fprintf(stderr, "Usage: %s [-i] |-l] [-8] [-r rate] [-b buffers] [-s] <musicfile>\n", argv0);
67
printf("Available commands: (p)ause (r)esume (h)alt > ");
81
printf("Music playing: %s Paused: %s\n", Mix_PlayingMusic() ? "yes" : "no",
82
Mix_PausedMusic() ? "yes" : "no");
85
void IntHandler(int sig)
94
int main(int argc, char *argv[])
104
/* Initialize variables */
106
audio_format = AUDIO_S16;
108
audio_buffers = 4096;
110
/* Check command line usage */
111
for ( i=1; argv[i] && (*argv[i] == '-'); ++i ) {
112
if ( (strcmp(argv[i], "-r") == 0) && argv[i+1] ) {
114
audio_rate = atoi(argv[i]);
116
if ( (strcmp(argv[i], "-b") == 0) && argv[i+1] ) {
118
audio_buffers = atoi(argv[i]);
120
if ( strcmp(argv[i], "-m") == 0 ) {
123
if ( strcmp(argv[i], "-l") == 0 ) {
126
if ( strcmp(argv[i], "-i") == 0 ) {
129
if ( strcmp(argv[i], "-8") == 0 ) {
130
audio_format = AUDIO_U8;
141
/* Initialize the SDL library */
142
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
143
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
147
signal(SIGINT, IntHandler);
148
signal(SIGTERM, exit);
150
/* Open the audio device */
151
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
152
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
155
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
156
printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
158
(audio_channels > 1) ? "stereo" : "mono",
163
/* Set the external music player, if any */
164
Mix_SetMusicCMD(getenv("MUSIC_CMD"));
169
/* Load the requested music file */
170
music = Mix_LoadMUS(argv[i]);
171
if ( music == NULL ) {
172
fprintf(stderr, "Couldn't load %s: %s\n",
173
argv[i], SDL_GetError());
177
/* Play and then exit */
178
printf("Playing %s\n", argv[i]);
179
Mix_FadeInMusic(music,looping,2000);
180
while ( !next_track && Mix_PlayingMusic() || Mix_PausedMusic() ) {
186
Mix_FreeMusic(music);
189
/* If the user presses Ctrl-C more than once, exit. */
191
if ( next_track > 1 ) break;