mirror of https://github.com/python/cpython
Added new audio library functionality (getstatus, float sample fmts)
This commit is contained in:
parent
38a22baea9
commit
e8a3c28f8d
|
@ -6,6 +6,10 @@ RATE_16000 = 16000
|
|||
RATE_11025 = 11025
|
||||
RATE_8000 = 8000
|
||||
|
||||
SAMPFMT_TWOSCOMP= 1
|
||||
SAMPFMT_FLOAT = 32
|
||||
SAMPFMT_DOUBLE = 64
|
||||
|
||||
SAMPLE_8 = 1
|
||||
SAMPLE_16 = 2
|
||||
# SAMPLE_24 is the low 24 bits of a long, sign extended to 32 bits
|
||||
|
@ -18,8 +22,21 @@ INPUT_LINE = 0
|
|||
INPUT_MIC = 1
|
||||
INPUT_DIGITAL = 2
|
||||
|
||||
HOLD, RELEASE = 0, 1
|
||||
ATTAIL, ATHEAD, ATMARK, ATTIME = 0, 1, 2, 3
|
||||
MONITOR_OFF = 0
|
||||
MONITOR_ON = 1
|
||||
|
||||
ERROR_NUMBER = 0
|
||||
ERROR_TYPE = 1
|
||||
ERROR_LOCATION_LSP = 2
|
||||
ERROR_LOCATION_MSP = 3
|
||||
ERROR_LENGTH = 4
|
||||
|
||||
ERROR_INPUT_UNDERFLOW = 0
|
||||
ERROR_OUTPUT_OVERFLOW = 1
|
||||
|
||||
# These seem to be not supported anymore:
|
||||
##HOLD, RELEASE = 0, 1
|
||||
##ATTAIL, ATHEAD, ATMARK, ATTIME = 0, 1, 2, 3
|
||||
|
||||
DEFAULT_DEVICE = 1
|
||||
|
||||
|
@ -35,6 +52,9 @@ OUTPUT_COUNT = 8
|
|||
UNUSED_COUNT = 9
|
||||
SYNC_INPUT_TO_AES = 10
|
||||
SYNC_OUTPUT_TO_AES = 11
|
||||
MONITOR_CTL = 12
|
||||
LEFT_MONITOR_ATTEN = 13
|
||||
RIGHT_MONITOR_ATTEN = 14
|
||||
|
||||
ENUM_VALUE = 0 # only certain values are valid
|
||||
RANGE_VALUE = 1 # any value in range is valid
|
||||
|
|
|
@ -6,6 +6,10 @@ RATE_16000 = 16000
|
|||
RATE_11025 = 11025
|
||||
RATE_8000 = 8000
|
||||
|
||||
SAMPFMT_TWOSCOMP= 1
|
||||
SAMPFMT_FLOAT = 32
|
||||
SAMPFMT_DOUBLE = 64
|
||||
|
||||
SAMPLE_8 = 1
|
||||
SAMPLE_16 = 2
|
||||
# SAMPLE_24 is the low 24 bits of a long, sign extended to 32 bits
|
||||
|
@ -18,8 +22,21 @@ INPUT_LINE = 0
|
|||
INPUT_MIC = 1
|
||||
INPUT_DIGITAL = 2
|
||||
|
||||
HOLD, RELEASE = 0, 1
|
||||
ATTAIL, ATHEAD, ATMARK, ATTIME = 0, 1, 2, 3
|
||||
MONITOR_OFF = 0
|
||||
MONITOR_ON = 1
|
||||
|
||||
ERROR_NUMBER = 0
|
||||
ERROR_TYPE = 1
|
||||
ERROR_LOCATION_LSP = 2
|
||||
ERROR_LOCATION_MSP = 3
|
||||
ERROR_LENGTH = 4
|
||||
|
||||
ERROR_INPUT_UNDERFLOW = 0
|
||||
ERROR_OUTPUT_OVERFLOW = 1
|
||||
|
||||
# These seem to be not supported anymore:
|
||||
##HOLD, RELEASE = 0, 1
|
||||
##ATTAIL, ATHEAD, ATMARK, ATTIME = 0, 1, 2, 3
|
||||
|
||||
DEFAULT_DEVICE = 1
|
||||
|
||||
|
@ -35,6 +52,9 @@ OUTPUT_COUNT = 8
|
|||
UNUSED_COUNT = 9
|
||||
SYNC_INPUT_TO_AES = 10
|
||||
SYNC_OUTPUT_TO_AES = 11
|
||||
MONITOR_CTL = 12
|
||||
LEFT_MONITOR_ATTEN = 13
|
||||
RIGHT_MONITOR_ATTEN = 14
|
||||
|
||||
ENUM_VALUE = 0 # only certain values are valid
|
||||
RANGE_VALUE = 1 # any value in range is valid
|
||||
|
|
|
@ -26,6 +26,16 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include "audio.h"
|
||||
|
||||
/* Check which version audio library we have: */
|
||||
#ifdef AL_ERROR_NUMBER
|
||||
#define AL_405
|
||||
/* XXXX 4.0.5 libaudio also allows us to provide better error
|
||||
** handling (with ALseterrorhandler). We should implement that
|
||||
** sometime.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
#include "allobjects.h"
|
||||
#include "import.h"
|
||||
#include "modsupport.h"
|
||||
|
@ -127,6 +137,52 @@ al_setchannels (self, args)
|
|||
return (setConfig (self, args, ALsetchannels));
|
||||
}
|
||||
|
||||
#ifdef AL_405
|
||||
|
||||
static object *
|
||||
al_getsampfmt (self, args)
|
||||
configobject *self;
|
||||
object *args;
|
||||
{
|
||||
return (getConfig (self, args, ALgetsampfmt));
|
||||
}
|
||||
|
||||
static object *
|
||||
al_setsampfmt (self, args)
|
||||
configobject *self;
|
||||
object *args;
|
||||
{
|
||||
return (setConfig (self, args, ALsetsampfmt));
|
||||
}
|
||||
|
||||
static object *
|
||||
al_getfloatmax(self, args)
|
||||
configobject *self;
|
||||
object *args;
|
||||
{
|
||||
double arg;
|
||||
|
||||
if ( !getnoarg(args) )
|
||||
return 0;
|
||||
arg = ALgetfloatmax(self->ob_config);
|
||||
return newfloatobject(arg);
|
||||
}
|
||||
|
||||
static object *
|
||||
al_setfloatmax(self, args)
|
||||
configobject *self;
|
||||
object *args;
|
||||
{
|
||||
double arg;
|
||||
|
||||
if ( !getargs(args, "d", &arg) )
|
||||
return 0;
|
||||
ALsetfloatmax(self->ob_config, arg);
|
||||
INCREF(None);
|
||||
return None;
|
||||
}
|
||||
#endif /* AL_405 */
|
||||
|
||||
static struct methodlist config_methods[] = {
|
||||
{"getqueuesize", al_getqueuesize},
|
||||
{"setqueuesize", al_setqueuesize},
|
||||
|
@ -134,6 +190,12 @@ static struct methodlist config_methods[] = {
|
|||
{"setwidth", al_setwidth},
|
||||
{"getchannels", al_getchannels},
|
||||
{"setchannels", al_setchannels},
|
||||
#ifdef AL_405
|
||||
{"getsampfmt", al_getsampfmt},
|
||||
{"setsampfmt", al_setsampfmt},
|
||||
{"getfloatmax", al_getfloatmax},
|
||||
{"setfloatmax", al_setfloatmax},
|
||||
#endif /* AL_405 */
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
@ -270,7 +332,17 @@ al_readsamps (self, args)
|
|||
}
|
||||
|
||||
c = ALgetconfig(self->ob_port);
|
||||
#ifdef AL_405
|
||||
width = ALgetsampfmt(c);
|
||||
if ( width == AL_SAMPFMT_FLOAT )
|
||||
width = sizeof(float);
|
||||
else if ( width == AL_SAMPFMT_DOUBLE )
|
||||
width = sizeof(double);
|
||||
else
|
||||
width = ALgetwidth(c);
|
||||
#else
|
||||
width = ALgetwidth(c);
|
||||
#endif /* AL_405 */
|
||||
ALfreeconfig(c);
|
||||
v = newsizedstringobject ((char *)NULL, width * count);
|
||||
if (v == NULL) return NULL;
|
||||
|
@ -295,7 +367,17 @@ al_writesamps (self, args)
|
|||
if (!getargs (args, "s#", &buf, &size)) return NULL;
|
||||
|
||||
c = ALgetconfig(self->ob_port);
|
||||
#ifdef AL_405
|
||||
width = ALgetsampfmt(c);
|
||||
if ( width == AL_SAMPFMT_FLOAT )
|
||||
width = sizeof(float);
|
||||
else if ( width == AL_SAMPFMT_DOUBLE )
|
||||
width = sizeof(double);
|
||||
else
|
||||
width = ALgetwidth(c);
|
||||
#else
|
||||
width = ALgetwidth(c);
|
||||
#endif /* AL_405 */
|
||||
ALfreeconfig(c);
|
||||
BGN_SAVE
|
||||
ALwritesamps (self-> ob_port, (void *) buf, (long) size / width);
|
||||
|
@ -363,6 +445,49 @@ al_getconfig (self, args)
|
|||
return newconfigobject (config);
|
||||
}
|
||||
|
||||
#ifdef AL_405
|
||||
static object *
|
||||
al_getstatus (self, args)
|
||||
portobject *self;
|
||||
object *args;
|
||||
{
|
||||
object *list, *v;
|
||||
long *PVbuffer;
|
||||
long length;
|
||||
int i;
|
||||
|
||||
if (!getargs(args, "O", &list))
|
||||
return NULL;
|
||||
if (!is_listobject(list)) {
|
||||
err_badarg();
|
||||
return NULL;
|
||||
}
|
||||
length = getlistsize(list);
|
||||
PVbuffer = NEW(long, length);
|
||||
if (PVbuffer == NULL)
|
||||
return err_nomem();
|
||||
for (i = 0; i < length; i++) {
|
||||
v = getlistitem(list, i);
|
||||
if (!is_intobject(v)) {
|
||||
DEL(PVbuffer);
|
||||
err_badarg();
|
||||
return NULL;
|
||||
}
|
||||
PVbuffer[i] = getintvalue(v);
|
||||
}
|
||||
|
||||
ALgetstatus(self->ob_port, PVbuffer, length);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
setlistitem(list, i, newintobject(PVbuffer[i]));
|
||||
|
||||
DEL(PVbuffer);
|
||||
|
||||
INCREF(None);
|
||||
return None;
|
||||
}
|
||||
#endif /* AL_405 */
|
||||
|
||||
static struct methodlist port_methods[] = {
|
||||
{"closeport", al_closeport},
|
||||
{"getfd", al_getfd},
|
||||
|
@ -375,6 +500,9 @@ static struct methodlist port_methods[] = {
|
|||
{"getfillpoint", al_getfillpoint},
|
||||
{"setconfig", al_setconfig},
|
||||
{"getconfig", al_getconfig},
|
||||
#ifdef AL_405
|
||||
{"getstatus", al_getstatus},
|
||||
#endif /* AL_405 */
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue