1 /*****************************************************************************
2 * aout_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
7 * Samuel Hocevar <sam@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
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>
35 #include <Application.h>
38 #include <media/MediaDefs.h>
39 #include <game/PushGameSound.h>
51 #include "audio_output.h"
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
66 BPushGameSound * p_sound;
67 gs_audio_format * p_format;
77 /*****************************************************************************
78 * aout_BeOpen: opens a BPushGameSound
79 *****************************************************************************/
80 int aout_BeOpen( aout_thread_t *p_aout )
82 /* Allocate structure */
83 p_aout->p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
84 if( p_aout->p_sys == NULL )
86 intf_ErrMsg("error: %s", strerror(ENOMEM) );
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 )
94 free( p_aout->p_sys );
95 intf_ErrMsg("error: cannot allocate memory for gs_audio_format" );
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 );
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;
112 /* Allocate BPushGameSound */
113 p_aout->p_sys->p_sound = new BPushGameSound( 8192,
114 p_aout->p_sys->p_format,
116 if( p_aout->p_sys->p_sound == NULL )
118 free( p_aout->p_sys->p_format );
119 free( p_aout->p_sys );
120 intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
124 if( p_aout->p_sys->p_sound->InitCheck() != B_OK )
126 free( p_aout->p_sys->p_format );
127 free( p_aout->p_sys );
128 intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
132 p_aout->p_sys->p_sound->StartPlaying( );
134 p_aout->p_sys->p_sound->LockForCyclic( &p_aout->p_sys->p_buffer,
135 (size_t *)&p_aout->p_sys->i_buffer_size );
139 /*****************************************************************************
140 * aout_BeReset: resets the dsp
141 *****************************************************************************/
142 int aout_BeReset( aout_thread_t *p_aout )
147 /*****************************************************************************
148 * aout_BeSetFormat: sets the dsp output format
149 *****************************************************************************/
150 int aout_BeSetFormat( aout_thread_t *p_aout )
155 /*****************************************************************************
156 * aout_BeSetChannels: sets the dsp's stereo or mono mode
157 *****************************************************************************/
158 int aout_BeSetChannels( aout_thread_t *p_aout )
163 /*****************************************************************************
164 * aout_BeSetRate: sets the dsp's audio output rate
165 *****************************************************************************/
166 int aout_BeSetRate( aout_thread_t *p_aout )
171 /*****************************************************************************
172 * aout_BeGetBufInfo: buffer status query
173 *****************************************************************************/
174 long aout_BeGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
176 /* Each value is 4 bytes long (stereo signed 16 bits) */
177 long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
179 i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
182 i_hard_pos += p_aout->p_sys->i_buffer_size;
185 return( i_hard_pos );
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 )
197 if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
198 > p_aout->p_sys->i_buffer_size )
200 memcpy( (void *)((int)p_aout->p_sys->p_buffer
201 + p_aout->p_sys->i_buffer_pos),
203 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
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 ) );
210 p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
215 memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
218 p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
222 /*****************************************************************************
223 * aout_BeClose: closes the dsp audio device
224 *****************************************************************************/
225 void aout_BeClose( aout_thread_t *p_aout )
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 );