Example #1
0
void audioFinish() {
	if (voicemsgs) {
		delete voicemsgs;
	}

	alSourceStop(notifySource);
	if (alIsBuffer(notifyBuffer)) {
		alDeleteBuffers(1, &notifyBuffer);
		notifyBuffer = 0;
	}
	if (alIsSource(notifySource)) {
		alDeleteSources(1, &notifySource);
		notifySource = 0;
	}

	if (audioContext) {
		alcMakeContextCurrent(NULL);
		alcDestroyContext(audioContext);
		audioContext = 0;
	}

	if (audioDevice) {
		alcCloseDevice(audioDevice);
		audioDevice = 0;
	}
}
Example #2
0
ALAPI void ALAPIENTRY alBuffer3f(ALuint buffer, ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
{
    ALCcontext    *pContext;

    (void)flValue1;
    (void)flValue2;
    (void)flValue3;

    pContext = alcGetCurrentContext();
    SuspendContext(pContext);

    if (alIsBuffer(buffer) && (buffer != 0))
    {
        switch(eParam)
        {
        default:
            alSetError(AL_INVALID_ENUM);
            break;
        }
    }
    else
    {
        alSetError(AL_INVALID_NAME);
    }

    ProcessContext(pContext);
}
Example #3
0
void al_isbuffer( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

	if (NULL == alIsBuffer) mogl_glunsupported("alIsBuffer");
	plhs[0]=mxCreateDoubleMatrix(1,1,mxREAL);
	*mxGetPr(plhs[0])=(double)alIsBuffer((ALuint)mxGetScalar(prhs[0]));

}
Example #4
0
ALAPI void ALAPIENTRY alBufferiv(ALuint buffer, ALenum eParam, const ALint* plValues)
{
    ALCcontext    *pContext;

    (void)plValues;

    pContext = alcGetCurrentContext();
    SuspendContext(pContext);

    if (alIsBuffer(buffer) && (buffer != 0))
    {
        switch(eParam)
        {
        default:
            alSetError(AL_INVALID_ENUM);
            break;
        }
    }
    else
    {
        alSetError(AL_INVALID_NAME);
    }

    ProcessContext(pContext);
}
Example #5
0
/* Creates a one second buffer containing a sine wave, and returns the new
 * buffer ID. */
static ALuint CreateSineWave(void)
{
    ALshort data[44100];
    ALuint buffer;
    ALenum err;
    ALuint i;

    for(i = 0;i < 44100;i++)
        data[i] = (ALshort)(sin(i * 441.0 / 44100.0 * 2.0*M_PI)*32767.0);

    /* Buffer the audio data into a new buffer object. */
    buffer = 0;
    alGenBuffers(1, &buffer);
    alBufferData(buffer, AL_FORMAT_MONO16, data, sizeof(data), 44100);

    /* Check if an error occured, and clean up if so. */
    err = alGetError();
    if(err != AL_NO_ERROR)
    {
        fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
        if(alIsBuffer(buffer))
            alDeleteBuffers(1, &buffer);
        return 0;
    }

    return buffer;
}
Example #6
0
ALAPI void ALAPIENTRY alGetBuffer3i(ALuint buffer, ALenum eParam, ALint* plValue1, ALint* plValue2, ALint* plValue3)
{
    ALCcontext    *pContext;

    pContext = alcGetCurrentContext();
    SuspendContext(pContext);

    if ((plValue1) && (plValue2) && (plValue3))
    {
        if (alIsBuffer(buffer) && (buffer != 0))
        {
            switch(eParam)
            {
            default:
                alSetError(AL_INVALID_ENUM);
                break;
            }
        }
        else
        {
            alSetError(AL_INVALID_NAME);
        }
    }
    else
    {
        alSetError(AL_INVALID_VALUE);
    }

    ProcessContext(pContext);
}
Example #7
0
/* Function: alureBufferDataFromMemory
 *
 * Loads a file image from memory into an existing OpenAL buffer object,
 * similar to alureBufferDataFromFile. Requires an active context.
 *
 * Returns:
 * AL_FALSE on error.
 *
 * See Also:
 * <alureCreateBufferFromMemory>
 */
ALURE_API ALboolean ALURE_APIENTRY alureBufferDataFromMemory(const ALubyte *fdata, ALsizei length, ALuint buffer)
{
    if(alGetError() != AL_NO_ERROR)
    {
        SetError("Existing OpenAL error");
        return AL_FALSE;
    }

    if(!buffer || !alIsBuffer(buffer))
    {
        SetError("Invalid buffer ID");
        return false;
    }

    if(length < 0)
    {
        SetError("Invalid data length");
        return AL_FALSE;
    }

    MemDataInfo memData;
    memData.Data = fdata;
    memData.Length = length;
    memData.Pos = 0;

    if(load_stream(create_stream(memData), buffer) == false)
        return AL_FALSE;
    return AL_TRUE;
}
void EOSAudioDevice::unbindBuffer(unsigned int num)
{
    for(unsigned int i=0; i<bindList.size(); i++)
    {
        if(bindList[i]->_bindNum == num)
        {
            bindList[i]->_numOwners--;
            if(bindList[i]->_numOwners == 0 && alIsBuffer(num))
            {
                alDeleteBuffers(1, &num);
				//printf("unbind: buffer number %d\n", num);
                //
                int alError = alGetError();
                switch(alError)
                {
                case AL_NO_ERROR:
                    bindList.erase(bindList.begin()+i, bindList.begin()+i);
			        //printf("unbind: AL_NO_ERROR (ok)\n");
                    break;
                case AL_INVALID_OPERATION:
                    // The buffer is still in use and can not be deleted
		          	//printf("unbind: AL_INVALID_OPERATION!\n");
                    break;
                default:
                    LOGERROR("[eos.audio] ERROR: %s in EOSAudioDevice::unbindBuffer()", (char *)alGetString(alError));
                }
            }           
            return;
        }
    }
}
Example #9
0
void SoundBuffer::Init( const char * a_file_name )
{
	ASSERT(a_file_name);

	// buffer id
	alGenBuffers( 1, &m_id );
	ASSERT( m_id != 0 );
	ASSERT( alIsBuffer(m_id) );
	SoundManager::Ref().CheckError();

	// load file based on extension
	const char * ext = GetFileExt( a_file_name );
	if ( strcmp( ext, "wav" ) == 0 )
		InitWave(a_file_name);
	else if ( strcmp( ext, "ogg" ) == 0 )
		InitOgg(a_file_name);
	else
		ERROR_MSG("Cannot load sound '%s': unrecognized file extension '%s'", a_file_name, ext );

	// TEMPFIX: basically, if we turn off vorbis, GetProperties will crash..
	#if defined(USE_VORBIS)
	GetBufferProperties();
	#endif

	SoundManager::Ref().CheckError();
}
Example #10
0
StaticSoundSample::~StaticSoundSample()
{
	if (alIsBuffer(mBuffer)) {
		alDeleteBuffers(1, &mBuffer);
		SoundGeneral::checkAlError("Deleting static sound buffers.");
	}
}
Example #11
0
bool OpenAL::IsBuffer(ALuint buffer)
{
    if(!IsInitialized())
        return false;

    return alIsBuffer(buffer) == AL_TRUE;
}
void SampleResourceManager::freeResourceData(SampleResource& res)
{
    if(alIsBuffer(res.bufferID))
    {
        // delete buffers, just like textures in GL
        alDeleteBuffers(1, &res.bufferID);
    }
}
Example #13
0
OpenalSound::~OpenalSound()
{
	if (alIsSource(source)) {
		alSourceStop (source);
		alDeleteSources(1, &source);
	}
	if (alIsBuffer(buffer)) {
		alDeleteBuffers(1, &buffer);
	}
}
Example #14
0
void SoundBuffer::InitOgg( const char * a_filename )
{
#ifdef USE_VORBIS
	// http://www.gamedev.net/page/resources/_/technical/game-programming/introduction-to-ogg-vorbis-r2031
	OggVorbis_File ogg_file;

	// load ogg
    const char * full_path = GetFullPath( a_filename );
	int err_val = ov_fopen( full_path, &ogg_file );
	//int err_val = ov_open_callbacks( nullptr, &ogg_file, (const char*)a_data_file.GetData(), a_data_file.GetNumBytes(), OV_CALLBACKS_STREAMONLY );
	CHECK( err_val == 0, "OGG File load error %d", err_val );
	vorbis_info * ogg_info = ov_info(&ogg_file, -1);
	ASSERT( ogg_info );

	// ogg format
	ALenum al_format;
	if ( ogg_info->channels == 1 ) 
		al_format = AL_FORMAT_MONO16;
	else if ( ogg_info->channels == 2 )
		al_format = AL_FORMAT_STEREO16;
	else
		ERROR_MSG("OGG - Unrecognized num channels : %d", ogg_info->channels );

	// num samples
	ogg_int64_t total_num_pcm_samples = ov_pcm_total( &ogg_file, -1 );
	ASSERT( total_num_pcm_samples > 0 );

	// reserve space for the buffer
	std::vector<char> buffer;
	buffer.reserve( (size_t)(total_num_pcm_samples * 2 * ogg_info->channels) );

	char buff_array[32768];    // Local fixed size array
	int bit_stream = 0;
	int num_bytes_read = 0;

	// read all the data
	do 
	{
		num_bytes_read = ov_read(&ogg_file, buff_array, sizeof(buff_array), 0, 2, 1, &bit_stream);
		buffer.insert(buffer.end(), buff_array, buff_array + num_bytes_read);
	} while (num_bytes_read > 0);
	 
	// check size size
	ASSERT( total_num_pcm_samples * 2 * ogg_info->channels  == buffer.size() );

	// output the data
	ALsizei al_size = buffer.size();
	ALsizei al_freq = ogg_info->rate;
	ASSERT( alIsBuffer(m_id) );
	alBufferData( m_id, al_format, &buffer[0], al_size, al_freq);
	
	// close the file
	ov_clear(&ogg_file);
#endif
}
void EOSAudioDevice::unbindAllBuffers()
{
    for(unsigned int i=0; i<bindList.size(); i++)
    {
        if(alIsBuffer(bindList[i]->_bindNum))
        {
            alDeleteBuffers(1, &bindList[i]->_bindNum);
            alGetError();
        }
    }
    bindList.clear();
}
Example #16
0
	AudioDevice::~AudioDevice()
	{
		for(auto itr = m_audioFiles.begin(); itr != m_audioFiles.end(); itr++)
		{
			if(alIsBuffer(itr->second.buffer))
				alDeleteBuffers(1, &itr->second.buffer);
		}

		alcMakeContextCurrent(NULL);
		alcDestroyContext(m_context);
		alcCloseDevice(m_device);
	}
Example #17
0
AudioTrack::~AudioTrack() {
	std::cout << "Freeing the buffers" << std::endl;
	if (alIsBuffer(buffers[0])) {
		std::cout << "IS BUFFER" << std::endl;
	} else {
		std::cout << "IS NOT A VALID BUFFER" << std::endl;
	}
	
	alGetError();
	alDeleteBuffers(1, buffers);
	std::cout << "AudioTrack::AudioTrack()    -   alDeleteBuffers(NUM_BUFFERS, buffers);" << alGetError() << std::endl;
}
Example #18
0
ALAPI ALvoid ALAPIENTRY alSourcei (ALuint source, ALenum pname, ALint value)
{
	ALenum error;
	ALuint buffer;
	
	if (alIsSource(source))
	{
		switch(pname) 
		{
			case AL_LOOPING:
				gSource[source].looping = value;
				break;
			case AL_BUFFER:
				if ((gSource[source].state == AL_STOPPED) || (gSource[source].state == AL_INITIAL))
				{
					if ((alIsBuffer(value)) || (value == NULL))
					{
						gSource[source].srcBufferNum = value;
				
						// reset queue
						alGetError(); // clear error code
						error = AL_NO_ERROR;
						while (error == AL_NO_ERROR)
						{
							alSourceUnqueueBuffers(source, 1, &buffer);
							error = alGetError();
						}
					
					} else
					{
						alSetError(AL_INVALID_VALUE);
					}
				} else
				{
					alSetError(AL_INVALID_OPERATION);
				}
				break;
			case AL_SOURCE_RELATIVE:
				if ((value==AL_FALSE)||(value==AL_TRUE))
				{
					gSource[source].srcRelative = value;
				} else
				{
					alSetError(AL_INVALID_VALUE);
				}
				break;
			default:
				alSetError(AL_INVALID_ENUM);
				break;
	
		}
	}
}
Example #19
0
void OpenAL::DeleteBuffer(ALuint buffer)
{
    if(!IsInitialized())
        return;

    if(!alIsBuffer(buffer))
        return;

    alDeleteBuffers(1, &buffer);
    --m_ActiveBuffers;

    LogInfo("Deleted OAL buffer, %i active buffers left", m_ActiveBuffers);
}
Example #20
0
File: bind.cpp Project: Qard/jsgame
Handle<Value> ALIsBufferCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 1)
		return v8::Undefined();
	
	//get arguments
	int arg0 = args[0]->IntegerValue();

	//make call
	alIsBuffer((ALuint)arg0);
	
	return v8::Undefined();
}
Example #21
0
void oggRead( SOggSound* o, ALuint* buffer )
{
  ALshort samples[SOUND_SAMPLE_SIZE];

  ALsizei read;  

  ALsizei total_read = 0;
  ALsizei total_size = SOUND_SAMPLE_SIZE * sizeof(ALshort);
  char* p_Samples = (char*)(&samples[0]);

    // Tant qu'on n'a pas atteint la taille voulue, on lit
    while( total_read < total_size)
    {
      // Lecture des échantillons à partir du flux ogg-vorbis
      read = ov_read( &o->stream, p_Samples + total_read, total_size - total_read, 0, 2, 1, NULL );
      //printf("read %d\n", read );
      
      if( read > 0 )
        {
	  // La lecture a réussi, on avance du nombre d'octets lus
	  total_read += read;
        }
      else
        {
	  // La lecture a échoué, on arrête de lire
	  return;
	  break;
        }
    }

    // Remplissage du tampon avec les données lues
    if( total_read > 0 )
      {
	if( !alIsBuffer( *buffer ) )
	  {
	    alGenBuffers( 1, buffer );
	    //printf( "create buffer.\n" );
	  }
	else
	  {
	    alDeleteBuffers( 1 , buffer );
	    alGenBuffers( 1, buffer );
	    
	  }
	
	alBufferData( *buffer, o->format, &samples[0], total_read, o->stream.vi->rate );
	
      }
    soundCheckErrorAL( "read ogg" );
    soundCheckErrorALC( "read ogg" );
}
Example #22
0
	SoundHandle AudioDevice::createSound(const std::string &name)
	{
		// Perform cleanup before creating new sounds
		audioCleanup();

		auto itr = m_audioFiles.find(name);
		if(itr != m_audioFiles.end())
		{
			// Check if data hasn't been loaded for this file previously
			if(!alIsBuffer(itr->second.buffer) || itr->second.buffer == 0)
			{
				// Open file and save initial data
				SF_INFO fileInfo;
				SNDFILE *file = sf_open(itr->second.fileName.c_str(), SFM_READ, &fileInfo);

				if(file == NULL)
				{
					JL_WARNING_LOG("Could not open audio file '%s'", itr->second.fileName.c_str());
					return SoundHandle();
				}

				// Create new buffer
				alGenBuffers(1, &itr->second.buffer);

				// Read whole file
				int sampleCount = fileInfo.frames * fileInfo.channels;
				std::vector<ALshort> fileData(sampleCount);
				sf_read_short(file, &fileData[0], sampleCount);
				alBufferData(
					itr->second.buffer,
					AudioDevice::getFormatFromChannels(fileInfo.channels),
					&fileData[0],
					sampleCount*sizeof(ALushort),
					fileInfo.samplerate);

				sf_close(file);
			}

			// Create new audio source
			m_sounds.push_back(
				SoundHandle(new AudioChunk(itr->second.buffer, itr->second.fileName)));

			return m_sounds.back();
		}
		else
		{
			JL_WARNING_LOG("Couldn't find any sound by the name '%s'", name.c_str());
			return SoundHandle(nullptr);
		}
	}
Example #23
0
/* Generates waveforms using additive synthesis. Each waveform is constructed
 * by summing one or more sine waves, up to (and excluding) nyquist.
 */
static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate)
{
    ALint data_size;
    ALfloat *data;
    ALuint buffer;
    ALenum err;
    ALuint i;

    data_size = srate * sizeof(ALfloat);
    data = calloc(1, data_size);
    if(type == WT_Sine)
        ApplySin(data, 1.0, srate, freq);
    else if(type == WT_Square)
        for(i = 1;freq*i < srate/2;i+=2)
            ApplySin(data, 4.0/M_PI * 1.0/i, srate, freq*i);
    else if(type == WT_Sawtooth)
        for(i = 1;freq*i < srate/2;i++)
            ApplySin(data, 2.0/M_PI * ((i&1)*2 - 1.0) / i, srate, freq*i);
    else if(type == WT_Triangle)
        for(i = 1;freq*i < srate/2;i+=2)
            ApplySin(data, 8.0/(M_PI*M_PI) * (1.0 - (i&2)) / (i*i), srate, freq*i);
    else if(type == WT_Impulse)
    {
        /* NOTE: Impulse isn't really a waveform, but it can still be useful to
         * test (other than resampling, the ALSOFT_DEFAULT_REVERB environment
         * variable can prove useful here to test the reverb response).
         */
        for(i = 0;i < srate;i++)
            data[i] = (i%(srate/freq)) ? 0.0f : 1.0f;
    }

    /* Buffer the audio data into a new buffer object. */
    buffer = 0;
    alGenBuffers(1, &buffer);
    alBufferData(buffer, AL_FORMAT_MONO_FLOAT32, data, data_size, srate);
    free(data);

    /* Check if an error occured, and clean up if so. */
    err = alGetError();
    if(err != AL_NO_ERROR)
    {
        fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
        if(alIsBuffer(buffer))
            alDeleteBuffers(1, &buffer);
        return 0;
    }

    return buffer;
}
Example #24
0
ALAPI ALvoid ALAPIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plValue)
{
    ALCcontext    *pContext;
    ALbuffer    *pBuffer;

    pContext = alcGetCurrentContext();
    SuspendContext(pContext);

    if (plValue)
    {
        if (alIsBuffer(buffer) && (buffer != 0))
        {
            pBuffer = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(buffer));

            switch (eParam)
            {
            case AL_FREQUENCY:
                *plValue = pBuffer->frequency;
                break;

            case AL_BITS:
                *plValue = aluBytesFromFormat(pBuffer->format) * 8;
                break;

            case AL_CHANNELS:
                *plValue = aluChannelsFromFormat(pBuffer->format);
                break;

            case AL_SIZE:
                *plValue = pBuffer->size;
                break;

            default:
                alSetError(AL_INVALID_ENUM);
                break;
            }
        }
        else
        {
            alSetError(AL_INVALID_NAME);
        }
    }
    else
    {
        alSetError(AL_INVALID_VALUE);
    }

    ProcessContext(pContext);
}
Example #25
0
// -------------------  LoadSound -------------------------
static ALuint LoadSound(const char* name)
{
	SDL_AudioSpec wav_spec;
	Uint32 wav_length;
	Uint8 *wav_buffer;
	if (SDL_LoadWAV(name, &wav_spec, &wav_buffer, &wav_length) == NULL) {
		ERR("LoadSound(%s): SDL_LoadWAV failed: %s\n", name, SDL_GetError());
		return 0;
	}

	ALenum format = 0;
	if (wav_spec.channels == 1) {
		switch(wav_spec.format) {
		case AUDIO_U8:			format = AL_FORMAT_MONO8; break;
		case AUDIO_S16LSB:		format = AL_FORMAT_MONO16; break;
		case AUDIO_F32LSB:		format = AL_FORMAT_MONO_FLOAT32; break;
		}
	} else if (wav_spec.channels == 2) {
		switch(wav_spec.format) {
		case AUDIO_U8:			format = AL_FORMAT_STEREO8; break;
		case AUDIO_S16LSB:		format = AL_FORMAT_STEREO16; break;
		case AUDIO_F32LSB:		format = AL_FORMAT_STEREO_FLOAT32; break;
		}
	}

	if (format == 0) {
		// TODO: if needed, more channels / other formats.
		ERR("LoadSound(%s): Unsupported format (TODO): 0x%X\n", name, wav_spec.format);
		SDL_FreeWAV(wav_buffer);
		return 0;
	}

	ALuint buffer;
	alGenBuffers(1, &buffer);
	alBufferData(buffer, format, wav_buffer, wav_length, wav_spec.freq);
	SDL_FreeWAV(wav_buffer);

	ALenum err = alGetError();
	if(err != AL_NO_ERROR)
	{
		ERR("LoadSound(%s): alBufferData Error: %s\n", name, alGetString(err));
		if(alIsBuffer(buffer))
			alDeleteBuffers(1, &buffer);
		return 0;
	}

	return buffer;
}
Example #26
0
void  cargar_sonido ( char *fichero_wav, int identificador ){

	/* Variables locales */

	FILE *fichero;
	SDL_RWops *file;
	char filename[LON_BUFF];
	SDL_AudioSpec wav_spec;
	Uint32 size;
	Uint8 *data;

	/* Generamos buffer, le asignamos un identificador y comprobamos errores */
	alGenBuffers( 1, &buffer[identificador] );
	if ( !alIsBuffer ( buffer[identificador] )){
		log_msj ( "[KO] error al crear los buffers\n");
	}

	/* Establecemos donde estara situado el directorio para los sonidos */
	strcpy(filename, "sonidos");
	strcat(filename, "/");
	strcat(filename, fichero_wav);
	log_msj("[efectos.c] Cargando sonido %s\n", filename);

	/* Cargamos ficheros Wave */
	fichero = abre_fichero(filename, "rb");
	file = SDL_RWFromFP(fichero,0);
	if( SDL_LoadWAV_RW(file,1, &wav_spec,&data,&size)== NULL ){
		log_msj("[KO]Error al cargar %s\n",filename);
		return;
	}
	alBufferData ( buffer[identificador], AL_FORMAT_STEREO16, data, size, wav_spec.freq ); /* Almacenamos en buffer */
	SDL_FreeWAV(data);/*Liberamos*/
	fclose(fichero);


	/* Generamos las fuentes de sonido y comprobamos errores */
	alGenSources( 1, &source[identificador] );
	if ( !alIsSource ( source[identificador])){
		log_msj ("[KO] No se pueden crear las fuentes de sonido\n");
	}

	/* Pasamos el archivo wav del buffer a la fuente */
	alSourcei ( source[identificador], AL_BUFFER, buffer[identificador]);

}
Example #27
0
/* Function: alureBufferDataFromFile
 *
 * Loads the given file into an existing OpenAL buffer object. The previous
 * contents of the buffer are replaced. Requires an active context.
 *
 * Returns:
 * AL_FALSE on error.
 *
 * See Also:
 * <alureCreateBufferFromFile>
 */
ALURE_API ALboolean ALURE_APIENTRY alureBufferDataFromFile(const ALchar *fname, ALuint buffer)
{
    if(alGetError() != AL_NO_ERROR)
    {
        SetError("Existing OpenAL error");
        return AL_FALSE;
    }

    if(!buffer || !alIsBuffer(buffer))
    {
        SetError("Invalid buffer ID");
        return false;
    }

    if(load_stream(create_stream(fname), buffer) == false)
        return AL_FALSE;
    return AL_TRUE;
}
Example #28
0
/** Initialises the sfx. 
 */
bool SFXOpenAL::init()
{
    m_status = SFX_UNKNOWN;

    alGenSources(1, &m_sound_source );
    if (!SFXManager::checkError("generating a source"))
        return false;

    assert( alIsBuffer(m_sound_buffer->getBufferID()) );
    assert( alIsSource(m_sound_source) );

    alSourcei (m_sound_source, AL_BUFFER, m_sound_buffer->getBufferID());

    if (!SFXManager::checkError("attaching the buffer to the source"))
        return false;

    alSource3f(m_sound_source, AL_POSITION,       0.0, 0.0, 0.0);
    alSource3f(m_sound_source, AL_VELOCITY,       0.0, 0.0, 0.0);
    alSource3f(m_sound_source, AL_DIRECTION,      0.0, 0.0, 0.0);

    alSourcef (m_sound_source, AL_ROLLOFF_FACTOR, m_sound_buffer->getRolloff());
    alSourcef (m_sound_source, AL_MAX_DISTANCE,   m_sound_buffer->getMaxDist());

    if (m_gain < 0.0f)
    {
        alSourcef (m_sound_source, AL_GAIN, m_default_gain * m_master_gain);
    }
    else
    {
        alSourcef (m_sound_source, AL_GAIN, m_gain * m_master_gain);
    }

    if (m_positional) alSourcei (m_sound_source, AL_SOURCE_RELATIVE, AL_FALSE);
    else              alSourcei (m_sound_source, AL_SOURCE_RELATIVE, AL_TRUE);

    alSourcei(m_sound_source, AL_LOOPING, m_loop ? AL_TRUE : AL_FALSE);

    if(!SFXManager::checkError("setting up the source"))
        return false;

    m_status = SFX_STOPPED;
    return true;
}   // init
Example #29
0
ALAPI ALvoid ALAPIENTRY alSourceQueueBuffers (ALuint source, ALsizei n, ALuint *buffers)
{
    int i;
    
	if (alIsSource(source))
	{
#ifdef MAC_OS_X
                LockBufs();
#endif
		for (i = 0; i < n; i++)
		{
			if ((alIsBuffer(buffers[i])) || (buffers[i] == NULL))
			{
				alQueuei(source, AL_BUFFER, buffers[i]);
			}
		}
#ifdef MAC_OS_X
                UnlockBufs();
#endif
	}
}
Example #30
0
void  CargaSonido (  char *fichero_wav, int identificador ){

	/* Variables locales */
	ALsizei size = NULL, freq = NULL, bits = NULL, format = NULL;
	ALenum format1 = NULL;
	static void *data = NULL;
	ALboolean loop = AL_FALSE;

	/* Generamos buffer, le asignamos un identificador y comprobamos errores */
	alGenBuffers( 1, &buffer[identificador] );
	if ( !alIsBuffer ( buffer[identificador] )){
		fprintf ( logs, "error al crear los buffers\n");
		exit(1);
	}

	/* Cargamos ficheros Wave */
#ifdef _LINUX
	alutLoadWAV ( fichero_wav, &data, &format, &size, &bits, &freq ); /* Cargamos en memoria */
	alBufferData ( buffer[identificador], format, data, size, freq ); /* Almacenamos en buffer */
	free (data); /* liberamos */
#endif
#ifdef _WIN32
	alutLoadWAVFile ( fichero_wav, &format1, &data, &size, &freq, &loop );
	alBufferData ( buffer[identificador], format1, data, size, freq );
	alutUnLoadWAV ( format1, data, size, freq );
#endif

	/* Generamos las fuentes de sonido y comprobamos errores */
	alGenSources( 1, &source[identificador] );
	if ( !alIsSource ( source[identificador])){
		fprintf ( logs, "No se pueden crear las fuentes de sonido\n");
		exit(1);
	}

	/* Pasamos el archivo wav del buffer a la fuente */
	alSourcei ( source[identificador], AL_BUFFER, buffer[identificador]);

}