Beispiel #1
0
void al_stream_update()
{
	int   processed;
	ALint state;

	if ( source_handle == -1 )
	{
		return;
	}

	// Un-queue any buffers, and delete them
	qalGetSourcei( source, AL_BUFFERS_PROCESSED, &processed );

	if ( processed )
	{
		while ( processed-- )
		{
			ALuint buffer;
			qalSourceUnqueueBuffers( source, 1, &buffer );
			qalDeleteBuffers( 1, &buffer );
		}
	}

	// If it's stopped, release the source
	qalGetSourcei( source, AL_SOURCE_STATE, &state );

	if ( state == AL_STOPPED )
	{
		is_playing = qfalse;
		qalSourceStop( source );
		free_channel();
	}
}
Beispiel #2
0
/*
 * Updates stream sources by removing all played
 * buffers and restarting playback if necessary.
 */
static void
AL_StreamUpdate(void)
{
	int numBuffers;
	ALint state;

	/* Un-queue any buffers, and delete them */
	qalGetSourcei(streamSource, AL_BUFFERS_PROCESSED, &numBuffers);

	while (numBuffers--)
	{
		ALuint buffer;
		qalSourceUnqueueBuffers(streamSource, 1, &buffer);
		qalDeleteBuffers(1, &buffer);
		active_buffers--;
	}

	/* Start the streamSource playing if necessary */
	qalGetSourcei(streamSource, AL_BUFFERS_QUEUED, &numBuffers);
	qalGetSourcei(streamSource, AL_SOURCE_STATE, &state);

	if (state == AL_STOPPED)
	{
		streamPlaying = false;
	}

	if (!streamPlaying && numBuffers)
	{
		qalSourcePlay(streamSource);
		streamPlaying = true;
	}
}
Beispiel #3
0
/*
=================
S_AL_StopBackgroundTrack
=================
*/
static
void S_AL_StopBackgroundTrack( void )
{
	int num;
	if(!musicPlaying)
		return;

	// Stop playing
	qalSourceStop(musicSource);

	// De-queue the musicBuffers
	qalGetSourcei(musicSource, AL_BUFFERS_PROCESSED, &num);
	if(num < NUM_MUSIC_BUFFERS)
		Com_Printf(S_COLOR_YELLOW "WARNING: fewer than NUM_MUSIC_BUFFERS buffers can be unqueued\n");
	qalSourceUnqueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers);

	// Destroy the musicBuffers
	qalDeleteBuffers(NUM_MUSIC_BUFFERS, musicBuffers);

	// Free the musicSource
	S_AL_MusicSourceFree();

	// Unload the stream
	S_AL_CloseMusicFiles();

	musicPlaying = qfalse;
}
Beispiel #4
0
void S_StopBackgroundTrack( void )
{
    bgTrack_t *next;

    if( source )
        qalSourceStop( source );

    if( alloced_buffers ) {
        qalSourceUnqueueBuffers( source, MUSIC_BUFFERS, buffers );
        qalDeleteBuffers( MUSIC_BUFFERS, buffers );
        alloced_buffers = queued_buffers = qfalse;
    }

    music_source_free();

    qalGetError();

    while( s_bgTrackHead )
    {
        next = s_bgTrackHead->anext;

        S_CloseMusicTrack( s_bgTrackHead );
        S_Free( s_bgTrackHead );

        s_bgTrackHead = next;
    }

    s_bgTrack = NULL;
    s_bgTrackHead = NULL;

    s_bgTrackBuffering = qfalse;

    s_bgTrackPaused = qfalse;
}
Beispiel #5
0
void SndAl_StopBackgroundTrack( void )
{
	if ( !mus_playing )
	{
		return;
	}

	// Stop playing
	qalSourceStop( source );

	// De-queue the buffers
	qalSourceUnqueueBuffers( source, BUFFERS, buffers );

	// Destroy the buffers
	qalDeleteBuffers( BUFFERS, buffers );

	// Free the source
	al_mus_source_free();

	// Unload the stream
	if ( mus_stream )
	{
		si.StreamClose( mus_stream );
	}

	mus_stream = NULL;

	mus_playing = qfalse;
}
Beispiel #6
0
void AL_DeleteSfx( sfx_t *s ) {
    sfxcache_t *sc;
    ALuint name;

    sc = s->cache;
    if( !sc ) {
        return;
    }

    name = sc->bufnum;
    qalDeleteBuffers( 1, &name );
}
/*
=================
S_StreamRawSamples

Cinematic streaming
=================
*/
void S_StreamRawSamples (const byte *data, int samples, int rate, int width, int channels)
{
	int			processed, state, size;
	unsigned	format, buffer;

	if (!s_initialized)
		return;

	if (!s_streamingChannel)
		return;

	// Unqueue and delete any processed buffers
	qalGetSourcei(s_streamingChannel->sourceNum, AL_BUFFERS_PROCESSED, &processed);
	if (processed > 0){
		while (processed--){
			qalSourceUnqueueBuffers(s_streamingChannel->sourceNum, 1, &buffer);
			qalDeleteBuffers(1, &buffer);
		}
	}

	// Calculate buffer size
	size = samples * width * channels;

	// Set buffer format
	if (width == 2)
	{
		if (channels == 2)
			format = AL_FORMAT_STEREO16;
		else
			format = AL_FORMAT_MONO16;
	}
	else
	{
		if (channels == 2)
			format = AL_FORMAT_STEREO8;
		else
			format = AL_FORMAT_MONO8;
	}

	// Upload and queue the new buffer
	qalGenBuffers(1, &buffer);
	qalBufferData(buffer, format, (byte *)data, size, rate);
	qalSourceQueueBuffers(s_streamingChannel->sourceNum, 1, &buffer);

	// Update volume
	qalSourcef(s_streamingChannel->sourceNum, AL_GAIN, s_sfxVolume->value);

	// If not playing, then do so
	qalGetSourcei(s_streamingChannel->sourceNum, AL_SOURCE_STATE, &state);
	if (state != AL_PLAYING)
		qalSourcePlay(s_streamingChannel->sourceNum);
}
Beispiel #8
0
 /*
  * Silence / stop all OpenAL streams
  */
 static void
 AL_StreamDie ( void )
 {
   q_int32_t numBuffers;
   streamPlaying = false;
   qalSourceStop ( streamSource );
   /* Un-queue any buffers, and delete them */
   qalGetSourcei ( streamSource, AL_BUFFERS_QUEUED, &numBuffers );

   while ( numBuffers-- ) {
     ALuint buffer;
     qalSourceUnqueueBuffers ( streamSource, 1, &buffer );
     qalDeleteBuffers ( 1, &buffer );
     active_buffers--;
   }
 }
/*
=================
S_AL_BufferUnload
=================
*/
static void S_AL_BufferUnload(sfxHandle_t sfx)
{
	ALenum error;

	if(knownSfx[sfx].filename[0] == '\0')
		return;

	if(!knownSfx[sfx].inMemory)
		return;

	// Delete it
	qalDeleteBuffers(1, &knownSfx[sfx].buffer);
	if((error = qalGetError()) != AL_NO_ERROR)
		Com_Printf( S_COLOR_RED "ERROR: Can't delete sound buffer for %s\n",
				knownSfx[sfx].filename);

	knownSfx[sfx].inMemory = qfalse;
}
Beispiel #10
0
/*
=================
S_AL_StreamUpdate
=================
*/
static
void S_AL_StreamUpdate( int stream )
{
	int		numBuffers;
	ALint	state;

	if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
		return;

	if(streamSourceHandles[stream] == -1)
		return;

	// Un-queue any buffers, and delete them
	qalGetSourcei( streamSources[stream], AL_BUFFERS_PROCESSED, &numBuffers );
	while( numBuffers-- )
	{
		ALuint buffer;
		qalSourceUnqueueBuffers(streamSources[stream], 1, &buffer);
		qalDeleteBuffers(1, &buffer);
	}

	// Start the streamSource playing if necessary
	qalGetSourcei( streamSources[stream], AL_BUFFERS_QUEUED, &numBuffers );

	qalGetSourcei(streamSources[stream], AL_SOURCE_STATE, &state);
	if(state == AL_STOPPED)
	{
		streamPlaying[stream] = qfalse;

		// If there are no buffers queued up, release the streamSource
		if( !numBuffers )
			S_AL_FreeStreamChannel( stream );
	}

	if( !streamPlaying[stream] && numBuffers )
	{
		qalSourcePlay( streamSources[stream] );
		streamPlaying[stream] = qtrue;
	}
}
Beispiel #11
0
bool S_UnloadBuffer( sfx_t *sfx )
{
	ALenum error;

	if( !sfx ) {
		return false;
	}
	if( sfx->filename[0] == '\0' || sfx->isLocked || !sfx->inMemory )
		return false;

	qalDeleteBuffers( 1, &sfx->buffer );
	if( ( error = qalGetError() ) != AL_NO_ERROR )
	{
		Com_Printf( "Couldn't delete sound buffer for %s (%s)", sfx->filename, S_ErrorMessage( error ) );
		sfx->isLocked = true;
		return false;
	}

	sfx->inMemory = false;

	return true;
}
/*
=================
S_AL_StopBackgroundTrack
=================
*/
static
void S_AL_StopBackgroundTrack( void )
{
	if(!musicPlaying)
		return;

	// Stop playing
	qalSourceStop(musicSource);

	// De-queue the musicBuffers
	qalSourceUnqueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers);

	// Destroy the musicBuffers
	qalDeleteBuffers(NUM_MUSIC_BUFFERS, musicBuffers);

	// Free the musicSource
	S_AL_MusicSourceFree();

	// Unload the stream
	S_AL_CloseMusicFiles();

	musicPlaying = qfalse;
}