Ejemplo n.º 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);
}
Ejemplo n.º 2
0
ALboolean alCaptureDestroy_EXT( ALvoid )
{
	ALuint cid;
	AL_context *cc;

	/* get the current context */
	cid = _alcCCId;
	_alcLockContext( cid );
	cc = _alcGetContext(cid);
	if ( cc == NULL ) {
		_alcUnlockContext( cid );
		return AL_FALSE;
	}

	if ( cc->read_device ) {
		/* Only close it if we opened it originally */
		if (cc->write_device && (cc->read_device != cc->write_device)) {
			alcCloseDevice(cc->read_device);
			cc->read_device = NULL;
		}
	}
	_alcUnlockContext( cid );

	return AL_TRUE;
}
Ejemplo n.º 3
0
/*
 * _alcSpeakerMove( ALuint cid )
 *
 * Moves speakers for context named by cid, using listener orientation and
 * position as modifiers.
 *
 * If cid is invalid, set ALC_INVALID_CONTEXT.
 *
 * assumes context cid is locked
 *
 * FIXME:
 *    please check my math
 */
void _alcSpeakerMove( ALuint cid ) {
    AL_context *cc;
    ALfloat vec[3];
    ALfloat *pos;    /* listener position */
    ALfloat *ori;    /* listener orientation */
    ALfloat ipos[3]; /* inverse listener position */
    ALuint i;
    ALfloat m[3][3];
    ALfloat pm[3];
    ALfloat rm[3];

    cc = _alcGetContext( cid );
    if(cc == NULL) {
        _alDebug(ALD_CONTEXT, __FILE__, __LINE__,
                 "_alcSpeakerMove: invalid context id %d", cid);

        _alcSetError( ALC_INVALID_CONTEXT );

        return;
    }

    pos = cc->listener.position;
    ori = cc->listener.orientation;

    _alVectorCrossProduct(vec, ori + 0, ori + 3);
    _alVectorNormalize(m[0], vec);

    _alVectorCrossProduct(vec, m[0], ori + 0);
    _alVectorNormalize(m[1], vec);

    _alVectorNormalize(m[2], ori + 0);

    /* reset speaker position */
    _alcSpeakerInit(cid);

    _alVectorInverse( ipos, cc->listener.position );

    /* rotate about at and up vectors */
    for(i = 0; i < _alcGetNumSpeakers(cid); i++) {
        _alVectorTranslate(pm,
                           cc->_speaker_pos[i].pos, ipos);

        _alVecMatrixMulA3(rm, pm, m);

        _alVectorTranslate(cc->_speaker_pos[i].pos,
                           rm, pos);
    }

    _alDebug(ALD_MATH, __FILE__, __LINE__,
             "SpAdj: l/r [%f|%f|%f] [%f|%f|%f]",
             cc->_speaker_pos[0].pos[0],
             cc->_speaker_pos[0].pos[1],
             cc->_speaker_pos[0].pos[2],

             cc->_speaker_pos[1].pos[0],
             cc->_speaker_pos[1].pos[1],
             cc->_speaker_pos[1].pos[2]);

    return;
}
Ejemplo n.º 4
0
/*
 * _alcGetSpeakerPosition( ALuint cid, ALuint speaker_num )
 *
 * Returns 3-float tuple giving the speaker position for speaker with offset
 * speaker_num for the context named cid, or NULL on error.
 *
 * assumes locked context
 */
ALfloat *_alcGetSpeakerPosition( ALuint cid, ALuint speaker_num ) {
    AL_context *cc;
    ALuint nc;

    cc = _alcGetContext( cid );
    if(cc == NULL) {
        return NULL;
    }

    nc = _alcGetNumSpeakers( cid );

    if( speaker_num >= nc ) {
        return NULL;
    }

    return cc->_speaker_pos[speaker_num].pos;
}
Ejemplo n.º 5
0
/*
 * _alSetError( ALuint cid, ALenum param )
 *
 * Sets the error for the context with name cid to param.
 *
 * assumes locked context
 */
void _alSetError( ALuint cid, ALenum param ) {
	AL_context *cc;

	cc = _alcGetContext( cid );
	if(cc == NULL) {
		/* No default context, no error set. */
		return;
	}

	if( cc->alErrorIndex == 0 ) {
		/*
		 * Only set error if no previous error has been recorded.
		 */
		
		cc->alErrorIndex = ErrorNo2index(param);
	}
		
	if(_alShouldBombOnError_LOKI == AL_TRUE) {
		raise(SIGABRT);
	}

	return;
}
Ejemplo n.º 6
0
ALsizei alCaptureGetData_EXT( UNUSED(ALvoid* data),
                              UNUSED(ALsizei n),
                              UNUSED(ALenum format),
                              UNUSED(ALuint rate) )
{
	AL_device *dev;
	ALuint size;
	ALuint cid;
	AL_context *cc;

	/* get the read device */
	cid = _alcCCId;
	cc = _alcGetContext(cid);
	if ( cc == NULL ) {
		return 0;
	}
	dev = cc->read_device;

	if ( (dev->format == format) && (dev->speed == rate) ) {
		size = _alcDeviceRead(cid, data, n);
	} else {
		ALuint samples;
		void *temp;

		samples = n / (_al_formatbits(format) / 8);

		/* Set size to the bytes of raw audio data we need */
		size = _al_PCMRatioify(rate, dev->speed,
		                       format, dev->format, samples);
		size *= (_al_formatbits(dev->format) / 8);

        	if ( n > (ALsizei)size )
			temp = malloc( n );
		else
			temp = malloc( size );

		if ( size > 0 ) {
			size = _alcDeviceRead(cid, temp, size);

			temp = _alBufferCanonizeData(dev->format,
						     temp,
						     size,
						     dev->speed,
						     format,
						     rate,
						     &size,
						     AL_TRUE);
		} else {
			/* Hmm, zero size in record.. */
			memset(temp, 0, n);
			size = n;
		}
		if(temp == NULL) {
			fprintf(stderr, "could not canonize data\n");
			return 0;
		}

		memcpy(data, temp, size);

		free( temp );
	}
	return size;
}
Ejemplo n.º 7
0
/*
 * _alcSpeakerInit( ALuint cid )
 *
 * Initialize position wrt listener, w/o rt orientation.
 *
 * assumes locked context
 */
static void _alcSpeakerInit( ALuint cid ) {
    AL_context  *cc;
    AL_listener *lis;
    ALfloat *lpos;
    ALfloat sdis; /* scaled distance */
    ALuint i;
    ALuint num;

    cc  = _alcGetContext( cid );
    lis = _alcGetListener( cid );
    if(cc == NULL) {
        /* invalid cid */
        _alDebug(ALD_CONTEXT, __FILE__, __LINE__,
                 "_alcSpeakerInit: invalid cid 0x%x", cid );

        return;
    }

    if(lis == NULL) {
        /* weird */
        return;
    }

    lpos = lis->position;

    /*
     * A speaker distance of one simplifies the math later.
     */
    sdis = 1.0f;

    _alDebug(ALD_CONTEXT, __FILE__, __LINE__,
             "_alcSpeakerInit: ( sdis %f )", sdis );

    for (i = 0; i < _ALC_MAX_CHANNELS; i++)
    {
        cc->_speaker_pos[i].pos[0]   = lpos[0];
        cc->_speaker_pos[i].pos[1]   = lpos[1];
        cc->_speaker_pos[i].pos[2]   = lpos[2];
    }

    num = _alcGetNumSpeakers(cid);

    /* fourpoint */

    if (num >= 4)
    {
        sdis *= M_SQRT1_2;

        cc->_speaker_pos[ALS_LEFT].pos[2] += sdis;
        cc->_speaker_pos[ALS_RIGHT].pos[2] += sdis;

        cc->_speaker_pos[ALS_LEFTS].pos[0] -= sdis;
        cc->_speaker_pos[ALS_LEFTS].pos[2] -= sdis;

        cc->_speaker_pos[ALS_RIGHTS].pos[0] += sdis;
        cc->_speaker_pos[ALS_RIGHTS].pos[2] -= sdis;
    }

    /* stereo */

    if (num >= 2)
    {
        cc->_speaker_pos[ALS_LEFT].pos[0] -= sdis;
        cc->_speaker_pos[ALS_RIGHT].pos[0] += sdis;
    }
    return;
}