]> git.sesse.net Git - vlc/blob - modules/gui/beos/AudioOutput.cpp
Now BeOS sound is (almost) clean.
[vlc] / modules / gui / beos / AudioOutput.cpp
1 /*****************************************************************************
2  * aout.cpp: BeOS audio output
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: AudioOutput.cpp,v 1.11 2002/10/13 15:39:16 titer Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Eric Petit <titer@videolan.org>
10  *
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.
15  * 
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdio.h>
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <malloc.h>
32 #include <string.h>
33
34 #include <SoundPlayer.h>
35
36 #include <vlc/vlc.h>
37 #include <vlc/aout.h>
38 #include "aout_internal.h"
39
40 #define FRAME_SIZE 2048
41
42 /*****************************************************************************
43  * aout_sys_t: BeOS audio output method descriptor
44  *****************************************************************************/
45
46 typedef struct aout_sys_t
47 {
48     BSoundPlayer *p_player;
49     float *p_buffer;
50     int i_got_data;
51 } aout_sys_t;
52
53 /*****************************************************************************
54  * Local prototypes.
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 );
59
60 /*****************************************************************************
61  * OpenAudio
62  *****************************************************************************/
63 int E_(OpenAudio) ( vlc_object_t * p_this )
64 {
65         aout_instance_t *p_aout = (aout_instance_t*) p_this;
66         p_aout->output.p_sys = (aout_sys_t *) malloc( sizeof( aout_sys_t ) );
67         
68         aout_sys_t *p_sys = p_aout->output.p_sys;
69         p_sys->i_got_data = 0;
70         p_sys->p_buffer = (float*) malloc( 16384 ); /*FIXME*/
71
72     aout_VolumeSoftInit( p_aout );
73     
74     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
75     p_aout->output.i_nb_samples = FRAME_SIZE;
76     p_aout->output.pf_play = DoNothing;
77     p_aout->output.output.i_rate = 44100;
78     p_aout->output.output.i_channels = 2;
79
80     p_sys->p_player = new BSoundPlayer( "player", Play, NULL, p_this );
81     p_sys->p_player->Start();
82     p_sys->p_player->SetHasData( true );
83         
84     return 0;
85 }
86
87 /*****************************************************************************
88  * CloseAudio
89  *****************************************************************************/
90 void E_(CloseAudio) ( vlc_object_t *p_this )
91 {
92     aout_instance_t * p_aout = (aout_instance_t *) p_this;
93     aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
94     
95     p_sys->p_player->Stop();
96     p_aout->b_die = 1;
97     delete p_sys->p_player;
98     free( p_sys );
99 }
100
101 /*****************************************************************************
102  * Play
103  *****************************************************************************/
104 static void Play( void *aout, void *buffer, size_t size,
105                   const media_raw_audio_format &format )
106 {
107     aout_buffer_t * p_aout_buffer;
108     aout_instance_t *p_aout = (aout_instance_t*) aout;
109     aout_sys_t *p_sys = p_aout->output.p_sys;
110
111     float *p_buffer = (float*) buffer;
112
113     /* <kludge> */
114     /* Usually BSoundPlay asks for 8192 bytes buffers, while vlc gives
115     a 16384 one. So we keep the second half of it in p_sys->p_buffer */
116
117     if( p_sys->i_got_data )
118     {
119         memcpy( p_buffer, p_sys->p_buffer, 8192 );
120         p_sys->i_got_data = 0;
121     }
122     else
123     {
124         p_aout_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
125
126         if( p_aout_buffer != NULL )
127         {
128             memcpy( p_buffer,
129                     p_aout_buffer->p_buffer,
130                     8192 );
131             memcpy( p_sys->p_buffer,
132                     p_aout_buffer->p_buffer + 8192,
133                     8192 );
134             p_sys->i_got_data = 1;
135         }
136     }
137     
138     /* </kludge> */
139 }
140
141 /*****************************************************************************
142  * DoNothing 
143  *****************************************************************************/
144 static void DoNothing( aout_instance_t *p_aout)
145 {
146     return;
147 }