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\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;
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\n" );
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\n" );
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 )
177 long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
179 /*fprintf( stderr, "read 0x%.6lx - write 0x%.6lx = ",
180 i_hard_pos, p_aout->p_sys->i_buffer_pos );*/
182 if( i_hard_pos < p_aout->p_sys->i_buffer_pos )
184 i_hard_pos += p_aout->p_sys->i_buffer_size;
187 /*fprintf( stderr, "0x%.6lx\n", i_hard_pos - p_aout->p_sys->i_buffer_pos ); */
189 return( (p_aout->p_sys->i_buffer_size - (i_hard_pos - p_aout->p_sys->i_buffer_pos)) );
192 /*****************************************************************************
193 * aout_BePlaySamples: plays a sound samples buffer
194 *****************************************************************************
195 * This function writes a buffer of i_length bytes in the dsp
196 *****************************************************************************/
197 void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
201 //fprintf( stderr, "writing %i\n", i_size );
203 if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
204 > p_aout->p_sys->i_buffer_size )
206 memcpy( (void *)((int)p_aout->p_sys->p_buffer
207 + p_aout->p_sys->i_buffer_pos),
209 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
211 memcpy( (void *)((int)p_aout->p_sys->p_buffer),
213 i_size - ( p_aout->p_sys->i_buffer_size
214 - p_aout->p_sys->i_buffer_pos ) );
216 p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
220 memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
222 p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
226 /*****************************************************************************
227 * aout_BeClose: closes the dsp audio device
228 *****************************************************************************/
229 void aout_BeClose( aout_thread_t *p_aout )
231 p_aout->p_sys->p_sound->UnlockCyclic();
232 p_aout->p_sys->p_sound->StopPlaying( );
233 delete p_aout->p_sys->p_sound;
234 free( p_aout->p_sys->p_format );
235 free( p_aout->p_sys );