2
** Copyright (C) 2001 Marcus Overhagen <marcus@overhagen.de>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU General Public License as published by
6
** the Free Software Foundation; either version 2 of the License, or
7
** (at your option) any later version.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <Application.h>
22
#include <SoundPlayer.h>
27
#define BUFFER_LEN 1024
29
/*------------------------------------------------------------------------------
30
** BeOS functions for playing a sound.
33
#if defined (__BEOS__)
44
buffer_callback(void *theCookie, void *buf, size_t size, const media_raw_audio_format &format)
46
shared_data *data = (shared_data *)theCookie;
47
short *buffer = (short *)buf;
48
int count = size / sizeof(short);
51
if (!data->player->HasData())
54
readcount = sf_read_short(data->sndfile, buffer, count);
56
{ data->player->SetHasData(false);
57
release_sem(data->finished);
59
if (readcount < count)
60
{ for (m = readcount ; m < count ; m++)
63
if (data->sfinfo.pcmbitwidth < 16)
64
{ for (m = 0 ; m < count ; m++)
70
beos_play (int argc, char *argv [])
76
/* BSoundPlayer requires a BApplication object */
77
BApplication app("application/x-vnd.MarcusOverhagen-sfplay");
79
for (k = 1 ; k < argc ; k++)
80
{ printf ("Playing %s\n", argv [k]) ;
81
if (! (data.sndfile = sf_open_read (argv [k], &data.sfinfo)))
86
if (data.sfinfo.channels < 1 || data.sfinfo.channels > 2)
87
{ printf ("Error : channels = %d.\n", data.sfinfo.channels) ;
88
sf_close (data.sndfile) ;
92
data.finished = create_sem(0,"finished");
94
media_raw_audio_format format =
95
{ data.sfinfo.samplerate,
97
media_raw_audio_format::B_AUDIO_SHORT,
98
B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN,
99
BUFFER_LEN * sizeof(short)
102
BSoundPlayer player(&format,"player",buffer_callback,NULL,&data);
103
data.player = &player;
105
if ((status = player.InitCheck()) != B_OK)
107
printf ("Error : BSoundPlayer init failed, %s.\n", strerror(status)) ;
108
delete_sem(data.finished);
109
sf_close (data.sndfile) ;
113
player.SetVolume(1.0);
115
player.SetHasData(true);
116
acquire_sem(data.finished);
118
delete_sem(data.finished);
120
sf_close (data.sndfile) ;
128
/*==============================================================================
133
main (int argc, char *argv [])
136
{ printf ("Usage : %s <input sound file>\n\n", argv [0]) ;
140
beos_play (argc, argv) ;