1 /*****************************************************************************
2 * AudioOutput.cpp: BeOS audio output
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: AudioOutput.cpp,v 1.25 2003/01/08 15:13:32 titer 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>
41 #include <aout_internal.h>
44 /*****************************************************************************
45 * aout_sys_t: BeOS audio output method descriptor
46 *****************************************************************************/
48 typedef struct aout_sys_t
50 BSoundPlayer *p_player;
54 /*****************************************************************************
56 *****************************************************************************/
57 static void Play ( void *p_aout, void *p_buffer, size_t size,
58 const media_raw_audio_format &format );
59 static void DoNothing ( aout_instance_t *p_aout );
61 /*****************************************************************************
63 *****************************************************************************/
64 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 ) );
68 if( p_aout->output.p_sys == NULL )
70 msg_Err( p_aout, "Not enough memory" );
73 aout_sys_t *p_sys = p_aout->output.p_sys;
75 aout_VolumeSoftInit( p_aout );
77 int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
78 if ( i_nb_channels > 2 )
80 /* BSoundPlayer does not support more than 2 channels AFAIK */
82 p_aout->output.output.i_physical_channels
83 = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
86 media_raw_audio_format *p_format;
87 p_format = (media_raw_audio_format*)
88 malloc( sizeof( media_raw_audio_format ) );
90 p_format->channel_count = i_nb_channels;
91 p_format->frame_rate = p_aout->output.output.i_rate;
92 p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
93 #ifdef WORDS_BIGENDIAN
94 p_format->byte_order = B_MEDIA_BIG_ENDIAN;
96 p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
98 p_format->buffer_size = 8192;
100 p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
101 p_aout->output.i_nb_samples = 2048 / i_nb_channels;
102 p_aout->output.pf_play = DoNothing;
104 p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
105 if( p_sys->p_player->InitCheck() != B_OK )
107 msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
108 delete p_sys->p_player;
113 p_sys->p_player->Start();
114 p_sys->p_player->SetHasData( true );
119 /*****************************************************************************
121 *****************************************************************************/
122 void E_(CloseAudio) ( vlc_object_t *p_this )
124 aout_instance_t * p_aout = (aout_instance_t *) p_this;
125 aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
127 p_sys->p_player->Stop();
128 delete p_sys->p_player;
132 /*****************************************************************************
134 *****************************************************************************/
135 static void Play( void *aout, void *p_buffer, size_t i_size,
136 const media_raw_audio_format &format )
138 aout_instance_t *p_aout = (aout_instance_t*)aout;
139 aout_sys_t *p_sys = (aout_sys_t*)p_aout->output.p_sys;
140 aout_buffer_t * p_aout_buffer;
141 mtime_t current_date;
143 /* FIXME - I don't know the right way to calculate this */
144 current_date = mdate() + 50000;
146 p_aout_buffer = aout_OutputNextBuffer( p_aout, current_date, VLC_FALSE );
148 if( p_aout_buffer != NULL )
150 p_aout->p_vlc->pf_memcpy( (float*)p_buffer,
151 p_aout_buffer->p_buffer, i_size );
152 aout_BufferFree( p_aout_buffer );
156 p_aout->p_vlc->pf_memset( (float*)p_buffer, 0, i_size );
160 /*****************************************************************************
162 *****************************************************************************/
163 static void DoNothing( aout_instance_t *p_aout)