@@ -26,6 +26,16 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2626
2727#include "audio.h"
2828
29+ /* Check which version audio library we have: */
30+ #ifdef AL_ERROR_NUMBER
31+ #define AL_405
32+ /* XXXX 4.0.5 libaudio also allows us to provide better error
33+ ** handling (with ALseterrorhandler). We should implement that
34+ ** sometime.
35+ */
36+
37+ #endif
38+
2939#include "allobjects.h"
3040#include "import.h"
3141#include "modsupport.h"
@@ -127,13 +137,65 @@ al_setchannels (self, args)
127137 return (setConfig (self , args , ALsetchannels ));
128138}
129139
140+ #ifdef AL_405
141+
142+ static object *
143+ al_getsampfmt (self , args )
144+ configobject * self ;
145+ object * args ;
146+ {
147+ return (getConfig (self , args , ALgetsampfmt ));
148+ }
149+
150+ static object *
151+ al_setsampfmt (self , args )
152+ configobject * self ;
153+ object * args ;
154+ {
155+ return (setConfig (self , args , ALsetsampfmt ));
156+ }
157+
158+ static object *
159+ al_getfloatmax (self , args )
160+ configobject * self ;
161+ object * args ;
162+ {
163+ double arg ;
164+
165+ if ( !getnoarg (args ) )
166+ return 0 ;
167+ arg = ALgetfloatmax (self -> ob_config );
168+ return newfloatobject (arg );
169+ }
170+
171+ static object *
172+ al_setfloatmax (self , args )
173+ configobject * self ;
174+ object * args ;
175+ {
176+ double arg ;
177+
178+ if ( !getargs (args , "d" , & arg ) )
179+ return 0 ;
180+ ALsetfloatmax (self -> ob_config , arg );
181+ INCREF (None );
182+ return None ;
183+ }
184+ #endif /* AL_405 */
185+
130186static struct methodlist config_methods [] = {
131187 {"getqueuesize" , al_getqueuesize },
132188 {"setqueuesize" , al_setqueuesize },
133189 {"getwidth" , al_getwidth },
134190 {"setwidth" , al_setwidth },
135191 {"getchannels" , al_getchannels },
136192 {"setchannels" , al_setchannels },
193+ #ifdef AL_405
194+ {"getsampfmt" , al_getsampfmt },
195+ {"setsampfmt" , al_setsampfmt },
196+ {"getfloatmax" , al_getfloatmax },
197+ {"setfloatmax" , al_setfloatmax },
198+ #endif /* AL_405 */
137199 {NULL , NULL } /* sentinel */
138200};
139201
@@ -270,7 +332,17 @@ al_readsamps (self, args)
270332 }
271333
272334 c = ALgetconfig (self -> ob_port );
335+ #ifdef AL_405
336+ width = ALgetsampfmt (c );
337+ if ( width == AL_SAMPFMT_FLOAT )
338+ width = sizeof (float );
339+ else if ( width == AL_SAMPFMT_DOUBLE )
340+ width = sizeof (double );
341+ else
342+ width = ALgetwidth (c );
343+ #else
273344 width = ALgetwidth (c );
345+ #endif /* AL_405 */
274346 ALfreeconfig (c );
275347 v = newsizedstringobject ((char * )NULL , width * count );
276348 if (v == NULL ) return NULL ;
@@ -295,7 +367,17 @@ al_writesamps (self, args)
295367 if (!getargs (args , "s#" , & buf , & size )) return NULL ;
296368
297369 c = ALgetconfig (self -> ob_port );
370+ #ifdef AL_405
371+ width = ALgetsampfmt (c );
372+ if ( width == AL_SAMPFMT_FLOAT )
373+ width = sizeof (float );
374+ else if ( width == AL_SAMPFMT_DOUBLE )
375+ width = sizeof (double );
376+ else
377+ width = ALgetwidth (c );
378+ #else
298379 width = ALgetwidth (c );
380+ #endif /* AL_405 */
299381 ALfreeconfig (c );
300382 BGN_SAVE
301383 ALwritesamps (self -> ob_port , (void * ) buf , (long ) size / width );
@@ -363,6 +445,49 @@ al_getconfig (self, args)
363445 return newconfigobject (config );
364446}
365447
448+ #ifdef AL_405
449+ static object *
450+ al_getstatus (self , args )
451+ portobject * self ;
452+ object * args ;
453+ {
454+ object * list , * v ;
455+ long * PVbuffer ;
456+ long length ;
457+ int i ;
458+
459+ if (!getargs (args , "O" , & list ))
460+ return NULL ;
461+ if (!is_listobject (list )) {
462+ err_badarg ();
463+ return NULL ;
464+ }
465+ length = getlistsize (list );
466+ PVbuffer = NEW (long , length );
467+ if (PVbuffer == NULL )
468+ return err_nomem ();
469+ for (i = 0 ; i < length ; i ++ ) {
470+ v = getlistitem (list , i );
471+ if (!is_intobject (v )) {
472+ DEL (PVbuffer );
473+ err_badarg ();
474+ return NULL ;
475+ }
476+ PVbuffer [i ] = getintvalue (v );
477+ }
478+
479+ ALgetstatus (self -> ob_port , PVbuffer , length );
480+
481+ for (i = 0 ; i < length ; i ++ )
482+ setlistitem (list , i , newintobject (PVbuffer [i ]));
483+
484+ DEL (PVbuffer );
485+
486+ INCREF (None );
487+ return None ;
488+ }
489+ #endif /* AL_405 */
490+
366491static struct methodlist port_methods [] = {
367492 {"closeport" , al_closeport },
368493 {"getfd" , al_getfd },
@@ -375,6 +500,9 @@ static struct methodlist port_methods[] = {
375500 {"getfillpoint" , al_getfillpoint },
376501 {"setconfig" , al_setconfig },
377502 {"getconfig" , al_getconfig },
503+ #ifdef AL_405
504+ {"getstatus" , al_getstatus },
505+ #endif /* AL_405 */
378506 {NULL , NULL } /* sentinel */
379507};
380508
0 commit comments