Пример #1
0
int main(int argc, char **argv)
{
  /* Initialise ALUT and eat any ALUT-specific commandline flags. */
  if (!alutInit(&argc, argv))
  {
    ALenum error = alutGetError();

    fprintf(stderr, "%s\n", alutGetErrorString(error));
    exit(EXIT_FAILURE);
  }

  /* If everything is OK, play the sound files and exit when finished. */
  playFile("file1.wav");
  playFile("file2.au");
  playFile("file3.raw");

  if (!alutExit())
  {
    ALenum error = alutGetError();

    fprintf(stderr, "%s\n", alutGetErrorString(error));
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char **argv)
{
  /* Initialise ALUT and eat any ALUT-specific commandline flags. */
  if (!alutInit(&argc, argv))
  {
    ALenum error = alutGetError();

    fprintf(stderr, "%s\n", alutGetErrorString(error));
    exit(EXIT_FAILURE);
  }

  /* Check for correct usage. */
  if (argc != 2)
  {
    fprintf(stderr, "usage: playfile <fileName>\n");
    alutExit();
    exit(EXIT_FAILURE);
  }

  /* If everything is OK, play the sound file and exit when finished. */
  playFile(argv[1]);

  if (!alutExit())
  {
    ALenum error = alutGetError();

    fprintf(stderr, "%s\n", alutGetErrorString(error));
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}
Пример #3
0
bool LLAudioBufferOpenAL::loadWAV(const std::string& filename)
{
	cleanup();
	mALBuffer = alutCreateBufferFromFile(filename.c_str());
	if(mALBuffer == AL_NONE)
	{
		ALenum error = alutGetError(); 
		if (gDirUtilp->fileExists(filename))
		{
			LL_WARNS("OpenAL") <<
				"LLAudioBufferOpenAL::loadWAV() Error loading "
				<< filename
				<< " " << alutGetErrorString(error) << LL_ENDL;
		}
		else
		{
			// It's common for the file to not actually exist.
			//LL_DEBUGS("OpenAL") <<
			//	"LLAudioBufferOpenAL::loadWAV() Error loading "
			//	 << filename
			//	 << " " << alutGetErrorString(error) << LL_ENDL;
		}
		return false;
	}

	return true;
}
Пример #4
0
int bind_noaudio_set(void *b, int v)
{
	int i = bind_common_onoffset_inverted(b, v);
	
	if(v)
	{
		alutExit();
		printf("-- Unloaded ALUT\n");
		
		if(resources.state & RS_SfxLoaded)
		{
			delete_sounds();
			resources.state &= ~RS_SfxLoaded;
		}
	}
	else
	{
		if(!alutInit(NULL, NULL))
		{
			warnx("Error initializing audio: %s", alutGetErrorString(alutGetError()));
			tconfig.intval[NO_AUDIO] = 1;
			return 1;	// index of "off"
		}
		tconfig.intval[NO_AUDIO] = 0;
		printf("-- ALUT\n");
		
		load_resources();
	}
	
	return i;
}
Пример #5
0
SoundManager::SoundManager()
{
	alutInit(0,NULL);
	if(alutGetError() != ALUT_ERROR_NO_ERROR)
	{
		throw SoundManagerException("Error at init of alut\n");
	}

	files_[0] = "Resources/Sounds/MetronomeSounds/tick.wav";
	files_[1] = "Resources/Sounds/PianoSounds/1.wav";
	files_[2] = "Resources/Sounds/PianoSounds/2.wav";
	files_[3] = "Resources/Sounds/PianoSounds/3.wav";
	files_[4] = "Resources/Sounds/PianoSounds/4.wav";
	files_[5] = "Resources/Sounds/PianoSounds/5.wav";
	files_[6] = "Resources/Sounds/PianoSounds/6.wav";
	files_[7] = "Resources/Sounds/PianoSounds/7.wav";
	files_[8] = "Resources/Sounds/PianoSounds/8.wav";
	files_[9] = "Resources/Sounds/PianoSounds/9.wav";
	files_[10] = "Resources/Sounds/PianoSounds/10.wav";
	files_[11] = "Resources/Sounds/PianoSounds/11.wav";
	files_[12] = "Resources/Sounds/PianoSounds/12.wav";
	files_[13] = "Resources/Sounds/PianoSounds/13.wav";
	files_[14] = "Resources/Sounds/PianoSounds/intro1.wav";
	files_[15] = "Resources/Sounds/PianoSounds/intro2.wav";
}
Пример #6
0
static void
checkForErrors (void)
{
  {
    ALenum error = alutGetError ();
    if (error != ALUT_ERROR_NO_ERROR)
      {
        die ("ALUT", alutGetErrorString (error));
      }
  }
  {
    ALCdevice *device = alcGetContextsDevice (alcGetCurrentContext ());
    ALCenum error = alcGetError (device);
    if (error != ALC_NO_ERROR)
      {
        die ("ALC", (const char *) alcGetString (device, error));
      }
  }
  {
    ALenum error = alGetError ();
    if (error != AL_NO_ERROR)
      {
        die ("AL", (const char *) alGetString (error));
      }
  }
}
Пример #7
0
SoundManager::SoundManager(QString soundDirectory)
{
    QString applicationDirectory;
    QString completeSoundDirectory;
    char cwd[PATH_MAX];
    ALuint bufferID;

    // Initialize ALUT.
    if (alutInit(NULL, NULL) == false) {
        reportALUTError();
    }

    // Get the complete application directory in which we will load sounds from.
    // We convert to QString since it is more convenient when working with directories.
    getcwd(cwd, PATH_MAX);
    applicationDirectory = QString(cwd);

    // Append the assets directory and the actual sounds directory name.
    completeSoundDirectory = applicationDirectory
                            .append("/app/native/assets/")
                            .append(soundDirectory);

    // Create OpenAL buffers from all files in the sound directory.
    QDir dir(completeSoundDirectory);

    if (!dir.exists()) {
        qDebug() << "Cannot find the sounds directory." << completeSoundDirectory;
    } else {

        // Set a filter for file listing, only files should be listed.
        dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);

        // Get a directory listing.
        QFileInfoList list = dir.entryInfoList();

        // Traverse all the files.
        for (int i = 0; i < list.size(); ++i) {

            // Attempt to create buffers for all the files.
            QFileInfo fileInfo = list.at(i);
            bufferID = alutCreateBufferFromFile(fileInfo.absoluteFilePath().toStdString().c_str());
            ALenum error = alutGetError();
            if (error == ALUT_ERROR_NO_ERROR) {

                // Add the bufferID to the Hash table with the file name as key.
                mSoundBuffers[fileInfo.fileName()] = bufferID;

            } else {
            	qDebug() << "For " << fileInfo.fileName() << ": ALUT reported the following error: " << alutGetErrorString(error);
            }
        }
    }

    // Generate a number of sources used to attach buffers and play.
    alGenSources(SOUNDMANAGER_MAX_NBR_OF_SOURCES, mSoundSources);

    if (alGetError() != AL_NO_ERROR) {
        reportOpenALError();
    }
}
Пример #8
0
void SonicDog::playArrived( void ) {
	SoundSrc *src = new SoundSrc;
	src->once = true;
	src->x = 0.0;
	src->z = 0.0;
	src->pause = 2.5;

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

	alutGetError();
	src->buffer = alutCreateBufferFromFile( "./radio_jingle.wav" );

	if ( src->buffer == AL_NONE ) {
		checkError( "alutCreateBufferWaveform", ALUT );
		return;
	}

	alSource3f( src->source, AL_POSITION, 0.0f, 0.0f, 0.0f );

	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 );

	pthread_mutex_lock( &q_lock_ );
	play_q_.push( src );
	pthread_mutex_unlock( &q_lock_ );
	pthread_cond_broadcast( &empty_q_lock_ );
}
Пример #9
0
SoundSystem::SoundSystem()  : id_gen(1), remote_head(0), sys(0) {
#ifdef USE_FMOD    
	FMOD_RESULT r;
	r = FMOD_System_Create(&sys);
	FMOD_ERRCHECK(r);

	unsigned int version;
	r = FMOD_System_GetVersion(sys, &version);
	FMOD_ERRCHECK(r);
	if(version < FMOD_VERSION ){
		print("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
		return;
	}
	r = FMOD_System_Init( sys, 32, FMOD_INIT_NORMAL, NULL );
	FMOD_ERRCHECK(r);
#endif
#ifdef USE_UNTZ
	UNTZ::System::initialize( 44100, 512, 0 );
#endif
#ifdef USE_OPENAL
    if(alutInit(0,NULL)==AL_FALSE) {
        print("alutInit failed! error:%s", alutGetErrorString(alutGetError()));
        assert(false);
    } else {
        print("alutInit success!");
    }
#endif    
    for(int i=0;i<elementof(sounds);i++) sounds[i] = NULL;
}
bool LLAudioBufferOpenAL::loadWAV(const std::string& filename)
{
	cleanup();
	mALBuffer = alutCreateBufferFromFile(filename.c_str());
	if (mALBuffer == AL_NONE)
	{
		ALenum error = alutGetError(); 
		if (gDirUtilp->fileExists(filename))
		{
			llwarns << "LLAudioBufferOpenAL::loadWAV() Error loading "
					<< filename << " " 
					<< convertALErrorToString(error) << ": "
					<< alutGetErrorString(error) 
					<< llendl;
		}
		else
		{
			// It's common for the file to not actually exist.
			lldebugs << "LLAudioBufferOpenAL::loadWAV() Error loading "
					<< filename << " " 
					<< convertALErrorToString(error) << ": "
					<< alutGetErrorString(error) 
					<< llendl;
		}
		return false;
	}

	return true;
}
Пример #11
0
// Start the sound sub-system
void SokobanSoundManager::Setup(void)
{
	// Initialise ALUT and eat any ALUT-specific command line flags
	if (!alutInit (NULL, NULL))
	{
		ALenum error = alutGetError ();
		fprintf (stderr, "%s\n", alutGetErrorString (error));
		// exit (EXIT_FAILURE);
		m_bIsSetup = false;
		return;
	}

	// Load the default sound
	//////////////////////////////////////////////////////////////////////////
	// NOTE: Cant use LoadSampleFromFile because if it fails it returns m_DefaultSoundID
	
	// Create an AL buffer from the given sound file
	m_DefaultSoundID = alutCreateBufferFromFile (".\\audio\\default.wav");
	if (m_DefaultSoundID == AL_NONE)
	{
		ALenum error = alutGetError ();
		fprintf (stderr, "Error loading file: '%s'\n", alutGetErrorString (error));
		alutExit ();
		// exit (EXIT_FAILURE);
		m_bIsSetup = false;
		return;
	}

	// Generate a single source
	alGenSources (1, &source);

	// Error check source generation
	ALenum error = alGetError ();
	if (error != ALUT_ERROR_NO_ERROR)
	{
		//	fprintf (stderr, "%s\n", alGetString (error));
		MessageBox (HWND_DESKTOP, alGetString(error), "Error 1", MB_OK | MB_ICONEXCLAMATION);
		alutExit ();
		exit (EXIT_FAILURE);
	}

	// toggle IsSetup
	m_bIsSetup = true;

	return;
}
Пример #12
0
  static void throw_ALUTError_onfailure()
  {
    ALenum error = alutGetError();
    if (error != ALUT_ERROR_NO_ERROR)
      {
	throw alutGetErrorString(error);
      }
  }
Пример #13
0
bool SoundManager::load(QString filePath) {

	bool isSuccessful = false;

	//Check to see whether this file has already been loaded
	if (mSoundBuffers.contains(filePath)) {

		ALuint bufferId = mSoundBuffers[filePath];
		ALuint sourceId = mAttachedSourceIds[bufferId];

		qDebug() << "XXXX Deleting old source id:" << sourceId
				<< " attached to buffer id:" << bufferId << " for: "
				<< filePath;

		//First we need to detach the source from that buffer
		alSourcei(sourceId, AL_BUFFER, 0);
		ALenum error = alGetError();
		if (error != AL_NO_ERROR) {
			qDebug() << "XXXX There was a problem detaching source id:"
					<< sourceId << " from buffer id: " << bufferId;
			reportOpenALError(error);
		}

		alDeleteBuffers(1, &bufferId);
		error = alGetError();
		if (error != AL_NO_ERROR) {
			qDebug() << "XXXX There was a problem deleting buffer id:"
					<< bufferId;
			reportOpenALError(error);
		}

		mSoundBuffers.remove(filePath);
	}

	//Create a buffer and fill it with data from the WAV file
	ALuint bufferId = alutCreateBufferFromFile(filePath.toStdString().c_str());

	if (bufferId != AL_NONE) {

		qDebug() << "XXXX Created buffer (id: " << bufferId
				<< ") from file for: " << filePath;

		//Record the bufferId which this file was loaded into
		mSoundBuffers[filePath] = bufferId;

		//Attach this buffer to an available source
		ALuint sourceId = getNextAvailableSourceId();
		isSuccessful = attachBufferToSource(bufferId, sourceId);

	} else {

		qDebug() << "XXXX Failed to create buffer for: " << filePath;
		reportALUTError(alutGetError());
	}

	return isSuccessful;
}
	Buffer* LoadWAV(const char* name, const void* data, size_t size)
	{
		Buffer* b = new Buffer(name);

		b->bufferId[0] = alutCreateBufferFromFileImage(data,size);
		
		ALenum error = alutGetError();
		if (error != ALUT_ERROR_NO_ERROR)
		{
			freeslw::ErrorPrintf(alutGetErrorString(error));
			delete b; return 0;
		}

		if (b->bufferId[0] == NO_BUFFER)
		{
			freeslw::ErrorPrintf("Failed to create buffer for \"%s\"",name);
			delete b; return 0;
		}

		ALint format;
		ALint isize;
		ALint freq;
		ALint bits;
		ALint channels;
		ALint d = 1;

		alGetBufferi(b->bufferId[0],AL_CHANNELS,&format);
		alGetBufferi(b->bufferId[0],AL_SIZE,&isize);
		alGetBufferi(b->bufferId[0],AL_FREQUENCY,&freq);

			 if (format == AL_FORMAT_MONO8) b->format = freeslw::TA_MONO8;
		else if (format == AL_FORMAT_MONO16) b->format = freeslw::TA_MONO16;
		else if (format == AL_FORMAT_STEREO8) b->format = freeslw::TA_STEREO8;
		else if (format == AL_FORMAT_STEREO16) b->format = freeslw::TA_STEREO16;
		else freeslw::ErrorPrintf("Failed to retrieve a valid sound format (format = %d)",format);

		alGetBufferi(b->bufferId[0],AL_BITS,&bits);
		alGetBufferi(b->bufferId[0],AL_CHANNELS,&channels);
			
			 if (bits == 16 && channels == 1) d = 2;
		else if (bits == 8 && channels == 2) d = 2;
		else if (bits == 16 && channels == 2) d = 4;

		if (freq == 0)
		{
			freeslw::ErrorPrintf("\"%s\": Frequency = 0",name);
			freq = 1;
		}

		b->frequency = (int)freq;
		b->length = (isize * 1000) / (freq * d);
		b->activeBuffer = 0;
		b->numBuffers = 1;

		return b;
	}
Пример #15
0
Handle<Value> ALUTGetErrorCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 0)
		return v8::Undefined();
	
	//get arguments

	//make call
	alutGetError();
	
	return v8::Undefined();
}
Пример #16
0
Sounds::Sounds()
{
	m_was_init=false;

	const ALCchar* device_str=alcGetString(NULL,ALC_DEVICE_SPECIFIER);
	
	int i=0;
	
	std::vector<std::string> devices;
	std::string curr_dev;
	
	while(true)
	{
		if(device_str[i]==0)
		{
			devices.push_back(curr_dev);
			curr_dev.clear();
		
			if(device_str[i+1]==0)
				break;
		}
		else
		{
			curr_dev.push_back(device_str[i]);
		}
		
		i++;
	}
	
	//std::cout<<"Available sound devices:"<<std::endl;
	
	std::vector<std::string>::iterator j;
	
	for(j=devices.begin();j!=devices.end();++j)
	{
		//std::cout<<*j<<std::endl;
	}
	
	if(alutInit(NULL, NULL) == AL_FALSE)
	{
		std::cerr<<"alutInit(NULL,NULL) failed"<<std::endl;
		std::cerr<<alutGetErrorString(alutGetError())<<"\n";
		return;	
	}

	alGetError();
	
	printSoundInfo();

	m_was_init=true;
}
Пример #17
0
void SoundManager::loadSoundBuffers()
{
	ALfloat listenerPos[] = {0.0,0.0,4.0};
	ALfloat listenerVel[] = {0.0,0.0,0.0};
	ALfloat listenerOri[] = {0.0,0.0,1.0, 0.0,1.0,0.0};

	alListenerfv(AL_POSITION, listenerPos);
	alListenerfv(AL_VELOCITY, listenerVel);
	alListenerfv(AL_ORIENTATION, listenerOri);
	if(alGetError() != AL_NO_ERROR)
	{
		std::cerr << "Error while creating sound listeners\n";
	}

	//generate the sound buffer
	alGenBuffers(NUM_BUFFERS, buffer_);
	if(alGetError() != AL_NO_ERROR)
	{
		std::cerr << "Error while creating sound buffers\n";
	}

	alGenSources(NUM_SOURCES, source_);
	if(alGetError() != AL_NO_ERROR)
	{
		std::cerr << "Error while creating sound sources\n";
	}

	for(int i=0; i<NUM_BUFFERS;i++)
	{
		std::cout << "Loading sound " << files_[i] << "." << std::endl;
		buffer_[i] = alutCreateBufferFromFile(files_[i].c_str());
		if(alutGetError() != ALUT_ERROR_NO_ERROR)
		{
			std::cerr << "Error when creating the buffer for the sound\n";
		}

		alSourcef(source_[i], AL_PITCH, 1.0f);
		alSourcef(source_[i], AL_GAIN, 1.0f);

		alSourcei(source_[i], AL_BUFFER, buffer_[i]);
		if(alGetError() != AL_NO_ERROR)
		{
			std::cerr << "Error while applying the sound source to the buffer\n";
		}

		alSourcei(source_[i], AL_LOOPING, AL_FALSE);
	}

	//repeat metronome klick
	alSourcei(source_[0], AL_LOOPING, AL_TRUE);
}
Пример #18
0
SoundManager::SoundManager() {

	// Initialize the ALUT
	if (alutInit(NULL, NULL) == false) {
		reportALUTError(alutGetError());
	}

	// Generate a number of sources used to attach buffers and play.
	alGenSources(SOUNDMANAGER_MAX_NBR_OF_SOURCES, mSourceIds);

	ALenum error = alGetError();
	if (error != AL_NO_ERROR) {
		reportOpenALError(error);
	}
}
Пример #19
0
// shut down the sound sub-system
void SokobanSoundManager::Destroy(void)
{

	// free sources
	alDeleteSources(1, &source);

	if (!alutExit ())
	{
		ALenum error = alutGetError ();
		fprintf (stderr, "%s\n", alutGetErrorString (error));
		exit (EXIT_FAILURE);
	}

	m_bIsSetup = false;
}
  Sound_Buffer::Sound_Buffer()
    : m_buffer(AL_NONE),
      m_loader(0),
      m_thread(0)
  {
    get_Sound();

#ifndef DISABLE_AL
    m_buffer = alutCreateBufferHelloWorld();

    if(m_buffer == AL_NONE) {
      cerr << "ALUT error on Hello World: " << alutGetErrorString(alutGetError()) << endl;
      throw Sound_Buffer_Init_Failure();
    }
#endif
  }
  int Sound_Buffer::Loader::function() {
#ifndef DISABLE_AL
    pair<ALuint, float> loaded_ogg = load_ogg_vorbis(m_filename);
    //if(loaded_ogg.first == AL_NONE)
    //  loaded_ogg.first = alutCreateBufferFromFile(m_filename.c_str());

    if(loaded_ogg.first == AL_NONE) {
      cerr << "ALUT error on '" << m_filename << "': " << alutGetErrorString(alutGetError()) << endl;
      return -1;
    }

    m_buffer = loaded_ogg.first;
    m_duration = loaded_ogg.second;
#endif

    return 0;
  }
Пример #22
0
SonicDog::SonicDog( size_t threads ) {
	num_threads_ = threads;

	// alutInit( NULL, NULL );
	// checkError( "clearing messages", AL );
	alutGetError();
	if ( alutInitWithoutContext( NULL, NULL ) == AL_FALSE ) {
		checkError( "alutInitWithoutContext", ALUT );
	}

	device_ = alcOpenDevice( NULL );
	if ( device_ ) {
		context_ = alcCreateContext( device_, NULL );
		if ( context_ ) {
			alcMakeContextCurrent( context_ );
		} else {
			checkError( "alcCreateContext", AL );
		}
	} else {
		checkError( "alcOpenDevice", AL );
	}

	// set the position of the listener at the origin
	alListener3f( AL_POSITION, 0.0f, 0.0f, 0.0f );
	alListener3f( AL_VELOCITY, 0.0f, 0.0f, 0.0f );
	// ALfloat ori[] = { 0.0f, 0.0f, 1.0f };
	// alListenerfv( AL_ORIENTATION, ori );

	// initialize the object id
	object_id_ = 1;

	// initialize the locks
	pthread_mutex_init( &play_lock_, NULL );
	pthread_mutex_init( &sources_lock_, NULL );
	pthread_mutex_init( &remove_lock_, NULL );
	pthread_mutex_init( &pause_lock_, NULL );
	pthread_mutex_init( &q_lock_, NULL );
	pthread_mutex_init( &turns_lock_, NULL );
	pthread_cond_init( &empty_q_lock_, NULL );
	pthread_cond_init( &pause_cond_lock_, NULL );

	// boolean to toggle regions on or off
	regions_ = true;
	cutoff_ = false;
	front_only_ = false;
}
Пример #23
0
FMCSound::FMCSound(const QString & filename, SOUND_SOURCE sound_source) :
    FMCSoundBase(sound_source), m_filename(filename)
{
    ALfloat sourcePosition[3] = {0.0f, 0.0f, 0.0f};
    ALfloat sourceVelocity[3] = {0.0f, 0.0f, 0.0f};
    ALfloat listenerPosition[3] = {0.0f, 0.0f, 0.0f};
    ALfloat listenerVelocity[3] = {0.0f, 0.0f, 0.0f};
    ALfloat listenerOrientation[6] = {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f};
    MYASSERT(!filename.isEmpty());
    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop = AL_FALSE;
    alGetError();
    //alGenBuffers(1, &m_buffer);
    //alutLoadWAVFile((ALbyte*)filename.toLatin1().data(), &format, &data, &size, &freq, &loop);
    //alBufferData(m_buffer, format, data, size, freq);
    //alutUnloadWAV(format, data, size, freq);
    m_buffer = alutCreateBufferFromFile(filename.toLatin1().data());

    if( m_buffer == AL_NONE)
    {
        Logger::log("ALUT: Buffer creation failed:");
        Logger::log(alutGetErrorString(alutGetError()));
    } 
    else 
    {
        MYASSERT(alGetError() == AL_NO_ERROR);
        alGenSources(1, &m_source);
        MYASSERT(alGetError() == AL_NO_ERROR);
        alSourcei (m_source, AL_BUFFER,   m_buffer   );
        alSourcef (m_source, AL_PITCH,    1.0      );
        alSourcef (m_source, AL_GAIN,     1.0      );
        alSourcefv(m_source, AL_POSITION, sourcePosition);
        alSourcefv(m_source, AL_VELOCITY, sourceVelocity);
        alSourcei (m_source, AL_LOOPING,  loop     );
        MYASSERT(alGetError() == AL_NO_ERROR);
        alListenerfv(AL_POSITION,    listenerPosition);
        alListenerfv(AL_VELOCITY,    listenerVelocity);
        alListenerfv(AL_ORIENTATION, listenerOrientation);
    }
}
Пример #24
0
wsSound::wsSound(const char* filePath) {
#if WS_SOUND_BACKEND == WS_BACKEND_OPENAL
    alGenSources(1, &soundSource);
    pitch = 1.0f;
    rolloff = 1.0f;
    refDistance = 50.0f;
    looping = false;
    relative = true;
    update();
    alGenBuffers(1, &soundBuffer);
    i32 errorType;
    soundBuffer = alutCreateBufferFromFile(filePath);
    errorType = alutGetError();
    if (errorType) {
        wsEcho(WS_LOG_SOUND | WS_LOG_ERROR, "Error Loading Sound file \"%s\": %s\n", filePath, alutGetErrorString(errorType));
    }
    alSourcei(soundSource, AL_BUFFER, soundBuffer);
#endif
}
Пример #25
0
static void
playFile (const char *fileName)
{
  ALuint buffer;
  ALuint source;
  ALenum error;
  ALint status;

  /* Create an AL buffer from the given sound file. */
  buffer = alutCreateBufferFromFile (fileName);
  if (buffer == AL_NONE)
    {
      error = alutGetError ();
      fprintf (stderr, "Error loading file: '%s'\n",
               alutGetErrorString (error));
      alutExit ();
      exit (EXIT_FAILURE);
    }

  /* Generate a single source, attach the buffer to it and start playing. */
  alGenSources (1, &source);
  alSourcei (source, AL_BUFFER, buffer);
  alSourcePlay (source);

  /* Normally nothing should go wrong above, but one never knows... */
  error = alGetError ();
  if (error != ALUT_ERROR_NO_ERROR)
    {
      fprintf (stderr, "%s\n", alGetString (error));
      alutExit ();
      exit (EXIT_FAILURE);
    }

  /* Check every 0.1 seconds if the sound is still playing. */
  do
    {
      alutSleep (0.1f);
      alGetSourcei (source, AL_SOURCE_STATE, &status);
    }
  while (status == AL_PLAYING);
}
Пример #26
0
	//-------------------------------------------------------------------------------------------------
    void SoundOpenAL::load(const char* filename)
	{
		if (!SoundManagerOpenAL::getSingleton().isValid())
		{
			SoundManagerOpenAL::getSingleton().init();
		}

		// Get the complete path for loading the file
		std::string completePath = ResourceManager::userDataPath + filename;

		// load the sound using FreeALUT
		bufferId = alutCreateBufferFromFile(completePath.c_str());
		if (bufferId == AL_NONE)
		{
			LOG_ERROR("Sound %s couldn't be loaded", completePath.c_str());
			LOG_ERROR("Error: %s", alutGetErrorString(alutGetError()));
			m_isValid = false;
			return;
		}else{
			m_isValid = true;
		}
	}
Пример #27
0
Sound *load_sound(char *filename) {
	ALuint sound;
	if(!(sound = alutCreateBufferFromFile(filename)))
		errx(-1,"load_sound():\n!- cannot load '%s': %s", filename, alutGetErrorString(alutGetError()));
	
	
	Sound *snd = create_element((void **)&resources.sounds, sizeof(Sound));
	
	snd->alsnd = sound;
	snd->lastplayframe = 0;
	
	char *beg = strstr(filename, "sfx/") + 4;
	char *end = strrchr(filename, '.');
	
	snd->name = malloc(end - beg + 1);
	memset(snd->name, 0, end-beg + 1);
	strncpy(snd->name, beg, end-beg);
	
	printf("-- loaded '%s' as '%s'\n", filename, snd->name);
	
	return snd;
}
bool LLAudioBufferOpenAL::loadWAV(const std::string& filename)
{
	if (filename.empty())
	{
		// invalid filename, abort.
		return false;
	}

	cleanup();
	mALBuffer = alutCreateBufferFromFile(filename.c_str());
	if(mALBuffer == AL_NONE)
	{
		ALenum error = alutGetError(); 
		if (gDirUtilp->fileExists(filename))
		{
			llwarns <<
				"LLAudioBufferOpenAL::loadWAV() Error loading "
				<< filename
				<< " " << alutGetErrorString(error) << llendl;
			//
			// If we EVER want to load wav files provided by end users, we need
			// to rethink this!
			//
			// file is probably corrupt - remove it.
			LLFile::remove(filename);
		}
		else
		{
			// It's common for the file to not actually exist.
			lldebugs <<
				"LLAudioBufferOpenAL::loadWAV() Error loading "
				 << filename
				 << " " << alutGetErrorString(error) << llendl;
		}
		return false;
	}

	return true;
}
Пример #29
0
SoundManager::~SoundManager() {

	// Clear all the sources.
	for (int sourceIndex = 0; sourceIndex < SOUNDMANAGER_MAX_NBR_OF_SOURCES;
			sourceIndex++) {
		ALuint source = mSourceIds[sourceIndex];
		alDeleteSources(1, &source);

		ALenum error = alGetError();
		if (error != AL_NO_ERROR) {
			reportOpenALError(error);
		}
	}

	// Clear the buffers by iterating through the hash table keys
	QHashIterator<ALuint, ALuint> iterator(mAttachedSourceIds);

	while (iterator.hasNext()) {
		iterator.next();

		// Get the buffer id and delete it.
		ALuint bufferId = iterator.key();
		alDeleteBuffers(1, &bufferId);

		ALenum error = alGetError();
		if (error != AL_NO_ERROR) {
			reportOpenALError(error);
		}
	}

	// Clear the QHash for buffer IDs.
	mAttachedSourceIds.clear();

	// Exit the ALUT.
	if (alutExit() == false) {
		reportALUTError(alutGetError());
	}
}
Пример #30
0
void SonicDog::checkError( const char *msg, al_t type ) {
	ALenum err;
	switch ( type ) {
		case ALUT: {
			err = alutGetError();
			if ( err == ALUT_ERROR_NO_ERROR ) {
				error_ = false;
			} else {
				displayAlutError( msg, err );
				error_ = true;
			}
		}
		case AL:
		default: {
			err = alGetError();
			if ( err == AL_NO_ERROR ) {
				error_ = false;
			} else {
				displayALError( msg, err );
				error_ = true;
			}
		}
	}
}