Esempio n. 1
0
sound_player::sound_player()
{
  alutInit(NULL,NULL);
  #ifdef __APPLE__
  ALsizei size, freq;
  ALenum format;
  ALvoid *data;

  alutLoadWAVFile("sounds/pew.wav", &format, &data, &size, &freq);
  alBufferData(buffers[PEW], format, data, size, freq);
  alutUnloadWAV(format,data,size,freq);

  alutLoadWAVFile("sounds/blast.wav", &format, &data, &size, &freq);
  alBufferData(buffers[BLAST], format, data, size, freq);
  alutUnloadWAV(format,data,size,freq);

  #elif __linux__ || _WIN32 || _WIN64
  buffers[PEW] = alutCreateBufferFromFile("sounds/pew.wav");
  buffers[BLAST] = alutCreateBufferFromFile("sounds/blast.wav");
  #endif


  //alGenSources(1,&source);
  alGenSources(SOUNDS,sources);

  alSourcei(sources[PEW],AL_BUFFER,buffers[PEW]);
  alSourcei(sources[PEW],AL_LOOPING,AL_FALSE);

  alSourcei(sources[BLAST],AL_BUFFER,buffers[BLAST]);
  alSourcei(sources[BLAST],AL_LOOPING,AL_FALSE);
}
Esempio n. 2
0
void init(int ini)
{
  if(ini) {
    alutInit(0, NULL);
  }

  alListenerfv(AL_POSITION,listenerPos);
  alListenerfv(AL_VELOCITY,listenerVel);
  alListenerfv(AL_ORIENTATION,listenerOri);
  
  alGetError(); // clear any error messages

  // Generate buffers, or else no sound will happen!
  alGenBuffers(NUM_BUFFERS, buffer);

  if(alGetError() != AL_NO_ERROR) {
      kerror(TRUE, "- Error creating buffers !!\n");
  }
    
  alutLoadWAVFile(reinterpret_cast<ALbyte*>(const_cast<char *>(HOME_DIR"1.wav")),&format,&data,&size,&freq,0);
  alBufferData(buffer[0],format,data,size,freq);
  alutUnloadWAV(format,data,size,freq);
  
  alutLoadWAVFile(reinterpret_cast<ALbyte*>(const_cast<char *>(HOME_DIR"2.wav")),&format,&data,&size,&freq,0);
  alBufferData(buffer[1],format,data,size,freq);
  alutUnloadWAV(format,data,size,freq);

  alutLoadWAVFile(reinterpret_cast<ALbyte*>(const_cast<char *>(HOME_DIR"3.wav")),&format,&data,&size,&freq,0);
  alBufferData(buffer[2],format,data,size,freq);
  alutUnloadWAV(format,data,size,freq);

  alGetError(); /* clear error */
  alGenSources(NUM_SOURCES, source);

  if(alGetError() != AL_NO_ERROR) {
    kerror(TRUE,"- Error creating sources !!\n");
  }

  int i;
  for(i = 0; i < NUM_SOURCES; i++) {
    alSourcef(source[i],AL_PITCH,1.0f);
    alSourcef(source[i],AL_GAIN,1.0f);
    alSourcefv(source[i],AL_POSITION,pos);
    alSourcefv(source[i],AL_VELOCITY,vel);
    alSourcei(source[i],AL_BUFFER,buffer[i]);
    alSourcei(source[i],AL_LOOPING,AL_TRUE);
  }
}
Esempio n. 3
0
unsigned int CSoundManager::LoadSoundWAV(std::string name)
{
	ALenum     format, error;
	ALsizei    size;
	ALsizei    freq;
	ALboolean  loop;
	ALvoid*    data;

	alutLoadWAVFile((ALbyte *)name.c_str(), &format, &data, &size, &freq, &loop);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		CLogManager::Instance()->LogMessage("Error loading sound : " + GetSoundError(error) );
		return 0;
	}

	alBufferData(m_iBuffers[m_iSoundCount],format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		CLogManager::Instance()->LogMessage("Error loading sound : " + GetSoundError(error) );
		return 0;
	}

	alutUnloadWAV(format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		CLogManager::Instance()->LogMessage("Error loading sound : " + GetSoundError(error) );
		return 0;
	}

	return m_iBuffers[m_iSoundCount++];
}
Esempio n. 4
0
Sound::Sound(string filename, Options* options)
{
	ALenum format;
	ALsizei size;
	ALsizei freq;
	ALboolean loop;
	ALvoid* data;
	ALuint error;

	this->options = options;

	alGenBuffers(1, &(this->buffer));
	if(!checkError(__func__)) return;

	alutLoadWAVFile((ALbyte*) filename.c_str(), &format, &data, &size, &freq, &loop);
	if(!checkError(__func__)) return;


	alBufferData(this->buffer, format, data, size, freq);
	if(!checkError(__func__)) return;

	alutUnloadWAV(format,data,size,freq);
	if(!checkError(__func__)) return;


	alGenSources(1, &(this->source));
	if(!checkError(__func__)) return;

	alSourcei(source, AL_BUFFER, buffer);
	if(!checkError(__func__)) return;
}
Esempio n. 5
0
void AudioManager::load_sounds() {
  if (loaded_) {
		std::cout << "SoundManager: Error - sounds already loaded" << std::endl;
		return;
	}
  
  // For now, assuming one sound (buffer) per source
  int sound_count = sound_names_.size();
  unsigned int source_indicies[sound_count];
  unsigned int buffer_indicies[sound_count];
  alGenBuffers(sound_count, buffer_indicies);
  alGenSources(sound_count, source_indicies);
  
  ALenum     format;
  ALsizei    size;
  ALsizei    freq;
  ALboolean  loop;
  ALvoid*    data;
    
  for (int j = 0; j < sound_count; ++j) {
    // TODO Evil, evil casting here
    alutLoadWAVFile(reinterpret_cast<ALbyte*>(const_cast<char*>(sound_names_[j].c_str())), &format, &data, &size, &freq, &loop);
    alBufferData(buffer_indicies[j], format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);
    Sound::ShPtr s(new Sound(sound_names_[j], source_indicies[j], buffer_indicies[j]));
    sounds_.push_back(s);
	}
}
Esempio n. 6
0
AudioTrack::AudioTrack(std::string filename, Ogre::Real startTime) :
startTime(startTime) {
	int error;
	
	// clear Error
	alGetError();
	
	std::cout << "Creating the buffers" << std::endl;	
	// Create the buffers
	alGenBuffers(1, buffers);
	if ((error = alGetError()) != AL_NO_ERROR) {
		std::cout << "alGenBuffers : " << error << std::endl;
		exit(0);
	}
	
	
	std::cout << "Loading the sound..." << std::endl;
	ALenum     format;
	ALsizei    size;
	ALsizei    freq;
	ALboolean  loop;
	ALvoid*    data;

/* ****Problem mit XCode-Update **/
	ALbyte* file = (ALbyte*) filename.c_str();
	#ifdef OSX
	alutLoadWAVFile(file, &format, &data, &size, &freq);//, &loop);
	#else
	alutLoadWAVFile(file, &format, &data, &size, &freq, &loop);
	#endif
	//loadWAVFile(file, &format, &data, &size, &freq);//, &loop);
	if ((error = alGetError()) != AL_NO_ERROR) {
		std::cout << "alutLoadWAVFile : " << error << std::endl;
		// Delete Buffers
		alDeleteBuffers(1, buffers);
		exit(0);
	}
	
	
	std::cout << "Filling Buffer..." << std::endl;
	alBufferData(buffers[0],format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR) {
		std::cout << "alBufferData buffer 0 : " << error << std::endl;
		// Delete buffers
		alDeleteBuffers(1, buffers);
		exit(0);
	}
	
	
	std::cout << "Freeing Audio-File..." << std::endl;
	alutUnloadWAV(format,data,size,freq);
	//unloadWAV(format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR) {
		std::cout << "alutUnloadWAV : " << error << std::endl;
		// Delete buffers
		alDeleteBuffers(1, buffers);
		exit(0);
	}
	/** ENDE VOM PROBLEM!*/
}
Esempio n. 7
0
void Audio::deleteSound(const SoundID sound){
	if (sounds[sound].samples){
		alDeleteBuffers(1, &sounds[sound].buffer);

		alutUnloadWAV(sounds[sound].format, sounds[sound].samples, sounds[sound].size, sounds[sound].sampleRate);
		//delete sound.samples;
		sounds[sound].samples = NULL;
	}
}
Esempio n. 8
0
system::sound_id system::load_wav(const std::string& filename)
{
    sound_id bad_id = -1;
    
    sound_info  buffer;
    
    ALenum    format;
    ALvoid*   data;
    ALsizei   size;
    ALsizei   freq;
    ALboolean loop;
    ALuint    buf_id = 0;
    
    buffer.m_filename = filename;
    sound_buffers::const_iterator end_it = m_d->m_buffers->end();
    for(sound_buffers::const_iterator it = m_d->m_buffers->begin(); it != end_it; ++it) {
        if(it->second.m_filename == filename) {
            buf_id = it->first;
            break;
        }
    }
    
    if(!buf_id) {
        alGenBuffers(1, &buffer.m_id);
        if(!check_al_error()) {
            return false;
        }
        alutLoadWAVFile((ALbyte *)filename.c_str(), &format, &data, &size, &freq, &loop);
        if (!check_al_error()) {
            return bad_id;
        }
        
        buffer.m_format = format;
        buffer.m_rate   = freq;
        
        alBufferData(buffer.m_id, format, data, size, freq);
        if (!check_al_error()) {
            return bad_id;
        }
        
        alutUnloadWAV(format, data, size, freq);
        if (!check_al_error()) {
            return bad_id;
        }
        m_d->m_buffers->insert(sound_buffers::value_type(buf_id, buffer));
    }
    else {
        buffer = (*m_d->m_buffers)[buf_id];
    }
    
    return buffer.m_id;
}
Esempio n. 9
0
int loadWavFile(char* emplacementFichierWav) {
	// Partie OpenAL

	alutInit(NULL, 0);
	alGetError();

	// Variables to load into.
	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop;
	// Load wav data into a buffer.
	alGenBuffers(1, &Buffer);

	if(alGetError() != AL_NO_ERROR)
	{
		printf("Error loading data.");
		return 0;
	}

	//Loading wave file
	alutLoadWAVFile((ALbyte*)emplacementFichierWav, &format, &data, &size,&freq, &loop);
	alBufferData(Buffer, format, data, size, freq);
	alutUnloadWAV(format, data, size, freq);

	// Bind the buffer with the source.
	alGenSources(1, &Source);

	if(alGetError() != AL_NO_ERROR)
	{
		printf("Error loading data.");
		return 0;
	}


	alSourcei (Source, AL_BUFFER,   Buffer   );
	alSourcef (Source, AL_PITCH,    1.0      );
	alSourcef (Source, AL_GAIN,     1.0      );

	//Mise en place de la position de la source
	alSourcefv(Source, AL_POSITION, SourcePos);
	alSourcefv(Source, AL_VELOCITY, SourceVel);
	alSourcei (Source, AL_LOOPING,  loop     );

	//Mise en place de la position
	alListenerfv(AL_POSITION,    ListenerPos);
	alListenerfv(AL_VELOCITY,    ListenerVel);
	alListenerfv(AL_ORIENTATION, ListenerOri);
	return 1;
}
ALboolean SoundManager::loadALData()
{
      // Variables to load into.

  ALenum format;
  ALsizei size;
  ALvoid* data;
  ALsizei freq;
  ALboolean loop;

   // Load wav data into a buffer.

  alGenBuffers(1, &Buffer);

  if(alGetError() != AL_NO_ERROR)
    return AL_FALSE;

  alutLoadWAVFile((ALbyte*)file.c_str(), &format, &data, &size, &freq, &loop);
  alBufferData(Buffer, format, data, size, freq);
  alutUnloadWAV(format, data, size, freq);

      // Bind the buffer with the source.

  alGenSources(1, &Source);

  if(alGetError() != AL_NO_ERROR)
  {
    std::cerr<<"Error loading data."<<std::endl;
    return AL_FALSE;
  }

  alSourcei (Source, AL_BUFFER,   Buffer   );
  alSourcef (Source, AL_PITCH,    1.0      );
  alSourcef (Source, AL_GAIN,     2.0      );
  alSourcefv(Source, AL_POSITION, SourcePos);
  alSourcefv(Source, AL_VELOCITY, SourceVel);
  alSourcei (Source, AL_LOOPING,  loop     );

      // Do another error check and return.

  if(alGetError() == AL_NO_ERROR)
  {
    std::cerr<<"Successfully loaded data."<<std::endl;
    return AL_TRUE;
  }

  std::cerr<<"Error loading data."<<std::endl;

  return AL_FALSE;
}
Esempio n. 11
0
void CsAudioManager::LoadBuffer(ALbyte* fileName, int no) {
    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;
    // Load wav data into a buffer.
    if (alGetError() != AL_NO_ERROR)
        return;

    alutLoadWAVFile(fileName, &format, &data, &size, &freq, &loop);
    alBufferData(Buffer[no], format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);
}
Esempio n. 12
0
void CSoundWave::load(){
	ALuint buffer = newBuffer();
	CFile f(getName());
	f.loadData();

	ALsizei size,freq;
	ALenum	format;
	ALvoid	*data;
	ALboolean loop;

	alutLoadWAVMemory((ALbyte *)f.getData(),&format,&data,&size,&freq,&loop);
	//alutLoadWAVFile((ALbyte *)name.c_str(),&format,&data,&size,&freq,&loop);
	alBufferData(buffer,format,data,size,freq);
	alutUnloadWAV(format,data,size,freq);
}
Esempio n. 13
0
File: bind.cpp Progetto: Qard/jsgame
Handle<Value> ALUTUnloadWAVCallback(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();
	String::Utf8Value value1(args[1]);
	char* key1 = *value1;
	void* arg1 = font_[key1];

	//make call
	alutUnloadWAV((ALenum)arg0, (ALvoid*)arg1, (ALsizei)arg2, (ALsizei)arg3);
	
	return v8::Undefined();
}
Esempio n. 14
0
/*
--==================================================================--
-- Function:	loadMusic
-- Edited By:	Brian McGlauflin
-- Modified:	Mar 5, 2007
-- Parameters:	filename of music file to load (char *)
-- Returns:		
-- Description:	Loads a musicfile into the manager so it can be played.
--==================================================================--
*/
ALboolean MusicManager::loadMusic(char* filename) {
	ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;
		
    alGenBuffers(1, &buffer);
	if (alGetError() != AL_NO_ERROR) {
		engine.logger.printlog("  Music: ERROR generating buffer for ");
		engine.logger.printlnlog(filename);
        return AL_FALSE;
	}

    alutLoadWAVFile(filename, &format, &data, &size, &freq, &loop);
    alBufferData(buffer, format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

	// Bind buffer with a source.
    alGenSources(1, &source);

	if (alGetError() != AL_NO_ERROR) {
		engine.logger.printlog("  Music: ERROR generating source for ");
		engine.logger.printlnlog(filename);
        return AL_FALSE;
	}

    alSourcei (source, AL_BUFFER,   buffer   );
    alSourcef (source, AL_PITCH,    1.0f     );
    alSourcef (source, AL_GAIN,     1.0f     );
    alSourcefv(source, AL_POSITION, sourcePos);
    alSourcefv(source, AL_VELOCITY, sourceVelocity);
    alSourcei (source, AL_LOOPING,  AL_TRUE     );
	
	// Do another error check and return.
	if (alGetError() != AL_NO_ERROR) {
		engine.logger.printlog("  Music: ERROR setting up source for ");
		engine.logger.printlnlog(filename);
        return AL_FALSE;
	}

	char str[101];
	sprintf_s(str, "  Music: Loaded music file '%s'", filename);
	engine.logger.printlnlog(str);

    return AL_TRUE;
}
Esempio n. 15
0
int	OpenALSampler::loadWaveBuffer (char* _fileName, ALuint _buffer)
{
	int			error;
	ALenum		format;
	ALsizei		size;
	ALsizei		freq;
	ALboolean	loop;
	ALvoid*		data;

	FILE *File=NULL;
	File=fopen(_fileName,"r");
	if (File)
	{
		// Carregar arquivo
		alutLoadWAVFile((ALbyte*) _fileName, &format, &data, &size, &freq, &loop);
		if ((error = alGetError()) != AL_NO_ERROR)
		{
			displayOpenALError("alutLoadWAVFile : ", error);
			return 0;
		}
	}
	else
	{
		printf("\n%s - Arquivo inexistente ou em uso.", _fileName);
		return 0;
	}


	// Carregar dados do arquivo no buffer.
	alBufferData(_buffer,format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		displayOpenALError("alBufferData :", error);
		return 0;
	}

	// Liberar memoria usada para carregar arquivo.
	alutUnloadWAV(format,data,size,freq);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		displayOpenALError("alutUnloadWAV :", error);
		return 0;
	}

	return 1;
}
Esempio n. 16
0
/* *************** Load WAV file into Buffer *****************/
int SoundManager::LoadWav(char* file) {
  if(nBuffers >= MAX_BUFFERS - 1) std::cerr << "Out of sources" << std::endl;

  ALenum     format;
  ALsizei    size;
  ALsizei    frequency;
  ALboolean  loop;
  ALvoid*    data;

  // Read in WAV data to buffer and delete temporary array used to
  // load the data. 
  AL_CHECK_ERR(alutLoadWAVFile(reinterpret_cast<ALbyte*>(file), &format, &data, &size, 
        &frequency, &loop));
  AL_CHECK_ERR(alBufferData(buffers[nBuffers], format, data, size, frequency));
  AL_CHECK_ERR(alutUnloadWAV(format, data, size, frequency));
  return nBuffers++;
}
Esempio n. 17
0
void AudioManager::initAL()
{
	ALfloat listenerPos[]={0.0,0.0,0.0};
	ALfloat listenerVel[]={0.0,0.0,0.0};
	ALfloat listenerOri[]={0.0,0.0,0.0, 0.0,0.0,0.0}; // "at", then "up"
	ALsizei size,freq;
	ALenum	format;
	ALvoid	*data;
	ALboolean loop;

	//Load sound files which are stored insided "sound" folder in the current directory
	char* audioFiles[NUM_BUFFERS] = {

		".\\sound\\1.wav", ".\\sound\\2.wav", ".\\sound\\3.wav", ".\\sound\\4.wav", 
		".\\sound\\5.wav", ".\\sound\\6.wav", ".\\sound\\7.wav", ".\\sound\\8.wav",
		".\\sound\\9.wav", ".\\sound\\10.wav", ".\\sound\\11.wav", ".\\sound\\12.wav", 
		".\\sound\\13.wav", ".\\sound\\14.wav", ".\\sound\\15.wav", ".\\sound\\16.wav",
		".\\sound\\17.wav", ".\\sound\\18.wav", ".\\sound\\19.wav", ".\\sound\\20.wav", 
		".\\sound\\21.wav", ".\\sound\\22.wav", ".\\sound\\23.wav", ".\\sound\\24.wav"

	};

	ALuint g_Buffers[NUM_BUFFERS];

	// Initialize OpenAL
	alutInit(0, 0);
	int alError = alGetError();

	// Generate Buffers
	alGenBuffers(NUM_BUFFERS, g_Buffers);

	//audio buffers for each chord
	for (ALuint k=0; k < NUM_BUFFERS; k++) {
		alutLoadWAVFile(audioFiles[k],&format,&data,&size,&freq,&loop);
		alBufferData(g_Buffers[k],format,data,size,freq);
		alutUnloadWAV(format,data,size,freq);
	}

	// Generate Sources
	alGenSources(NUM_BUFFERS,soundClip);
	for (ALuint r=0; r < NUM_BUFFERS; r++) {
		alSourcei(soundClip[r], AL_BUFFER, g_Buffers[r]);
	}

}
Esempio n. 18
0
bool SoundManager::_loadSound(const std::string& file, IdBuffer& buffer)
{
	// Variables to load into.
	FILE *fd;
	ALenum format;
	ALenum error;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop;

	// Load wav data into buffers.
	alGenBuffers(1, &buffer);

	if((error=alGetError()) != AL_NO_ERROR)
	{	
		alDeleteBuffers(1,&buffer);
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::_loadSound","Error: Can't create openAL Buffer (" + GetALErrorString(error,false)  + ")",LOGEXCEPTION);	
		return false;	
	}

	// Check if the file exists
	if ((fd = fopen(file.c_str(),"r"))==NULL)
	{
		alDeleteBuffers(1,&buffer);
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::_loadSound","Error: Can't open file " + file,LOGEXCEPTION);			
		return false;
	}
	else
	{
		fclose(fd);
	}

	alutLoadWAVFile((ALbyte*)file.c_str(), &format, &data, &size, &freq, &loop);
	alBufferData(buffer, format, data, size, freq);
	alutUnloadWAV(format, data, size, freq);
	if ((error=alGetError()) != AL_NO_ERROR)
	{		
		alDeleteBuffers(1,&buffer);
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::_loadSound","Error: Can't load sound file " + file + " (" + GetALErrorString(error,false)  + ")",LOGEXCEPTION);			
		return false;
	}		
	return true;
}
Esempio n. 19
0
void Sound3D::main1 ()
{


	// Initialize OpenAL and clear the error bit.

	alutInit(NULL, 0);
	alGetError();

	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop = AL_TRUE;
	alutLoadWAVFile("BuzzingBee.wav", &format, &data, &size, &freq, &loop);
	alGenBuffers(1, &Buffer);
	alBufferData(Buffer, format, data, size, freq);
	alutUnloadWAV(format, data, size, freq);


}
Esempio n. 20
0
OPAL_SOUND_MGR void SoundManager::testSound( const char* wavFile )
{
	ALuint buffer;
	ALuint source;
	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop;
	alGenBuffers( 1, &buffer );
	if ( checkALError( "testSound()" ) )
		return;

	// This is the same for alutLoadWAVMemory
#ifndef MACINTOSH_AL
	alutLoadWAVFile( (ALbyte*) wavFile, &format, &data, &size, &freq, &loop );
#else
	alutLoadWAVFile( (ALbyte*) wavFile, &format, &data, &size, &freq );
#endif

	alBufferData( buffer, format, data, size, freq );

	alutUnloadWAV( format, data, size, freq );
	alGenSources( 1, &source );
	alSourcei( source, AL_BUFFER, buffer );
	alSourcef( source, AL_PITCH, 1.0f );
	alSourcef( source, AL_GAIN, 1.0f );

#ifndef MACINTOSH_AL
	alSourcei( source, AL_LOOPING, loop );
#else
	alSourcei( source, AL_LOOPING, false ); // TODO ! But how to get from file?
#endif

	alSourcePlay( source );

	//Or else we risk to destroy the manager too quickly to here anything !
	for (int i=0;i<50000; i++) {printf(".");};
}
Esempio n. 21
0
OPAL_SOUND_MGR bool SoundManager::loadWAV( std::string filename, ALuint pDestAudioBuffer )
{
	ALenum      format;         //for the buffer format
	ALsizei      size;         //the bit depth
	ALsizei      freq;         //for the frequency of the buffer
	ALboolean   loop;         //looped
	ALvoid*      data;         //data for the buffer

	std::string mFullPath = mAudioPath;

	alGetError();   // Clear Error Code

	// Load in the WAV file from disk
	//mFullPath += "\\";
	mFullPath += filename;

#ifndef MACINTOSH_AL
	alutLoadWAVFile( (ALbyte*)mFullPath.c_str(), &format, &data, &size, &freq, &loop);
#else
	alutLoadWAVFile( (ALbyte*)mFullPath.c_str(), &format, &data, &size, &freq);
#endif

	if ( checkALError("loadWAV::alutLoadWAVFile: ") )
		return false;

	// Copy the new WAV data into the buffer
	alBufferData(pDestAudioBuffer, format, data, size, freq);
	if ( checkALError("loadWAV::alBufferData: ") )
		return false;

	// Unload the WAV file
	alutUnloadWAV(format, data, size, freq);
	if ( checkALError("loadWAV::alutUnloadWAV: ") )
		return false;

	return true;
}
Esempio n. 22
0
ALboolean loadALData()
{
    // Variables to load into.

    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;

    // Load wav data into buffers.

    alGenBuffers(NUM_BUFFERS, Buffers);

    if (alGetError() != AL_NO_ERROR)
        return AL_FALSE;

    alutLoadWAVFile("Data/loop.wav", &format, &data, &size, &freq, &loop);
    alBufferData(Buffers[LOOP], format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

    alutLoadWAVFile("Data/minestep.wav", &format, &data, &size, &freq, &loop);
    alBufferData(Buffers[MINE], format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

    alutLoadWAVFile("Data/alarm001.wav", &format, &data, &size, &freq, &loop);
    alBufferData(Buffers[WARNING], format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

    // Bind buffers into audio sources.

    alGenSources(NUM_SOURCES, Sources);

    if (alGetError() != AL_NO_ERROR)
        return AL_FALSE;

    alSourcei (Sources[LOOP], AL_BUFFER,   Buffers[LOOP]  );
    alSourcef (Sources[LOOP], AL_PITCH,    1.0              );
    alSourcef (Sources[LOOP], AL_GAIN,     1.0              );
    alSourcefv(Sources[LOOP], AL_POSITION, SourcePos[LOOP]);
    alSourcefv(Sources[LOOP], AL_VELOCITY, SourceVel[LOOP]);
    alSourcei (Sources[LOOP], AL_LOOPING,  AL_TRUE          );

    alSourcei (Sources[MINE], AL_BUFFER,   Buffers[MINE]  );
    alSourcef (Sources[MINE], AL_PITCH,    1.0            );
    alSourcef (Sources[MINE], AL_GAIN,     1.0            );
    alSourcefv(Sources[MINE], AL_POSITION, SourcePos[MINE]);
    alSourcefv(Sources[MINE], AL_VELOCITY, SourceVel[MINE]);
    alSourcei (Sources[MINE], AL_LOOPING,  AL_FALSE       );

    alSourcei (Sources[WARNING], AL_BUFFER,   Buffers[WARNING]  );
    alSourcef (Sources[WARNING], AL_PITCH,    1.0            );
    alSourcef (Sources[WARNING], AL_GAIN,     1.0            );
    alSourcefv(Sources[WARNING], AL_POSITION, SourcePos[WARNING]);
    alSourcefv(Sources[WARNING], AL_VELOCITY, SourceVel[WARNING]);
    alSourcei (Sources[WARNING], AL_LOOPING,  AL_FALSE       );

    // Do another error check and return.

    if( alGetError() != AL_NO_ERROR)
        return AL_FALSE;

    return AL_TRUE;
}
Esempio n. 23
0
CSound::CSound()
{
	// Позиция слушателя.
	ListenerPos[0] = 0.0;
	ListenerPos[1] = 0.0;
	ListenerPos[2] = 0.0;

	// Скорость слушателя.
	ListenerVel[0] = 0.0;
	ListenerVel[1] = 0.0;
	ListenerVel[2] = 0.0;

	// Ориентация слушателя. (Первые 3 элемента – направление «на», последние 3 – «вверх»)
	ListenerOri[0] =  0.0; 
	ListenerOri[1] =  0.0;
	ListenerOri[2] = -1.0;
	ListenerOri[3] =  0.0;
	ListenerOri[4] =  1.0;
	ListenerOri[5] =  0.0;

	pContext = alcGetCurrentContext();
	//pDevice = alcGetContextsDevice( pContext );
	if ( !pContext )
	{
		// Открываем заданное по умолчанию устройство
		pDevice = alcOpenDevice( 0 );

		if ( pDevice )
		{
			Log("Open sound device");
			pContext = 0;
			pContext = alcCreateContext( pDevice, 0 );
			if ( pContext )
				alcMakeContextCurrent( pContext );	// Делаем контекст текущим
			else
			{
				Log("Default sound contex not present");
				alcCloseDevice( pDevice );
				return;
			}
		}	
		else
		{
			Log("Default sound device not present");
			return;
		}
	}
	else 
		pDevice = alcGetContextsDevice( pContext );

	// Устанавливаем параметры слушателя
	// Позиция	
	alListenerfv( AL_POSITION,	  ListenerPos);
	// Скорость
	alListenerfv( AL_VELOCITY,    ListenerVel);
	// Ориентация
	alListenerfv( AL_ORIENTATION, ListenerOri);
	char		*filename_shot;
	char		*filename_Recharge;
	char		*filename_Fon;
	ALvoid		*p;
	ALsizei		size;
	ALsizei		rate; 
	ALenum		format;
	ALboolean	loop;

	filename_shot = "galil.wav";
	filename_Recharge = "ak47_clipout.wav";
	filename_Fon = "Gladiator.wav";


	/* Загрузить данные */
	alGenBuffers( 3, buffer );
	alGenSources( 3, source ); // создаём нужное количество буфферов

	alutLoadWAVFile( (ALbyte *) filename_shot, &format, &p, &size, &rate, &loop );
	alBufferData( buffer[0], format, p, size, rate );
	alutUnloadWAV( format, p, size, rate );

	alutLoadWAVFile( (ALbyte *) filename_Recharge, &format, &p, &size, &rate, &loop );
	alBufferData( buffer[1], format, p, size, rate );
	alutUnloadWAV( format, p, size, rate );

	alutLoadWAVFile( (ALbyte *) filename_Fon, &format, &p, &size, &rate, &loop );
	alBufferData( buffer[2], format, p, size, rate );
	alutUnloadWAV( format, p, size, rate );


	Play(2);
}
Esempio n. 24
0
int Audio::loadWav(Path file){
	engineTime.skipNextFrame();
	AudioSource* source=new AudioSource;

	source->type=AUDIO_WAV;
	source->filename=file;

	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean l;  //discarded
	
	// Load wav data into a buffer.

	alGetError();
	alGetError();
	alGetError();
	alGetError();
	alGetError();
	alGetError();

	alGenBuffers(1, &source->buffer);

	ALenum error=alGetError();

	if(error != AL_NO_ERROR){
		logs().audio.write("[AudioObject] Error loading file:"+file.getRelative()+", "+String(alGetString(error)));
		console().write("audio error: could not load file '"+file.getRelative()+"', "+String(alGetString(error)));
		return -1;
	}

	
	error=alGetError();
	

		alutLoadWAVFile((ALbyte*)file.getAbsolute().c_str(), &format, &data, &size, &freq, &l);

	
	if(format==AL_FORMAT_STEREO8 || format==AL_FORMAT_STEREO16){
		source->stereo=true;
	}else{
		source->stereo=false;
	}


	alBufferData(source->buffer, format, data, size, freq);
	alutUnloadWAV(format, data, size, freq);

	// Bind buffer with a source.

	error=alGetError();


	if(error != AL_NO_ERROR){
		logs().audio.write("[AudioObject] Error loading file:"+file.getRelative()+", "+String(alGetString(error)));
		console().write("audio error: could not loading file '"+file.getRelative()+"', "+String(alGetString(error)));
		return -1;
	}

	alGenSources(1, &source->source);

	
	
	if(error==AL_OUT_OF_MEMORY || error==AL_INVALID_VALUE){
		//there's not more resources for sources
		source->alSourceSet=false;
	}else if(error!=AL_NO_ERROR){
		return -1;
	}else{
		source->alSourceSet=true;
		alSources.pushBack(source->source);
		source->sourceIndex=sources.size()-1;
		alSourcePriority.pushBack(0);

		while(alSourceUsedBy.size()<=sources.size()){	//note, we haven't actually added this source to the sources list yet, thus the weird index
			alSourceUsedBy.pushBack();
		}
		alSourceUsedBy[alSources.size()-1]=sources.size();

		source->alSourceIndex=alSources.size()-1;
	}
	
	source->sourcePos[0]=source->pos.x;
	source->sourcePos[1]=source->pos.y;
	source->sourcePos[2]=source->pos.z;

	source->sourceVelocity[0]=source->velocity.x;
	source->sourceVelocity[1]=source->velocity.y;
	source->sourceVelocity[2]=source->velocity.z;
	
	
	if(source->alSourceSet){
		alSourcei (source->source, AL_BUFFER,   source->buffer   );
		alSourcef (source->source, AL_PITCH,    1.0f     );
		alSourcef (source->source, AL_GAIN,     1.0f     );

		if(!source->stream){
			alSourcei (source->source, AL_LOOPING,  source->loop     );
		}
	}
	
	
	// Do another error check and return.

	error=alGetError();

	if(error == AL_NO_ERROR){
		sources.pushBack(source);
		source->sourceIndex=sources.size()-1;
		return sources.size()-1;
	}else{

		logs().audio.write("[AudioObject] Error 2 loading file:"+file.getRelative());
		console().write(String("audio wav error: error '")+String(alGetString(error))+"' loading file '"+file.getRelative()+"'");
		return -1;
	}

}	
Esempio n. 25
0
struct SoundManager newSoundManager(struct Settings* settings)
{
    int i;
    struct SoundManager sm;
    sm.settings = settings;
    alutInit(NULL, 0);
    if(alGetError() != AL_NO_ERROR)
    {
        printf("newSoundManager: cannot initalize ALUT");
        return sm;
    }

    alGenBuffers(SOUND_COUNT, sm.buffers);
    alGenSources(SOUND_SOURCE_COUNT, sm.sources);

    char filenames[SOUND_COUNT][256] =
    {
        "music.wav",
        "click.wav",
        "crash.wav",
        "engine.wav"
    };

    ALfloat zeroVector[3]  = {0.0, 0.0, 0.0};
    ALfloat zeroVector6[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

    for(i=0;i<SOUND_COUNT;i++)
    {
        ALenum format;
        ALsizei size;
        ALvoid* data;
        ALsizei freq;
        ALboolean loop;

        alutLoadWAVFile(filenames[i], &format, &data, &size, &freq, &loop);
        alBufferData(sm.buffers[i], format, data, size, freq);
        alutUnloadWAV(format, data, size, freq);
    }

    for(i=0;i<SOUND_SOURCE_COUNT;i++)
    {
        if(SOUND_SOURCE_ENGINE1 == i || SOUND_SOURCE_ENGINE2 == i)
            alSourcei (sm.sources[i], AL_BUFFER,   sm.buffers[SOUND_ENGINE]);
        else
            alSourcei (sm.sources[i], AL_BUFFER,   sm.buffers[i]);
        alSourcef (sm.sources[i], AL_PITCH,    1.0);
        if(SOUND_SOURCE_MUSIC == i)
            alSourcef (sm.sources[i], AL_GAIN, settings->musicVolmue / 100.0);
        else
            alSourcef (sm.sources[i], AL_GAIN, settings->fxVolmue / 100.0);
        alSourcefv(sm.sources[i], AL_POSITION, zeroVector);
        alSourcefv(sm.sources[i], AL_VELOCITY, zeroVector);
        if(SOUND_SOURCE_CLICK == i || SOUND_SOURCE_CRASH == i)
            alSourcei (sm.sources[i], AL_LOOPING,  AL_FALSE);
        else
            alSourcei (sm.sources[i], AL_LOOPING,  AL_TRUE);
    }

    alListenerfv(AL_POSITION,    zeroVector);
    alListenerfv(AL_VELOCITY,    zeroVector);
    alListenerfv(AL_ORIENTATION, zeroVector6);

    return sm;
}
Esempio n. 26
0
/* ‘ункци¤ инициализации объекта анимации.
 * ј–√”ћ≈Ќ“џ:
 *   - указатель на "себ¤" - сам объект анимации:
 *       ok2UNIT_CUBE *Unit;
 *   - указатель на контекст анимации:
 *       ok2ANIM *Ani;
 * ¬ќ«¬–јўј≈ћќ≈ «Ќј„≈Ќ»≈: Ќет.
 */
static VOID CubeUnitInit( ok2UNIT_CUBE *Unit, ok2ANIM *Ani )
{
  INT format;
  UINT size, freq;
  VOID *mem;
  CHAR loop;

  alutInit(NULL, 0);
  alGetError();

  /* создаем буфера */
  alGenBuffers(2, Unit->SndBuf);

  /* загружаем звук в буфер */
  alutLoadWAVFile("a.wav", &format, &mem,
    &size, &freq, &loop);
  alBufferData(Unit->SndBuf[0], format, mem, size, freq);
  alutUnloadWAV(format, mem, size, freq);

  alutLoadWAVFile("a.wav", &format, &mem,
    &size, &freq, &loop);
  alBufferData(Unit->SndBuf[1], format, mem, size, freq);
  alutUnloadWAV(format, mem, size, freq);

  /* создаем источники звука и параметризируем их */
  alGenSources(2, Unit->SndSrc);

  alSourcei(Unit->SndSrc[0], AL_BUFFER, Unit->SndBuf[0]); /* закрепл¤ем буфер за источником */
  alSourcef(Unit->SndSrc[0], AL_PITCH, 0.5);      /* скорость воспроизведени¤: 1.0 - обычна¤*/
  alSourcef(Unit->SndSrc[0], AL_GAIN, 0.1);          /* громкость: 1.0 Ц обычна¤ */
  alSourcei(Unit->SndSrc[0], AL_LOOPING, 1);       /* флаг повтора: 0 Ц нет, 1 Ц бесконечно */

  alSourcei(Unit->SndSrc[1], AL_BUFFER, Unit->SndBuf[1]);
  alSourcef(Unit->SndSrc[1], AL_PITCH, 1.5);
  alSourcef(Unit->SndSrc[1], AL_GAIN, 0.1);
  alSourcei(Unit->SndSrc[1], AL_LOOPING, 0);
  //OK2_GeomLoad(&Unit->Geom, ".object");
  /*
  OK2_GeomLoad(&Unit->Geom[0], "imac\\imac.object");
  Unit->Scale[0] = 50.0;

  OK2_GeomLoad(&Unit->Geom[1], "Mustang\\Mustang.object"); 
  Unit->Scale[1] = 0.005;

  OK2_GeomLoad(&Unit->Geom[2], "Avent\\Avent.object");
  Unit->Scale[2] = 1.0;

  OK2_GeomLoad(&Unit->Geom[4], "Houses\\house1.object"); 
  Unit->Scale[4] = 1.0;

  OK2_GeomLoad(&Unit->Geom[5], "x6\\x6.object");  
  Unit->Scale[5] = 3.0;
  */
  OK2_GeomLoad(&Unit->Geom[3], "BMW_M3_GTR\\BMW_M3_GTR.object");    
  Unit->Scale[3] = 0.001;
  /*
  OK2_GeomLoad(&Unit->Geom[3], "MINICOOPER\\mini_obj.object");    
  Unit->Scale[3] = 0.001;
  */   
  /*
  OK2_GeomLoad(&Unit->Geom[3], "mord_fustang\\Shelby7..object");    
  Unit->Scale[3] = 0.001;
  */
} /* End of 'CubeUnitInit' function */
ALboolean LoadALData()
{
	// Variables to load into.

	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop;

	// Load wav data into buffers.

	alGenBuffers(NUM_BUFFERS, Buffers);

	if(alGetError() != AL_NO_ERROR)
		return AL_FALSE;

	alutLoadWAVFile("sound/hit.wav", &format, &data, &size, &freq, &loop);
	alBufferData(Buffers[hit], format, data, size, freq);
	alutUnloadWAV(format, data, size, freq);

//	alutLoadWAVFile("wavdata/Gun1.wav", &format, &data, &size, &freq, &loop);
//	alBufferData(Buffers[GUN1], format, data, size, freq);
//	alutUnloadWAV(format, data, size, freq);

//	alutLoadWAVFile("wavdata/Gun2.wav", &format, &data, &size, &freq, &loop);
//	alBufferData(Buffers[GUN2], format, data, size, freq);
//	alutUnloadWAV(format, data, size, freq);
	
	//alutLoadWAVFile("sound/dung.wav", &format, &data, &size, &freq, &loop);
	//alBufferData(Buffers[dung], format, data, size, freq);
	//alutUnloadWAV(format, data, size, freq);

	// Bind buffers into audio sources.

	alGenSources(NUM_SOURCES, Sources);

	if(alGetError() != AL_NO_ERROR)
		return AL_FALSE;



	//alSourcei (Sources[dung], AL_BUFFER,   Buffers[dung]   );
	//alSourcef (Sources[dung], AL_PITCH,    1.0f              );
	//alSourcef (Sources[dung], AL_GAIN,     1.0f              );
	//alSourcefv(Sources[dung], AL_POSITION, SourcesPos[dung]);
	//alSourcefv(Sources[dung], AL_VELOCITY, SourcesVel[dung]);
	//alSourcei (Sources[dung], AL_LOOPING,  AL_TRUE           );


	alSourcei (Sources[hit], AL_BUFFER,   Buffers[hit]   );
	alSourcef (Sources[hit], AL_PITCH,    1.0f              );
	alSourcef (Sources[hit], AL_GAIN,     1.0f              );
	alSourcefv(Sources[hit], AL_POSITION, SourcesPos[hit]);
	alSourcefv(Sources[hit], AL_VELOCITY, SourcesVel[hit]);
	alSourcei (Sources[hit], AL_LOOPING,  AL_FALSE           );
/*
	alSourcei (Sources[GUN1], AL_BUFFER,   Buffers[GUN1]   );
	alSourcef (Sources[GUN1], AL_PITCH,    1.0f            );
	alSourcef (Sources[GUN1], AL_GAIN,     1.0f            );
	alSourcefv(Sources[GUN1], AL_POSITION, SourcesPos[GUN1]);
	alSourcefv(Sources[GUN1], AL_VELOCITY, SourcesVel[GUN1]);
	alSourcei (Sources[GUN1], AL_LOOPING,  AL_FALSE        );

	alSourcei (Sources[GUN2], AL_BUFFER,   Buffers[GUN2]   );
	alSourcef (Sources[GUN2], AL_PITCH,    1.0f            );
	alSourcef (Sources[GUN2], AL_GAIN,     1.0f            );
	alSourcefv(Sources[GUN2], AL_POSITION, SourcesPos[GUN2]);
	alSourcefv(Sources[GUN2], AL_VELOCITY, SourcesVel[GUN2]);
	alSourcei (Sources[GUN2], AL_LOOPING,  AL_FALSE        );
*/
	// Do another error check and return.

	if(alGetError() != AL_NO_ERROR)
		return AL_FALSE;

	return AL_TRUE;
}
Esempio n. 28
0
/*
 * ALboolean LoadALData()
 *
 *	This function will load our sample data from the disk using the alut
 *	utility and send the data into OpenAL as a buffer. A source is then
 *	also created to play that buffer.
 */
int LoadSoundBuffers()
{
    int theerror=0;
	// Variables to load into.
    if (total_loaded_buffers==0) { fprintf(stderr,"No Sounds to load!\n");
                                   return 0; }

	ALenum format;
	ALsizei size;
	ALvoid* data;
	ALsizei freq;
	ALboolean loop;

	// Load wav data into buffers.
	alGenBuffers(total_loaded_buffers, Buffers);
	if(alGetError() != AL_NO_ERROR) { fprintf(stderr,"Error Generating Buffers!\n");
                                      return 0; }

    for (unsigned int i=0; i<total_loaded_buffers; i++)
      {
         alutLoadWAVFile((ALbyte *)filenames[i], &format, &data, &size, &freq, &loop);
         theerror=alGetError();
	     if(theerror != AL_NO_ERROR) { fprintf(stderr,"Error (%u) loading Wav sound Buffer %u %s\n",theerror,i,filenames[i]);   }

         alBufferData(Buffers[i], format, data, size, freq);
	     theerror=alGetError();
	     if(theerror != AL_NO_ERROR) { fprintf(stderr,"Error (%u) loading Wav sound Buffer %u %s\n",theerror,i,filenames[i]);   }

         alutUnloadWAV(format, data, size, freq);
	     theerror=alGetError();
	     if(theerror != AL_NO_ERROR) { fprintf(stderr,"Error (%u) loading Wav sound Buffer %u %s\n",theerror,i,filenames[i]);   }

	     free(filenames[i]); /* Release memory for filename */
      }
	// Bind buffers into audio sources.


	alGenSources(NUM_SOURCES, Sources);
    theerror=alGetError();
	if(theerror != AL_NO_ERROR) { fprintf(stderr,"Error Generating Sources (%u)!\n",theerror);
                                  return 0; }


    for (unsigned int i=0; i<total_loaded_buffers; i++)
      {
         /*alGenSources( 1, &Sources[i] );
         theerror=alGetError();
         if(theerror != AL_NO_ERROR) { cout<<"Error Generating Sources ("<<theerror<<")!\n";
                                       return false; }   */
         alSourcei (Sources[i], AL_BUFFER,   Buffers[i]   );
         alSourcef (Sources[i], AL_PITCH,    1.0f              );
         alSourcef (Sources[i], AL_GAIN,     1.0f              );
	     alSourcefv(Sources[i], AL_POSITION, SourcesPos[i]);
	     alSourcefv(Sources[i], AL_VELOCITY, SourcesVel[i]);
	     alSourcei (Sources[i], AL_LOOPING,  AL_FALSE           );
      }
	// Bind buffers into audio sources.


	// Do another error check and return.
	if(alGetError() != AL_NO_ERROR) return 0;

	SetListenerValues();

    return 1;
}
Esempio n. 29
0
//based on http://ffainelli.github.io/openal-example/
Sound::Sound(std::string path)
{
    int LOAD_OK = 1;
    ALenum  format;
    ALsizei size;
    ALvoid* data;
    ALfloat freq;

    if(alGetError() != AL_NO_ERROR)
        LOAD_OK = 0;

    audioBuffer = 0;
    audioSource = 0;

    if(LOAD_OK == 1)
    {
        alGenBuffers(1,&audioBuffer);
        if (alGetError() != AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(LOAD_OK == 1)
    {
        alGenSources(1,&audioSource);
        if(alGetError() != AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(LOAD_OK == 1)
    {
        data = alutLoadMemoryFromFile(path.c_str(),&format,&size,&freq);
        LOAD_OK =  (data!=NULL) ? 1:0;
    }

    if(LOAD_OK == 1)
    {
        alBufferData(audioBuffer, format, data, size, (ALsizei)freq);
        if(alGetError() != AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(LOAD_OK == 1)
    {
        // Unload the WAV file. It's not needed now.
        alutUnloadWAV(format, data, size,(ALsizei)freq);
        if(alGetError() != AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(LOAD_OK == 1)
    {
        alSourcei(audioSource,AL_BUFFER,audioBuffer);
        if (alGetError()!=AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(LOAD_OK == 1)
    {
        // Position of the source of the sound.
        ALfloat sourcePosition[] = { 0.0f, 0.0f, 0.0f };

        // Velocity of the source of the sound.
        ALfloat sourceVelocity[] = { 0.0f, 0.0f, 0.0f };

        alSourcef(audioSource, AL_PITCH, 1.0f);
        alSourcef(audioSource, AL_GAIN, 1.0f);
        alSourcefv(audioSource, AL_POSITION, sourcePosition);
        alSourcefv(audioSource, AL_VELOCITY, sourceVelocity);

        if(alGetError() != AL_NO_ERROR)
            LOAD_OK = 0;
    }

    if(!LOAD_OK)
    {
        printf("Failed to load sound: %s\n", path.c_str());
        loaded = false;
    } else {
        loaded = true;
    }
}
Esempio n. 30
-1
/*
 * ALboolean LoadALData()
 *
 *	This function will load our sample data from the disk using the Alut
 *	utility and send the data into OpenAL as a buffer. A source is then
 *	also created to play that buffer.
 */
ALboolean LoadALData()
{
    // Variables to load into.
    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;
    // Load wav data into a buffer.
    alGenBuffers(1, &Buffer);
    if(alGetError() != AL_NO_ERROR)
        return AL_FALSE;
    alutLoadWAVFile((ALbyte*)"wavdata/FancyPants.wav", &format, &data, &size, &freq, &loop);
    alBufferData(Buffer, format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);
    // Bind the buffer with the source.
    alGenSources(1, &Source);
    if(alGetError() != AL_NO_ERROR)
        return AL_FALSE;
    alSourcei (Source, AL_BUFFER,   Buffer   );
    alSourcef (Source, AL_PITCH,    1.0      );
    alSourcef (Source, AL_GAIN,     1.0      );
    alSourcefv(Source, AL_POSITION, SourcePos);
    alSourcefv(Source, AL_VELOCITY, SourceVel);
    alSourcei (Source, AL_LOOPING,  loop     );
    // Do another error check and return.
    if(alGetError() == AL_NO_ERROR)
        return AL_TRUE;
    return AL_FALSE;
}