unsigned int loadPopulationIntoBuffer( _PopulationVector population )
{
	unsigned int num_buffers = 0;
	// queue up (starting at the front) our rotating queue of file buffers
	for ( _PopulationIterator population_it = population.begin(); population_it != population.end(); ++population_it )
	{
		_GenomePtr current_genome = *population_it;
		num_buffers += current_genome->wave_descriptors.size();
		// printf( "number of wave descriptors: %zu\n", current_genome->wave_descriptors.size() );
		for ( _WaveDescriptorIterator wave_descriptor_it = current_genome->wave_descriptors.begin(); wave_descriptor_it != current_genome->wave_descriptors.end(); ++wave_descriptor_it )
		{
			WaveDescriptor current_descriptor = *wave_descriptor_it;
			// every gene advances our "clock" 1/16 of a beat
			// the wave state is updated first
			// if we've reached a commit bit, the buffer for the wave is generated and queued
			// if our note duration has expired, we go silent (queue silent wave buffer)

			if ( current_descriptor.type == 1 )
			{
				printf( "Creating sound clip: %f %f\n", current_descriptor.frequency, current_descriptor.duration );
			}
			else
			{
				printf( "Creating silent clip: %f %f\n", current_descriptor.frequency, current_descriptor.duration );
			}
			checkAndQueueBuffer( alutCreateBufferWaveform( current_descriptor.wave_type, current_descriptor.frequency, current_descriptor.phase, current_descriptor.duration ) );

		}
	}
	return num_buffers;
}
Ejemplo n.º 2
0
Archivo: bind.cpp Proyecto: Qard/jsgame
Handle<Value> ALUTCreateBufferWaveformCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 4)
		return v8::Undefined();
	
	//get arguments
	int arg0 = args[0]->IntegerValue();
	double arg1 = args[1]->NumberValue();
	double arg2 = args[2]->NumberValue();
	double arg3 = args[3]->NumberValue();

	//make call
	alutCreateBufferWaveform((ALenum)arg0, (ALfloat)arg1, (ALfloat)arg2, (ALfloat)arg3);
	
	return v8::Undefined();
}
Ejemplo n.º 3
0
bool SoundManager::playSquareTone() {

	//Create a sound buffer with a Saw tone in it
	ALuint bufferId = alutCreateBufferWaveform(ALUT_WAVEFORM_SQUARE, 440.0, 0,
			2);

	//Get the next available source
	ALuint sourceId = getNextAvailableSourceId();

	//Attach the buffer to the source
	if (attachBufferToSource(bufferId, sourceId)) {

		//Now play it
		return playSource(sourceId, 1.0, 0.3, false);

	} else {
		return false;
	}

}
Ejemplo n.º 4
0
size_t SonicDog::addObject( float x, float z, obj_t type ) {
	// instantiate the source and buffer for this sound source
	SoundSrc *src = new SoundSrc;
	src->id = object_id_;
	src->once = false;
	src->x = x;
	src->z = z;
	src->pause = 1.5;

	alGetError();
	alGenSources( 1, &(src->source) );
	checkError( "alGenSources", AL );

	switch ( type ) {
		case BEAC: {
			// src->buffer = alutCreateBufferWaveform( ALUT_WAVEFORM_WHITENOISE, 500.0f, 0.0f, 0.5f );
			alutGetError();
			src->buffer = alutCreateBufferFromFile( "./beeps.wav" );
			checkError( "alutCreateBufferFromFile", ALUT );

			alSourcef( src->source, AL_GAIN, 10.0f );
			break;
		}
		case OBS: {
			alutGetError();
			src->buffer = alutCreateBufferWaveform( ALUT_WAVEFORM_SQUARE, object_id_*100.0f + 100.0f, 0.0f, 0.7f );
			checkError( "alutCreateBufferWaveform", ALUT );

			alSourcef( src->source, AL_GAIN, 0.1f );
			break;
		}
		default: break;
	}

	alSourcef( src->source, AL_PITCH, 1 );
	alSource3f( src->source, AL_VELOCITY, 0.0f, 0.0f, 0.0f );
	alSourcei( src->source, AL_LOOPING, AL_FALSE );
	alSourcei( src->source, AL_BUFFER, src->buffer );

	if ( regions_ ) {
		// move the location of the source in the OpenAL world to one of our discrete zones
		ALfloat pos[] = { 0.0, 0.0, 0.0 };
		placeInRegion( x, z, pos );
		alSourcefv( src->source, AL_POSITION, pos );
	} else if ( cutoff_ ) {
		ALfloat pos[] = { 0.0, 0.0, 0.0 };
		placeInCutoff( x, z, pos );	
		alSourcefv( src->source, AL_POSITION, pos );
	} else {
		alSource3f( src->source, AL_POSITION, x, 0.0f, z );
	}

	// insert the src into our map
	pthread_mutex_lock( &sources_lock_ );
	sources_.insert( SoundMap::value_type( src->id, src ) );
	pthread_mutex_unlock( &sources_lock_ );

	// insert an entry for this source to our removed map
	pthread_mutex_lock( &remove_lock_ );
	removed_.insert( BoolMap::value_type( src->id, false ) );
	pthread_mutex_unlock( &remove_lock_ );

	// insert an entry for this source to our paused map
	pthread_mutex_lock( &pause_lock_ );
	paused_.insert( BoolMap::value_type( src->id, false ) );
	pthread_mutex_unlock( &pause_lock_ );

	// alSourcePlay( src->source );

	// then insert it into the play queue
	pthread_mutex_lock( &q_lock_ );
	play_q_.push( src );
	pthread_mutex_unlock( &q_lock_ );

	// alert the threads that a new object has been added
	pthread_cond_broadcast( &empty_q_lock_ );

	// increment the id counter
	object_id_++;

	return src->id;
}