1 /*****************************************************************************
2 * aout_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: aout_beos.cpp,v 1.7 2001/01/05 18:46:43 massiot Exp $
8 * Samuel Hocevar <sam@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <kernel/OS.h>
34 #include <Application.h>
37 #include <media/MediaDefs.h>
38 #include <game/PushGameSound.h>
50 #include "audio_output.h"
57 /*****************************************************************************
58 * aout_sys_t: esd audio output method descriptor
59 *****************************************************************************
60 * This structure is part of the audio output thread descriptor.
61 * It describes some esd specific variables.
62 *****************************************************************************/
63 typedef struct aout_sys_s
65 BPushGameSound * p_sound;
66 gs_audio_format * p_format;
76 /*****************************************************************************
77 * aout_BeOpen: opens a BPushGameSound
78 *****************************************************************************/
79 int aout_BeOpen( aout_thread_t *p_aout )
81 /* Allocate structure */
82 p_aout->p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
83 if( p_aout->p_sys == NULL )
85 intf_ErrMsg("error: %s", strerror(ENOMEM) );
89 /* Allocate gs_audio_format */
90 p_aout->p_sys->p_format = (gs_audio_format *) malloc( sizeof( gs_audio_format ) );
91 if( p_aout->p_sys->p_format == NULL )
93 free( p_aout->p_sys );
94 intf_ErrMsg("error: cannot allocate memory for gs_audio_format" );
98 /* Initialize some variables */
99 p_aout->i_format = AOUT_FORMAT_DEFAULT;
100 p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
101 AOUT_STEREO_DEFAULT );
102 p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
104 p_aout->p_sys->p_format->frame_rate = 44100.0;
105 p_aout->p_sys->p_format->channel_count = p_aout->i_channels;
106 p_aout->p_sys->p_format->format = gs_audio_format::B_GS_S16;
107 p_aout->p_sys->p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
108 p_aout->p_sys->p_format->buffer_size = 4*8192;
109 p_aout->p_sys->i_buffer_pos = 0;
111 /* Allocate BPushGameSound */
112 p_aout->p_sys->p_sound = new BPushGameSound( 8192,
113 p_aout->p_sys->p_format,
115 if( p_aout->p_sys->p_sound == NULL )
117 free( p_aout->p_sys->p_format );
118 free( p_aout->p_sys );
119 intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
123 if( p_aout->p_sys->p_sound->InitCheck() != B_OK )
125 free( p_aout->p_sys->p_format );
126 free( p_aout->p_sys );
127 intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
131 p_aout->p_sys->p_sound->StartPlaying( );
133 p_aout->p_sys->p_sound->LockForCyclic( &p_aout->p_sys->p_buffer,
134 (size_t *)&p_aout->p_sys->i_buffer_size );
138 /*****************************************************************************
139 * aout_BeReset: resets the dsp
140 *****************************************************************************/
141 int aout_BeReset( aout_thread_t *p_aout )
146 /*****************************************************************************
147 * aout_BeSetFormat: sets the dsp output format
148 *****************************************************************************/
149 int aout_BeSetFormat( aout_thread_t *p_aout )
154 /*****************************************************************************
155 * aout_BeSetChannels: sets the dsp's stereo or mono mode
156 *****************************************************************************/
157 int aout_BeSetChannels( aout_thread_t *p_aout )
162 /*****************************************************************************
163 * aout_BeSetRate: sets the dsp's audio output rate
164 *****************************************************************************/
165 int aout_BeSetRate( aout_thread_t *p_aout )
170 /*****************************************************************************
171 * aout_BeGetBufInfo: buffer status query
172 *****************************************************************************/
173 long aout_BeGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
175 /* Each value is 4 bytes long (stereo signed 16 bits) */
176 long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
178 i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
181 i_hard_pos += p_aout->p_sys->i_buffer_size;
184 return( i_hard_pos );
187 /*****************************************************************************
188 * aout_BePlaySamples: plays a sound samples buffer
189 *****************************************************************************
190 * This function writes a buffer of i_length bytes in the dsp
191 *****************************************************************************/
192 void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
196 if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
197 > p_aout->p_sys->i_buffer_size )
199 memcpy( (void *)((int)p_aout->p_sys->p_buffer
200 + p_aout->p_sys->i_buffer_pos),
202 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
204 memcpy( (void *)((int)p_aout->p_sys->p_buffer),
205 buffer + p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos,
206 i_size - ( p_aout->p_sys->i_buffer_size
207 - p_aout->p_sys->i_buffer_pos ) );
209 p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
214 memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
217 p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
221 /*****************************************************************************
222 * aout_BeClose: closes the dsp audio device
223 *****************************************************************************/
224 void aout_BeClose( aout_thread_t *p_aout )
226 p_aout->p_sys->p_sound->UnlockCyclic();
227 p_aout->p_sys->p_sound->StopPlaying( );
228 delete p_aout->p_sys->p_sound;
229 free( p_aout->p_sys->p_format );
230 free( p_aout->p_sys );