1 /*****************************************************************************
2 * aout.cpp: BeOS audio output
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: AudioOutput.cpp,v 1.13 2002/10/21 20:00:09 massiot Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Eric Petit <titer@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
34 #include <SoundPlayer.h>
35 #include <media/MediaDefs.h>
39 #include "aout_internal.h"
41 #define FRAME_SIZE 2048
43 /*****************************************************************************
44 * aout_sys_t: BeOS audio output method descriptor
45 *****************************************************************************/
47 typedef struct aout_sys_t
49 BSoundPlayer *p_player;
53 /*****************************************************************************
55 *****************************************************************************/
56 static void Play ( void *p_aout, void *p_buffer, size_t size,
57 const media_raw_audio_format &format );
58 static void DoNothing ( aout_instance_t *p_aout );
60 /*****************************************************************************
62 *****************************************************************************/
63 int E_(OpenAudio) ( vlc_object_t * p_this )
66 aout_instance_t *p_aout = (aout_instance_t*) p_this;
67 p_aout->output.p_sys = (aout_sys_t *) malloc( sizeof( aout_sys_t ) );
69 aout_sys_t *p_sys = p_aout->output.p_sys;
71 aout_VolumeSoftInit( p_aout );
73 media_raw_audio_format *p_format;
74 p_format = (media_raw_audio_format*)
75 malloc( sizeof( media_raw_audio_format ) );
77 p_format->frame_rate = p_aout->output.output.i_rate;
79 i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
80 if ( i_nb_channels > 2 )
82 /* I don't know if BeOS supports more than two channels. --Meuuh */
84 p_aout->output.output.i_channels = AOUT_CHAN_STEREO;
86 p_format->channel_count = i_nb_channels;
88 p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
89 #ifdef WORDS_BIGENDIAN
90 p_format->byte_order = B_MEDIA_BIG_ENDIAN;
92 p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
94 p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
96 p_format->buffer_size = 16384;
97 p_aout->output.i_nb_samples = FRAME_SIZE;
98 p_aout->output.pf_play = DoNothing;
100 p_sys->p_player = new BSoundPlayer( p_format, "player",
101 Play, NULL, p_this );
102 p_sys->p_player->Start();
103 p_sys->p_player->SetHasData( true );
108 /*****************************************************************************
110 *****************************************************************************/
111 void E_(CloseAudio) ( vlc_object_t *p_this )
113 aout_instance_t * p_aout = (aout_instance_t *) p_this;
114 aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
116 p_sys->p_player->Stop();
117 delete p_sys->p_player;
121 /*****************************************************************************
123 *****************************************************************************/
124 static void Play( void *aout, void *buffer, size_t size,
125 const media_raw_audio_format &format )
127 aout_buffer_t * p_aout_buffer;
128 aout_instance_t *p_aout = (aout_instance_t*) aout;
130 float *p_buffer = (float*) buffer;
132 p_aout_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
134 if( p_aout_buffer != NULL )
137 p_aout_buffer->p_buffer,
138 MIN( size, p_aout_buffer->i_nb_bytes ) );
142 /*****************************************************************************
144 *****************************************************************************/
145 static void DoNothing( aout_instance_t *p_aout)