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; }
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; }
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; }
bool SoundGeneral::checkAlError(const std::string& description) { ALenum error = alGetError(); if (error == AL_NO_ERROR) { return true; } else { if (description == "") { S_LOG_FAILURE("OpenAl error: " << alutGetErrorString(error)); } else { S_LOG_FAILURE("OpenAl error: " << alutGetErrorString(error) << "\nDescription: " << description); } return false; } }
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; }
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)); } } }
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)) { 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; }
static void throw_ALUTError_onfailure() { ALenum error = alutGetError(); if (error != ALUT_ERROR_NO_ERROR) { throw alutGetErrorString(error); } }
// 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; }
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; }
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; }
Handle<Value> ALUTGetErrorStringCallback(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 alutGetErrorString((ALenum)arg0); return v8::Undefined(); }
int main(int argc, char **argv) { alutInit(&argc,argv); ALuint buffer =alutCreateBufferFromFile("mario.wav"); ALuint source; alGenSources(1,&source); alSourcei(source,AL_BUFFER,buffer); alSourcePlay(source); int error =alGetError(); if(error) printf("%s Error\n",alutGetErrorString(error)); return 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; }
// virtual void LLAudioEngine_OpenAL::shutdown() { llinfos << "Entering LLAudioEngine::shutdown()" << llendl; LLAudioEngine::shutdown(); llinfos << "Entering alutExit()" << llendl; if (!alutExit()) { llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString(alutGetError()) << llendl; } else { llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; } delete mListenerp; mListenerp = NULL; ALenum error; alcMakeContextCurrent(NULL); error = alGetError(); if (error != AL_NO_ERROR) { llinfos << "AL error: " << convertALErrorToString(error) << ". Could not make current context NULL!" << llendl; } alcDestroyContext(mContext); error = alGetError(); if (error != AL_NO_ERROR) { llinfos << "AL error: " << convertALErrorToString(error) << ". Could not destroy context!" << llendl; } else { mContext = NULL; } alcCloseDevice(mDevice); error = alGetError(); if (error != AL_NO_ERROR) { llinfos << "AL error: " << convertALErrorToString(error) << ". Could not close device!" << llendl; } else { mDevice = NULL; } }
void _alutSetError (ALenum err) { /* print a message to stderr if ALUT_DEBUG environment variable is defined */ if (getenv ("ALUT_DEBUG")) { fprintf (stderr, "ALUT error: %s\n", alutGetErrorString (err)); } if (lastError == ALUT_ERROR_NO_ERROR) { lastError = err; } }
void GOSound::init() { canPlay = false; soundName = ""; alGenSources(1, &source); ALfloat sourceVel[] = { 0.0, 0.0, 0.0 }; alSourcef(source, AL_PITCH, 1.0f ); alSourcef(source, AL_GAIN, 1.0f ); alSourcefv(source, AL_VELOCITY, sourceVel); alSourcei(source, AL_LOOPING, false); ALenum error = alGetError(); if (error != AL_NO_ERROR) Log::warning("error create sound (%s)", alutGetErrorString(error)); }
// 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; }
// virtual void LLAudioEngine_OpenAL::shutdown() { LL_INFOS("OpenAL") << "About to LLAudioEngine::shutdown()" << LL_ENDL; LLAudioEngine::shutdown(); LL_INFOS("OpenAL") << "About to alutExit()" << LL_ENDL; if(!alutExit()) { LL_WARNS("OpenAL") << "Nuts." << LL_ENDL; LL_WARNS("OpenAL") << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString (alutGetError ()) << LL_ENDL; } LL_INFOS("OpenAL") << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << LL_ENDL; delete mListenerp; mListenerp = NULL; }
// virtual void LLAudioEngine_OpenAL::shutdown() { llinfos << "About to LLAudioEngine::shutdown()" << llendl; LLAudioEngine::shutdown(); llinfos << "About to alutExit()" << llendl; if(!alutExit()) { llwarns << "Nuts." << llendl; llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString (alutGetError ()) << llendl; } llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; delete mListenerp; mListenerp = NULL; }
BOOL LLAudioEngine_OpenAL::init(const S32 num_channels) { LLAudioEngine::init(num_channels); if(!alutInit(NULL, NULL)) { llwarns << "LLAudioEngine_OpenAL::init() ALUT initialization failed: " << alutGetErrorString (alutGetError ()) << llendl; return FALSE; } initInternetStream(); llinfos << "LLAudioEngine_OpenAL::init() OpenAL successfully initialized" << llendl; llinfos << "LLAudioEngine_OpenAL::init() Speed of sound is: " << alGetFloat(AL_SPEED_OF_SOUND) << llendl; return TRUE; }
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); } }
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); }
bool Sound_Effect::LoadAsset(const std::string &name) { m_bufferID = alutCreateBufferFromFile(name.c_str()); unsigned int errorCode = alGetError(); if(errorCode != AL_NO_ERROR) { std::cerr << "Could not load sound chunk \"" << name << "\": " << alutGetErrorString(errorCode) << std::endl; return false; } if(m_bufferID == 0) { std::cerr << "Could not load sound chunk \"" << name << "\": Unkown reason!" << std::endl; return false; } return true; }
//------------------------------------------------------------------------------------------------- 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; } }
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; }
// virtual bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata) { mWindGen = NULL; LLAudioEngine::init(num_channels, userdata); if(!alutInit(NULL, NULL)) { llwarns << "LLAudioEngine_OpenAL::init() ALUT initialization failed: " << alutGetErrorString (alutGetError ()) << llendl; return false; } llinfos << "LLAudioEngine_OpenAL::init() OpenAL successfully initialized" << llendl; llinfos << "OpenAL version: " << ll_safe_string(alGetString(AL_VERSION)) << llendl; llinfos << "OpenAL vendor: " << ll_safe_string(alGetString(AL_VENDOR)) << llendl; llinfos << "OpenAL renderer: " << ll_safe_string(alGetString(AL_RENDERER)) << llendl; ALint major = alutGetMajorVersion (); ALint minor = alutGetMinorVersion (); llinfos << "ALUT version: " << major << "." << minor << llendl; ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &minor); llinfos << "ALC version: " << major << "." << minor << llendl; llinfos << "ALC default device: " << ll_safe_string(alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER)) << llendl; return true; }