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); }
void initAudio(){ alutInit(0,NULL); alGetError(); //Create Buffers laserBuffer = alutCreateBufferFromFile("audio/laser.wav"); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); asteroidBuffer = alutCreateBufferFromFile("audio/Coin.wav"); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); shipBuffer = alutCreateBufferFromFile("audio/Block.wav"); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error - ship buffer from file: %s\n",alutGetErrorString(error)); highScoreBuffer = alutCreateBufferFromFile("audio/smb_world_clear.wav"); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error - ship buffer from file: %s\n",alutGetErrorString(error)); gameOverBuffer = alutCreateBufferFromFile("audio/smb_mariodie.wav"); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error - ship buffer from file: %s\n",alutGetErrorString(error)); //Generate Sources alGenSources(1, &laserSource); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alGenSources(1, &asteroidSource); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alGenSources(1, &shipSource); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alGenSources(1, &highScoreSource); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alGenSources(1, &gameOverSource); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); //Link sources to buffers alSourcei(laserSource, AL_BUFFER, laserBuffer); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alSourcei(asteroidSource, AL_BUFFER, asteroidBuffer); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alSourcei(shipSource, AL_BUFFER, shipBuffer); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alSourcei(highScoreSource, AL_BUFFER, highScoreBuffer); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); alSourcei(gameOverSource, AL_BUFFER, gameOverBuffer); if((error = alutGetError()) != ALUT_ERROR_NO_ERROR) fprintf(stderr, "ALUT Error: %s\n",alutGetErrorString(error)); }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { EffectsMap::iterator iter = s_effects.find(pszFilePath); // check if we have this already if (iter == s_effects.end()) { ALuint buffer; ALuint source; soundData *data = new soundData; string path = pszFilePath; buffer = alutCreateBufferFromFile(path.data()); if (buffer == AL_NONE) { fprintf(stderr, "Error loading file: '%s'\n", path.data()); alDeleteBuffers(1, &buffer); return; } alGenSources(1, &source); alSourcei(source, AL_BUFFER, buffer); data->isLooped = false; data->buffer = buffer; data->source = source; s_effects.insert(EffectsMap::value_type(pszFilePath, data)); } }
void TextToSpeech::play_wav() { // alutの初期化 int alut_argc = 0; char* alut_argv[] = {}; alutInit(&alut_argc, alut_argv); // ソースの用意 ALuint buf; ALenum state; buf = alutCreateBufferFromFile(wav_filename_.c_str()); alGenSources(1, &wav_src_); alSourcei(wav_src_, AL_BUFFER, buf); alSourcePlay(wav_src_); alGetSourcei(wav_src_, AL_SOURCE_STATE, &state); while (state == AL_PLAYING) { alGetSourcei(wav_src_, AL_SOURCE_STATE, &state); } // 後片付け alDeleteSources(1, &wav_src_); alDeleteBuffers(1, &buf); alutExit(); }
ALuint ALSequencer::LoadSFX(const char *fileName) { sfxBuffers[sfxPos] = alutCreateBufferFromFile(fileName); alGenSources(1, &sfxSources[sfxPos]); alSourcei(sfxSources[sfxPos], AL_BUFFER, sfxBuffers[sfxPos]); return sfxPos++; }
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(); } }
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; }
/** *@brief SoundObject creation method. * *@detailed The method reads a .wav-file and with it, instanciates a Sound object. If it's a background object it won't get a owner. * *@return SoundObject* */ SoundObject* SoundObject::CreateFromFile(const char* fileName, Illustration* owner){ SoundObject* s = new SoundObject(); #ifndef NO_SOUND s->_buffer = AL_NONE; alGenBuffers(1, &s->_buffer); alGenSources(1, &s->_source); s->_buffer = alutCreateBufferFromFile(fileName); if(s->_buffer == AL_NONE ) { sgct::MessageHandler::Instance()->print("Failed to read audio file '%s', error: %s\n", fileName, alutGetErrorString( alutGetError() )); } alSourcei(s->_source, AL_BUFFER, s->_buffer); s->_owner = owner; s->_ambient = owner == 0; alSourcef(s->_source, AL_PITCH, 1.0f); alSourcef(s->_source, AL_GAIN, 1.0f); alSource3f(s->_source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); #endif return s; }
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_ ); }
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; }
Audio::Buffer :: Buffer(const std::string& fn, ICache* c) { if(Headless::enabled()) return; auto l = Audio::lock(); Audio::check_errors(); id = alutCreateBufferFromFile(fn.c_str()); Audio::check_errors(); }
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; }
// SoundFX() // // Class constructor. Sets up OpenAL and loads all sound effect files into // memory. SoundFX::SoundFX() { Buffers = NULL; Sources = NULL; DIR *SFXDir = opendir( "./sounds/" ); if (SFXDir == NULL) { PRINT_DEBUG_LVL(2, "'sounds' directory not present; no sounds will be loaded.\n"); return; } dirent *de; std::string files[256]; /* TODO: Instead of holding all of the sound effects in memory in wav format, * it would be great to switch to compressed audio files. It would * drastically decrease the overall memory footprint. */ if (SFXDir != NULL) { Num_of_SFX = 0; while ((de = readdir(SFXDir)) != NULL) { if ( std::strstr( de->d_name, ".wav" ) ) { files[Num_of_SFX] = std::string( de->d_name ); Num_of_SFX++; } } closedir( SFXDir ); } if (Num_of_SFX < 1) { PRINT_DEBUG_LVL(2, "No sound files present in 'sounds' directory; no sounds will be loaded.\n"); return; } // Init buffers and sources. Buffers = new ALuint[Num_of_SFX]; Sources = new ALuint[Num_of_SFX]; alGenBuffers( Num_of_SFX, Buffers ); alGenSources( Num_of_SFX, Sources ); // Load sound files. char filename[80]; for ( int i = 0; i < Num_of_SFX; i++ ) { sprintf( filename, "./sounds/%s", files[i].c_str() ); Buffers[i] = alutCreateBufferFromFile(filename); File_Hash[ files[i] ] = i; // Create name to index map. SetSFX( files[i], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, AL_FALSE ); } SetSFXListener( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); }
BOOL LLAudioBufferOpenAL::loadWAV(const std::string& filename) { cleanup(); ALBuffer = alutCreateBufferFromFile(filename.c_str()); if(ALBuffer == AL_NONE) { return FALSE; } return TRUE; }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { // Changing file path to full path std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); EffectsMap::iterator iter = s_effects.find(fullPath); // check if we have this already if (iter == s_effects.end()) { ALuint buffer; ALuint source; soundData *data = new soundData; string path = fullPath; checkALError("preloadEffect"); if (isOGGFile(path.data())) { buffer = createBufferFromOGG(path.data()); } else { buffer = alutCreateBufferFromFile(path.data()); checkALError("preloadEffect"); } if (buffer == AL_NONE) { fprintf(stderr, "Error loading file: '%s'\n", path.data()); alDeleteBuffers(1, &buffer); return; } alGenSources(1, &source); if (checkALError("preloadEffect") != AL_NO_ERROR) { alDeleteBuffers(1, &buffer); return; } alSourcei(source, AL_BUFFER, buffer); checkALError("preloadEffect"); data->isLooped = false; data->buffer = buffer; data->source = source; s_effects.insert(EffectsMap::value_type(fullPath, data)); } }
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; }
VALUE method_init_player(VALUE self) { VALUE tick_wav, tock_wav; char *tick_wav_str, *tock_wav_str; alutInit (NULL, NULL); tick_wav = rb_const_get(lolrbmet_class, rb_intern("TickFile")); tick_wav_str = rb_string_value_cstr(&tick_wav); tock_wav = rb_const_get(lolrbmet_class, rb_intern("TockFile")); tock_wav_str = rb_string_value_cstr(&tock_wav); tickBuffer = alutCreateBufferFromFile (tick_wav_str); tockBuffer = alutCreateBufferFromFile (tock_wav_str); alGenSources (1, &tickSource); alGenSources (1, &tockSource); alSourcei (tickSource, AL_BUFFER, tickBuffer); alSourcei (tockSource, AL_BUFFER, tockBuffer); }
void RoboySpeechProduction::init(std::string filetoplay) { this->filetoplay = filetoplay; alutInit (NULL, NULL); sndBuffer = alutCreateBufferFromFile (filetoplay.c_str()); alGenSources (1, &sndSource); alSourcei (sndSource, AL_BUFFER, sndBuffer); // TODO: should get .wav playing time std::cerr << " SPEECH PRODUCTION INIT: " << filetoplay << std::endl; }
/* * 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; // yea yea i hard coded the sound wave // alutLoadWAVFile is deprecate //alutLoadWAVFile("FancyPants.wav", &format, &data, &size, &freq, &loop); /* Create an AL buffer from the given sound file. */ Buffer = alutCreateBufferFromFile ("hyperwars.wav"); // not need see the above func read right into the buffer save a step. //alBufferData(Buffer, format, data, size, freq); // alutUnloadWAV is deprecate //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; }
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); }
Handle<Value> ALUTCreateBufferFromFileCallback(const Arguments& args) { //if less that nbr of formal parameters then do nothing if (args.Length() < 1) return v8::Undefined(); //get arguments String::Utf8Value value0(args[0]); char* arg0 = *value0; //make call alutCreateBufferFromFile((const char*)arg0); return v8::Undefined(); }
Sound::Sound(const char *file) : handle(alutCreateBufferFromFile(file)) { if (handle == AL_NONE) { throw ALError(alGetError(), "alutCreateBufferFromFile"); } ALint size, channels, bits, freq; alGetBufferi(handle, AL_SIZE, &size); alGetBufferi(handle, AL_CHANNELS, &channels); alGetBufferi(handle, AL_BITS, &bits); alGetBufferi(handle, AL_FREQUENCY, &freq); duration = size * 8 * 1000 / (channels * bits * freq); }
// 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; }
int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) { /* Consider colored notify as primary */ if (self) { if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1; else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) return -1; if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1; #ifdef _SOUND_NOTIFY control_lock(); if (!actives[id].active || !Control.sounds[notif]) { control_unlock(); return -1; } alSourceStop(actives[id].source); alDeleteSources(1, &actives[id].source); alDeleteBuffers(1,&actives[id].buffer); alGenSources(1, &actives[id].source); alGenBuffers(1, &actives[id].buffer); actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]); alSourcei(actives[id].source, AL_BUFFER, actives[id].buffer); alSourcei(actives[id].source, AL_LOOPING, flags & NT_LOOP); alSourcePlay(actives[id].source); control_unlock(); return id; #else if (notif != silent) beep(); return 0; #endif /* _SOUND_NOTIFY */ }
void OpenALPlayer::initSound(ALuint* sourceArray, ALuint* bufferNumber, QString sourceFile) { char* fileName = sourceFile.toUtf8().data(); *bufferNumber = alutCreateBufferFromFile(fileName); alGetError(); for (int i = 0; i < 10; i++) { ALuint src = 0; alGenSources(1, &src); alGetError(); alSourcef(src, AL_PITCH, 1.0f); alSourcef(src, AL_GAIN, 32.0f); alSource3f(src, AL_POSITION, 0, 0, 0.0); alSource3f(src, AL_VELOCITY, 0.0, 0.0, 0.0); alSourcei(src, AL_BUFFER, *bufferNumber); alSourcei(src, AL_LOOPING, AL_FALSE); sourceArray[i] = src; } }
void load(char* fileName) { //> Sound buffer variable ALuint buffer = 0; //> Sound source varialbe source = 0; //> Generate sound buffer alGenBuffers(NUM_BUFFERS, &buffer); //> Load WAV file buffer = alutCreateBufferFromFile(fileName); //> Generate sound source (sound position in 3D space) alGenSources(NUM_SOURCES, &source); //> Associate source with sound buffer alSourcei(source, AL_BUFFER, buffer); }
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 }
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); } }
void loadFile( const string &path, const string &id ) { BK_ASSERT( m_buffers.count( id ) == 0, "id " << id << " must be unique in the collection!" ); ALuint buffer = alutCreateBufferFromFile( path.c_str() ); ALuint source; alGenSources( 1, &source ); alSourcei( source, AL_BUFFER, buffer ); OpenALData *data = new OpenALData(); data->m_id = id; data->m_path = path; data->m_buffer = buffer; data->m_source = source; m_buffers[ id ] = data; }
int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) { tab_notify(self, flags); if (notifications_are_disabled(flags)) return -1; if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1; #ifdef SOUND_NOTIFY control_lock(); if (!actives[id].active || !Control.sounds[notif]) { control_unlock(); return -1; } m_open_device(); alSourceStop(actives[id].source); alDeleteSources(1, &actives[id].source); alDeleteBuffers(1,&actives[id].buffer); alGenSources(1, &actives[id].source); alGenBuffers(1, &actives[id].buffer); actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]); alSourcei(actives[id].source, AL_BUFFER, actives[id].buffer); alSourcei(actives[id].source, AL_LOOPING, flags & NT_LOOP); alSourcePlay(actives[id].source); control_unlock(); return id; #else if (notif != silent) beep(); return 0; #endif /* SOUND_NOTIFY */ }