]> git.sesse.net Git - vlc/blob - plugins/beos/aout_beos.cpp
Move #define from audio_output.h to config.h
[vlc] / plugins / beos / aout_beos.cpp
1 /*****************************************************************************
2  * aout_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  * Samuel Hocevar <sam@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "defs.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h>                                            /* "input.h" */
33 #include <kernel/OS.h>
34 #include <View.h>
35 #include <Application.h>
36 #include <Message.h>
37 #include <Locker.h>
38 #include <media/MediaDefs.h>
39 #include <game/PushGameSound.h>
40 #include <malloc.h>
41 #include <string.h>
42
43 extern "C"
44 {
45 #include "config.h"
46 #include "common.h"
47 #include "threads.h"
48 #include "mtime.h"
49 #include "plugins.h"
50
51 #include "audio_output.h"
52
53 #include "intf_msg.h"
54
55 #include "main.h"
56 }
57
58 /*****************************************************************************
59  * aout_sys_t: esd audio output method descriptor
60  *****************************************************************************
61  * This structure is part of the audio output thread descriptor.
62  * It describes some esd specific variables.
63  *****************************************************************************/
64 typedef struct aout_sys_s
65 {
66     BPushGameSound * p_sound;
67     gs_audio_format * p_format;
68     void * p_buffer;
69     long i_buffer_size;
70     long i_buffer_pos;
71
72 } aout_sys_t;
73
74 extern "C"
75 {
76
77 /*****************************************************************************
78  * aout_BeOpen: opens a BPushGameSound
79  *****************************************************************************/
80 int aout_BeOpen( aout_thread_t *p_aout )
81 {
82     /* Allocate structure */
83     p_aout->p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
84     if( p_aout->p_sys == NULL )
85     {
86         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
87         return( 1 );
88     }
89
90     /* Allocate gs_audio_format */
91     p_aout->p_sys->p_format = (gs_audio_format *) malloc( sizeof( gs_audio_format ) );
92     if( p_aout->p_sys->p_format == NULL )
93     {
94         free( p_aout->p_sys );
95         intf_ErrMsg("error: cannot allocate memory for gs_audio_format\n" );
96         return( 1 );
97     }
98
99     /* Initialize some variables */
100     p_aout->i_format = AOUT_FORMAT_DEFAULT;
101     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
102                                                   AOUT_STEREO_DEFAULT );
103     p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
104
105     p_aout->p_sys->p_format->frame_rate = 44100.0;
106     p_aout->p_sys->p_format->channel_count = p_aout->i_channels;
107     p_aout->p_sys->p_format->format = gs_audio_format::B_GS_S16;
108     p_aout->p_sys->p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
109     p_aout->p_sys->p_format->buffer_size = 4*8192;
110     p_aout->p_sys->i_buffer_pos = 0;
111
112     /* Allocate BPushGameSound */
113     p_aout->p_sys->p_sound = new BPushGameSound( 8192,
114                                                  p_aout->p_sys->p_format,
115                                                  2, NULL );
116     if( p_aout->p_sys->p_sound == NULL )
117     {
118         free( p_aout->p_sys->p_format );
119         free( p_aout->p_sys );
120         intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
121         return( 1 );
122     }
123
124     if( p_aout->p_sys->p_sound->InitCheck() != B_OK )
125     {
126         free( p_aout->p_sys->p_format );
127         free( p_aout->p_sys );
128         intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
129         return( 1 );
130     }
131
132     p_aout->p_sys->p_sound->StartPlaying( );
133
134     p_aout->p_sys->p_sound->LockForCyclic( &p_aout->p_sys->p_buffer,
135                             (size_t *)&p_aout->p_sys->i_buffer_size );
136
137     return( 0 );
138 }
139 /*****************************************************************************
140  * aout_BeReset: resets the dsp
141  *****************************************************************************/
142 int aout_BeReset( aout_thread_t *p_aout )
143 {
144     return( 0 );
145 }
146
147 /*****************************************************************************
148  * aout_BeSetFormat: sets the dsp output format
149  *****************************************************************************/
150 int aout_BeSetFormat( aout_thread_t *p_aout )
151 {
152     return( 0 );
153 }
154
155 /*****************************************************************************
156  * aout_BeSetChannels: sets the dsp's stereo or mono mode
157  *****************************************************************************/
158 int aout_BeSetChannels( aout_thread_t *p_aout )
159 {
160     return( 0 );
161 }
162
163 /*****************************************************************************
164  * aout_BeSetRate: sets the dsp's audio output rate
165  *****************************************************************************/
166 int aout_BeSetRate( aout_thread_t *p_aout )
167 {
168     return( 0 );
169 }
170
171 /*****************************************************************************
172  * aout_BeGetBufInfo: buffer status query
173  *****************************************************************************/
174 long aout_BeGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
175 {
176     /* Each value is 4 bytes long (stereo signed 16 bits) */
177     long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
178
179     i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
180     if( i_hard_pos < 0 )
181     {
182          i_hard_pos += p_aout->p_sys->i_buffer_size;
183     }
184
185     return( i_hard_pos );
186 }
187
188 /*****************************************************************************
189  * aout_BePlaySamples: plays a sound samples buffer
190  *****************************************************************************
191  * This function writes a buffer of i_length bytes in the dsp
192  *****************************************************************************/
193 void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
194 {
195     long i_newbuf_pos;
196
197     if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
198               > p_aout->p_sys->i_buffer_size )
199     {
200         memcpy( (void *)((int)p_aout->p_sys->p_buffer
201                         + p_aout->p_sys->i_buffer_pos),
202                 buffer,
203                 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
204
205         memcpy( (void *)((int)p_aout->p_sys->p_buffer),
206                 buffer + p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos,
207                 i_size - ( p_aout->p_sys->i_buffer_size
208                              - p_aout->p_sys->i_buffer_pos ) );
209         
210         p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
211
212     }
213     else
214     {
215         memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
216                 buffer, i_size );
217
218         p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
219     }
220 }
221
222 /*****************************************************************************
223  * aout_BeClose: closes the dsp audio device
224  *****************************************************************************/
225 void aout_BeClose( aout_thread_t *p_aout )
226 {
227     p_aout->p_sys->p_sound->UnlockCyclic();
228     p_aout->p_sys->p_sound->StopPlaying( );
229     delete p_aout->p_sys->p_sound;
230     free( p_aout->p_sys->p_format );
231     free( p_aout->p_sys );
232 }
233
234 } /* extern "C" */
235