2 * playsound - command line sound file player for Haiku
3 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <FileGameSound.h>
29 volatile bool interrupted
= false;
41 fprintf(stderr
, "playsound - command line sound file player for Haiku\n");
42 fprintf(stderr
, "Usage:\n");
43 fprintf(stderr
, " playsound [--loop] [--gain <value>] [--pan <value>] <filename>\n");
44 fprintf(stderr
, " gain value in percent, can be 0 (silence) to 100 (normal) or higher\n");
45 fprintf(stderr
, " pan value in percent, can be -100 (left) to 100 (right)\n");
50 main(int argc
, char *argv
[])
60 static struct option long_options
[] =
62 {"loop", no_argument
, 0, 'l'},
63 {"gain", required_argument
, 0, 'g'},
64 {"pan", required_argument
, 0, 'p'},
68 c
= getopt_long (argc
, argv
, "lgp:", long_options
, &option_index
);
98 // test if file exists
99 int fd
= open(file
, O_RDONLY
);
101 fprintf(stderr
, "Can't open file %s\n", file
);
106 signal(SIGINT
, keyb_int
);
108 BFileGameSound
snd(file
, loop
);
111 err
= snd
.InitCheck();
113 fprintf(stderr
, "Init failed, error 0x%08lx (%s)\n", err
, strerror(err
));
117 err
= snd
.SetGain(gain
/ 100.0);
119 fprintf(stderr
, "Setting gain failed, error 0x%08lx (%s)\n", err
, strerror(err
));
123 err
= snd
.SetPan(pan
/ 100.0);
125 fprintf(stderr
, "Setting pan failed, error 0x%08lx (%s)\n", err
, strerror(err
));
131 fprintf(stderr
, "Preload failed, error 0x%08lx (%s)\n", err
, strerror(err
));
135 err
= snd
.StartPlaying();
137 fprintf(stderr
, "Start playing failed, error 0x%08lx (%s)\n", err
, strerror(err
));
141 while (snd
.IsPlaying() && !interrupted
)
144 err
= snd
.StopPlaying();
146 fprintf(stderr
, "Stop playing failed, error 0x%08lx (%s)\n", err
, strerror(err
));