Пример #1
0
ALboolean alCaptureInit_EXT( UNUSED(ALenum format),
                             UNUSED(ALuint rate),
                             UNUSED(ALsizei bufferSize) )
{
	ALuint cid;
	AL_context *cc;
	AL_device *capture_device;

	/* get the current context */
	capture_device = NULL;
	cid = _alcCCId;
	_alcLockContext( cid );
	cc = _alcGetContext(cid);
	if ( cc != NULL ) {
		capture_device = cc->read_device;
		if ( capture_device == NULL ) {
			char spec[1024];
			char *fmt="'( (direction \"read\") (sampling-rate %d))";

			sprintf(spec, fmt, rate);
			capture_device = alcOpenDevice((ALubyte *)spec);
			if ( capture_device ) {
				_alcSetContext(NULL, cid, capture_device);
				_alcDeviceSet(capture_device);
			}
		}
	}
	_alcUnlockContext( cid );

	return (capture_device != NULL);
}
Пример #2
0
/*
 * Opens a device, using the alrc expression deviceSpecifier to specify
 * attributes for the device.  Returns the device if successful, NULL
 * otherwise.
 */
ALCdevice *alcOpenDevice( const ALchar *deviceSpecifier ) {
	ALCdevice *retval;
	char dirstr[65];
	Rcvar direction = NULL;
	Rcvar freq_sym = NULL;
	Rcvar speakers = NULL;
	Rcvar devices = NULL;
	int openForInput;

	if( num_devices == 0 ) {
		/* first initialization */
		if( _alParseConfig() == AL_FALSE ) {
			_alDebug(ALD_CONFIG, __FILE__, __LINE__,
				"Couldn't parse config file.");
		}
		if( _alInit() == AL_FALSE ) {
			_alDebug(ALD_CONFIG, __FILE__, __LINE__,
				"Couldn't initialize OpenAL.");
		}
	}

    /* If the name starts with a ', then it's a device configuration */
    if(deviceSpecifier && deviceSpecifier[0] == '\'') {
        Rcvar listOfLists;

        /* see if the user defined devices, sampling-rate, or direction */
        devices   = rc_lookup( "devices" );
        direction = rc_lookup( "direction" );
        freq_sym  = rc_lookup( "sampling-rate" );
        speakers  = rc_lookup( "speaker-num" );

        listOfLists = rc_eval( deviceSpecifier );
        rc_foreach( listOfLists, rc_define_list );
        /* Got a config, so remove the name from further processing */
        deviceSpecifier = NULL;

        /* redefine the stuff we saved */
        if( direction != NULL )
            rc_define( "direction", alrc_quote( direction ));

        if( devices != NULL )
            rc_define( "devices", alrc_quote( devices ) );

        if( freq_sym != NULL )
            rc_define( "sampling-rate", alrc_quote( freq_sym ));

        if( speakers != NULL )
            rc_define( "speaker-num", alrc_quote( speakers ));
    }


	direction = rc_lookup( "direction" );
	devices   = rc_lookup( "devices" );
	freq_sym  = rc_lookup( "sampling-rate" );
	speakers  = rc_lookup( "speaker-num" );

	memset( dirstr, 0, sizeof(dirstr) );
	
	if( direction != NULL ) {
		switch( rc_type( direction ) ) {
			case ALRC_STRING:
				rc_tostr0(direction, dirstr, 64);
				break;
			case ALRC_SYMBOL:
				rc_symtostr0(direction, dirstr, 64);
				break;
			default:
				break;
		}
	}

	retval = malloc( sizeof *retval );
	if( retval == NULL) {
		/* FIXME: set AL_OUT_OF_MEMORY here? */

		return NULL;
	}

	/* defaults */
	retval->format = _ALC_EXTERNAL_FMT;
	retval->speed  = _ALC_EXTERNAL_SPEED;
	retval->flags  = ALCD_NONE;

	if( freq_sym != NULL ) {
		switch(rc_type( freq_sym )) {
			case ALRC_INTEGER:
			case ALRC_FLOAT:
				retval->speed = rc_toint( freq_sym );
				break;
			default:
				_alDebug(ALD_CONVERT, __FILE__, __LINE__,
					"invalid type for sampling-rate");
				break;
		}
	}

	if( speakers != NULL ) {
		switch(rc_type( speakers )) {
			case ALRC_INTEGER:
			case ALRC_FLOAT:
				{
					ALint s = rc_toint( speakers );
					if (s >= 0) {
						ALenum fmt = _al_formatscale( retval->format, (ALuint)s );
						if ( fmt >= 0 ) {
							retval->format = fmt;
						}
					}
				}
				break;
			default:
				break;
		}
	}

	openForInput = (strncmp( dirstr, "read", 64 ) == 0);
	alcBackendOpen_(deviceSpecifier, (openForInput ? ALC_OPEN_INPUT_ : ALC_OPEN_OUTPUT_), &retval->ops, &retval->privateData );
	if( retval->privateData == NULL ) {
		free( retval );
		return NULL;
	}
        /* set specifier */
        retval->specifier = retval->ops->getName(retval->privateData);
	retval->flags |= ( openForInput ? ALCD_READ : ALCD_WRITE );

	num_devices++;

	/* Figure out the size of buffer to request from the device based
	 * on the bytes per sample and speed */
	retval->bufferSizeInBytes  = _alSmallestPowerOfTwo(retval->speed / 15);
	retval->bufferSizeInBytes *= _alGetChannelsFromFormat(retval->format);
	retval->bufferSizeInBytes *= _alGetBitsFromFormat(retval->format) / 8;
	if(_alcDeviceSet(retval) == ALC_FALSE) {
		alcCloseDevice(retval);
		return NULL;
	}

	return retval;
}