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_SysOpen: opens a BPushGameSound
79 *****************************************************************************/
80 int aout_SysOpen( 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\n", 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\n" );
99 /* Initialize some variables */
100 p_aout->i_format = AOUT_DEFAULT_FORMAT;
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 = 8192;
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\n" );
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\n" );
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_SysReset: resets the dsp
140 *****************************************************************************/
141 int aout_SysReset( aout_thread_t *p_aout )
146 /*****************************************************************************
147 * aout_SysSetFormat: sets the dsp output format
148 *****************************************************************************/
149 int aout_SysSetFormat( aout_thread_t *p_aout )
154 /*****************************************************************************
155 * aout_SysSetChannels: sets the dsp's stereo or mono mode
156 *****************************************************************************/
157 int aout_SysSetChannels( aout_thread_t *p_aout )
162 /*****************************************************************************
163 * aout_SysSetRate: sets the dsp's audio output rate
164 *****************************************************************************/
165 int aout_SysSetRate( aout_thread_t *p_aout )
170 /*****************************************************************************
171 * aout_SysGetBufInfo: buffer status query
172 *****************************************************************************/
173 long aout_SysGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
176 long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
178 /*fprintf( stderr, "read 0x%.6lx - write 0x%.6lx = ",
179 i_hard_pos, p_aout->p_sys->i_buffer_pos );*/
181 if( i_hard_pos < p_aout->p_sys->i_buffer_pos )
183 i_hard_pos += p_aout->p_sys->i_buffer_size;
186 /*fprintf( stderr, "0x%.6lx\n", i_hard_pos - p_aout->p_sys->i_buffer_pos ); */
188 return( (p_aout->p_sys->i_buffer_size - (i_hard_pos - p_aout->p_sys->i_buffer_pos)) );
191 /*****************************************************************************
192 * aout_SysPlaySamples: plays a sound samples buffer
193 *****************************************************************************
194 * This function writes a buffer of i_length bytes in the dsp
195 *****************************************************************************/
196 void aout_SysPlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
200 //fprintf( stderr, "writing %i\n", i_size );
202 if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
203 > p_aout->p_sys->i_buffer_size )
205 memcpy( (void *)((int)p_aout->p_sys->p_buffer
206 + p_aout->p_sys->i_buffer_pos),
208 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
210 memcpy( (void *)((int)p_aout->p_sys->p_buffer),
212 i_size - ( p_aout->p_sys->i_buffer_size
213 - p_aout->p_sys->i_buffer_pos ) );
215 p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
219 memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
221 p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
225 /*****************************************************************************
226 * aout_SysClose: closes the dsp audio device
227 *****************************************************************************/
228 void aout_SysClose( aout_thread_t *p_aout )
230 p_aout->p_sys->p_sound->UnlockCyclic();
231 p_aout->p_sys->p_sound->StopPlaying( );
232 delete p_aout->p_sys->p_sound;
233 free( p_aout->p_sys->p_format );
234 free( p_aout->p_sys );