// ---------------------------------------------------------------------------- ofOpenALSoundPlayer::~ofOpenALSoundPlayer(){ unloadSound(); close(); if(fftCfg!=0) kiss_fftr_free(fftCfg); //kiss_fftr_free(fftCfg); //players.erase(this); }
AppDelegate::~AppDelegate() { unloadSound(); SelectMenuController::destory(); MainMenuController::destory(); GalleryController::destory(); GameRunController::destory(); BeautyStaticData::detroy(); GameModel::destoryInstance(); //// cocostdio //UIHelper::purgeUIHelper(); SceneReader::sharedSceneReader()->purgeSceneReader(); GUIReader::purgeGUIReader(); ActionManager::purgeActionManager(); //CCActionManager:: //// reCache CCTextureCache::sharedTextureCache()->removeAllTextures(); CCTextureCache::purgeSharedTextureCache(); CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFrames(); CCSpriteFrameCache::purgeSharedSpriteFrameCache(); //cocos CCScriptEngineManager::purgeSharedManager(); // DictionaryHelper::purgeDictionaryHelper(); SceneReader::sharedSceneReader()->purgeSceneReader(); //CCUIHELPER->purgeUIHelper(); }
//------------------------------------------------------------ void ofMultiDeviceSoundPlayer::loadSoundWithTarget(string fileName, int deviceIndex) { device = deviceIndex; bool stream = false; fileName = ofToDataPath(fileName); // fmod uses IO posix internally, might have trouble // with unicode paths... // says this code: // http://66.102.9.104/search?q=cache:LM47mq8hytwJ:www.cleeker.com/doxygen/audioengine__fmod_8cpp-source.html+FSOUND_Sample_Load+cpp&hl=en&ct=clnk&cd=18&client=firefox-a // for now we use FMODs way, but we could switch if // there are problems: bMultiPlay = false; // [1] init fmod, if necessary initializeFmodWithTargetDevice(deviceIndex); // [2] try to unload any previously loaded sounds // & prevent user-created memory leaks // if they call "loadSound" repeatedly, for example unloadSound(); // [3] load sound //choose if we want streaming int fmodFlags = FMOD_SOFTWARE; if(stream)fmodFlags = FMOD_SOFTWARE | FMOD_CREATESTREAM; result = FMOD_System_CreateSound(sys_Array[deviceIndex], fileName.c_str(), fmodFlags, NULL, &sound); if (result != FMOD_OK){ bLoadedOk = false; printf("ofSoundPlayer: Could not load sound file %s \n", fileName.c_str() ); } else { bLoadedOk = true; FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCM); isStreaming = stream; } }
//------------------------------------------------------------ bool ofOpenALSoundPlayer::loadSound(string fileName, bool is_stream){ fileName = ofToDataPath(fileName); bMultiPlay = false; isStreaming = is_stream; int err = AL_NO_ERROR; // [1] init sound systems, if necessary initialize(); // [2] try to unload any previously loaded sounds // & prevent user-created memory leaks // if they call "loadSound" repeatedly, for example unloadSound(); ALenum format=AL_FORMAT_MONO16; bLoadedOk = false; if(!isStreaming){ readFile(fileName, buffer); }else{ stream(fileName, buffer); } int numFrames = buffer.size()/channels; if(isStreaming){ buffers.resize(channels*2); }else{ buffers.resize(channels); } alGenBuffers(buffers.size(), &buffers[0]); if(channels==1){ sources.resize(1); alGenSources(1, &sources[0]); err = alGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "loadSound(): couldn't generate source for \"" << fileName << "\": " << (int) err << " " << getALErrorString(err); return false; } for(int i=0; i<(int)buffers.size(); i++){ alBufferData(buffers[i],format,&buffer[0],buffer.size()*2,samplerate); err = alGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer:") << "loadSound(): couldn't create buffer for \"" << fileName << "\": " << (int) err << " " << getALErrorString(err); return false; } if(isStreaming){ stream(fileName,buffer); } } if(isStreaming){ alSourceQueueBuffers(sources[0],buffers.size(),&buffers[0]); }else{ alSourcei (sources[0], AL_BUFFER, buffers[0]); } alSourcef (sources[0], AL_PITCH, 1.0f); alSourcef (sources[0], AL_GAIN, 1.0f); alSourcef (sources[0], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[0], AL_SOURCE_RELATIVE, AL_TRUE); }else{ vector<vector<short> > multibuffer; multibuffer.resize(channels); sources.resize(channels); alGenSources(channels, &sources[0]); if(isStreaming){ for(int s=0; s<2;s++){ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[s*2+i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); err = alGetError(); if ( err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "loadSound(): couldn't create stereo buffers for \"" << fileName << "\": " << (int) err << " " << getALErrorString(err); return false; } alSourceQueueBuffers(sources[i],1,&buffers[s*2+i]); stream(fileName,buffer); } } }else{ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); err = alGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "loadSound(): couldn't create stereo buffers for \"" << fileName << "\": " << (int) err << " " << getALErrorString(err); return false; } alSourcei (sources[i], AL_BUFFER, buffers[i] ); } } for(int i=0;i<channels;i++){ err = alGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "loadSound(): couldn't create stereo sources for \"" << fileName << "\": " << (int) err << " " << getALErrorString(err); return false; } // only stereo panning if(i==0){ float pos[3] = {-1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); }else{ float pos[3] = {1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); } alSourcef (sources[i], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[i], AL_SOURCE_RELATIVE, AL_TRUE); } } bLoadedOk = true; return bLoadedOk; }
// ---------------------------------------------------------------------------- ofOpenALSoundPlayer::~ofOpenALSoundPlayer(){ unloadSound(); kiss_fftr_free(fftCfg); players.erase(this); }
//------------------------------------------------------------ ofxSoundPlayer::~ofxSoundPlayer(){ unloadSound(); if(_engine) delete _engine; }
//------------------------------------------------------------ bool ofOpenALSoundPlayer::loadSound(string fileName, bool is_stream){ string ext = ofToLower(ofFilePath::getFileExt(fileName)); if(ext != "wav" && ext != "aif" && ext != "aiff" && ext != "mp3"){ ofLogError("Sound player can only load .wav .aiff or .mp3 files"); return false; } fileName = ofToDataPath(fileName); checkErrors("pre initiaze OpenAL " + fileName); // try to unload any previously loaded sounds // & prevent user-created memory leaks // if they call "loadSound" repeatedly, for example unloadSound(); if(!checkErrors("unloading previous OpenAL " + fileName)){ return false; } //bLoadedOk = false; bMultiPlay = false; isStreaming = is_stream; // init sound systems, if necessary initialize(); if(!checkErrors("initializing OpenAL " + fileName)){ return false; } ALenum format = AL_FORMAT_MONO16; if(!isStreaming || ext == "mp3"){ // mp3s don't stream cause they gotta be decoded readFile(fileName, buffer); if(!checkErrors("reading file " + fileName)){ return false; } }else{ stream(fileName, buffer); if(!checkErrors("opening file for streaming " + fileName)){ return false; } } if(channels == 0){ ofLogError("ofOpenALSoundPlayer -- File not found"); return false; } int numFrames = buffer.size()/channels; if(isStreaming){ buffers.resize(channels*2); }else{ buffers.resize(channels); } ALenum err; alGenBuffers(buffers.size(), &buffers[0]); if(channels==1){ sources.resize(1); alGenSources(1, &sources[0]); if(!checkErrors("generating sources for " + fileName)){ return false; } for(int i=0; i<(int)buffers.size(); i++){ alBufferData(buffers[i],format,&buffer[0],buffer.size()*2,samplerate); if(!checkErrors("creating bufferfor" + fileName)){ return false; } if(isStreaming){ stream(fileName,buffer); } } if(isStreaming){ alSourceQueueBuffers(sources[0],buffers.size(),&buffers[0]); }else{ alSourcei (sources[0], AL_BUFFER, buffers[0]); } alSourcef (sources[0], AL_PITCH, 1.0f); alSourcef (sources[0], AL_GAIN, 1.0f); alSourcef (sources[0], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[0], AL_SOURCE_RELATIVE, AL_TRUE); if(!checkErrors("setting sources for " + fileName)){ return false; } } else{ vector<vector<short> > multibuffer; multibuffer.resize(channels); sources.resize(channels); alGenSources(channels, &sources[0]); if(isStreaming){ for(int s=0; s<2;s++){ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[s*2+i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); if(!checkErrors("creating stereo buffers for " + fileName)){ return false; } alSourceQueueBuffers(sources[i],1,&buffers[s*2+i]); stream(fileName,buffer); } } }else{ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); if(!checkErrors("creating stereo buffers for " + fileName)){ return false; } alSourcei (sources[i], AL_BUFFER, buffers[i] ); } } for(int i=0;i<channels;i++){ // only stereo panning if(i==0){ float pos[3] = {-1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); }else{ float pos[3] = {1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); } alSourcef (sources[i], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[i], AL_SOURCE_RELATIVE, AL_TRUE); if(!checkErrors("creating stereo sources for " + fileName)){ return false; } } } ofLogVerbose("ofOpenALSoundPlayer: successfully loaded " + fileName); bLoadedOk = true; return true; }
// ---------------------------------------------------------------------------- ofOpenALSoundPlayer_TimelineAdditions::~ofOpenALSoundPlayer_TimelineAdditions(){ unloadSound(); kiss_fftr_free(fftCfg); players.erase(this); }
ofFmodSoundPlayer::~ofFmodSoundPlayer(){ unloadSound(); }
void PCMAudioManager::unloadSound(const char *assetName) { S32 soundId = getSoundId(assetName); unloadSound(soundId); }
void resources_unload() { int id; void * vp; for (id = Resource_SCREENCONGRATS; id >= Resource_PALETTE; --id) { switch (id) { case Resource_PALETTE: { vp = game_colors; unloadRawData(&vp, &game_color_count); game_colors = vp; break; } case Resource_ENTDATA: unloadResourceEntdata(); break; case Resource_SPRSEQ: { vp = ent_sprseq; unloadRawData(&vp, &ent_nbr_sprseq); ent_sprseq = vp; break; } case Resource_MVSTEP: { vp = ent_mvstep; unloadRawData(&vp, &ent_nbr_mvstep); ent_mvstep = vp; break; } case Resource_MAPS: unloadResourceMaps(); break; case Resource_SUBMAPS: unloadResourceSubmaps(); break; case Resource_CONNECT: { vp = map_connect; unloadRawData(&vp, &map_nbr_connect); map_connect = vp; break; } case Resource_BNUMS: { vp = map_bnums; unloadRawData(&vp, &map_nbr_bnums); map_bnums = vp; break; } case Resource_BLOCKS: { vp = map_blocks; unloadRawData(&vp, &map_nbr_blocks); map_blocks = vp; break; } case Resource_MARKS: { vp = map_marks; unloadRawData(&vp, &map_nbr_marks); map_marks = vp; break; } case Resource_EFLGC: { vp = map_eflg_c; unloadRawData(&vp, &map_nbr_eflgc); map_eflg_c = vp; break; } case Resource_IMAPSL: { vp = screen_imapsl; unloadRawData(&vp, &screen_nbr_imapsl); screen_imapsl = vp; break; } case Resource_IMAPSTEPS: unloadResourceImapsteps(); break; case Resource_IMAPSOFS: { vp = screen_imapsofs; unloadRawData(&vp, &screen_nbr_imapsofs); screen_imapsofs = vp; break; } case Resource_IMAPTEXT: unloadResourceImaptext(); break; case Resource_GAMEOVERTXT: unloadString((char **)(&screen_gameovertxt)); break; case Resource_PAUSEDTXT: unloadString((char **)(&screen_pausedtxt)); break; case Resource_SPRITESDATA: unloadResourceSpritesData(); break; case Resource_TILESDATA: unloadResourceTilesData(); break; case Resource_HIGHSCORES: unloadResourceHighScores(); break; case Resource_IMGSPLASH: unloadImage(&img_splash); break; #ifdef GFXST case Resource_PICHAF: unloadPicture(&pic_haf); break; case Resource_PICCONGRATS: unloadPicture(&pic_congrats); break; case Resource_PICSPLASH: unloadPicture(&pic_splash); break; #endif /* GFXST */ #ifdef GFXPC case Resource_IMAINHOFT: unloadString((char **)(&screen_imainhoft)); break; case Resource_IMAINRDT: unloadString((char **)(&screen_imainrdt)); break; case Resource_IMAINCDC: unloadString((char **)(&screen_imaincdc)); break; case Resource_SCREENCONGRATS: unloadString((char **)(&screen_congrats)); break; #endif /* GFXPC */ default: break; } } #ifdef ENABLE_SOUND for (id = Resource_SOUNDWALK; id >= Resource_SOUNDBOMBSHHT; --id) { unloadSound(id); } #endif /* ENABLE_SOUND */ unloadResourceFilelist(); }
//------------------------------------------------------------ void ofQuicktimeSoundPlayer::loadSound(string fileName, bool stream){ fileName = ofToDataPath(fileName); // TODO: hmm? bMultiPlay = false; // [1] init fmod, if necessary initializeQuicktime(); // [2] try to unload any previously loaded sounds // & prevent user-created memory leaks // if they call "loadSound" repeatedly, for example if (bLoadedOk == true){ unloadSound(); } // [3] load sound OSErr error; //CFBundleRef gameBundle = CFBundleGetMainBundle(); // Find the file in the application bundle. CFURLRef movieFileLocation; movieFileLocation = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)fileName.c_str(), strlen(fileName.c_str()), false); //CFBundleCopyResourceURL(gameBundle, filename, fileExtension, subdirectory); if (movieFileLocation == NULL) return; Handle dataRef; OSType dataRefType; dataRef = NewHandle(sizeof(AliasHandle)); // Get the movie file set up so we can load it in memory. // The second parameter to QTNewDataReferenceFromCFURL is flags. // It should be set to 0. error = QTNewDataReferenceFromCFURL(movieFileLocation, 0, &dataRef, &dataRefType); if(error != noErr) { DisposeHandle(dataRef); CFRelease(movieFileLocation); return; } // Get the movie into memory short fileID = movieInDataForkResID; short flags = 0; error = NewMovieFromDataRef(&soundToPlay, flags, &fileID, dataRef, dataRefType); // Dispose of the memory we allocated. DisposeHandle(dataRef); CFRelease(movieFileLocation); // TODO: check here! bLoadedOk = true; }
ofQuicktimeSoundPlayer::~ofQuicktimeSoundPlayer(){ if (bLoadedOk){ unloadSound(); } }
//------------------------------------------------------------ bool ofOpenALSoundPlayer_TimelineAdditions::loadSound(string fileName, bool is_stream){ string ext = ofToLower(ofFilePath::getFileExt(fileName)); if(ext != "wav" && ext != "aif" && ext != "aiff"){ ofLogError("Sound player can only load .wav or .aiff files"); return false; } fileName = ofToDataPath(fileName); bLoadedOk = false; bMultiPlay = false; isStreaming = is_stream; // [1] init sound systems, if necessary initialize(); // [2] try to unload any previously loaded sounds // & prevent user-created memory leaks // if they call "loadSound" repeatedly, for example unloadSound(); ALenum format=AL_FORMAT_MONO16; if(!isStreaming){ readFile(fileName, buffer); }else{ stream(fileName, buffer); } if(channels == 0){ ofLogError("ofOpenALSoundPlayer_TimelineAdditions -- File not found"); return false; } int numFrames = buffer.size()/channels; if(isStreaming){ buffers.resize(channels*2); }else{ buffers.resize(channels); } alGenBuffers(buffers.size(), &buffers[0]); if(channels==1){ sources.resize(1); alGenSources(1, &sources[0]); if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_WARNING,"ofOpenALSoundPlayer_TimelineAdditions: openAL error reported generating sources for " + fileName); return false; } for(int i=0; i<(int)buffers.size(); i++){ alBufferData(buffers[i],format,&buffer[0],buffer.size()*2,samplerate); if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: error creating buffer"); return false; } if(isStreaming){ stream(fileName,buffer); } } if(isStreaming){ alSourceQueueBuffers(sources[0],buffers.size(),&buffers[0]); }else{ alSourcei (sources[0], AL_BUFFER, buffers[0]); } alSourcef (sources[0], AL_PITCH, 1.0f); alSourcef (sources[0], AL_GAIN, 1.0f); alSourcef (sources[0], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[0], AL_SOURCE_RELATIVE, AL_TRUE); }else{ vector<vector<short> > multibuffer; multibuffer.resize(channels); sources.resize(channels); alGenSources(channels, &sources[0]); if(isStreaming){ for(int s=0; s<2;s++){ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[s*2+i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: error creating stereo buffers for " + fileName); return false; } alSourceQueueBuffers(sources[i],1,&buffers[s*2+i]); stream(fileName,buffer); } } }else{ for(int i=0;i<channels;i++){ multibuffer[i].resize(buffer.size()/channels); for(int j=0;j<numFrames;j++){ multibuffer[i][j] = buffer[j*channels+i]; } alBufferData(buffers[i],format,&multibuffer[i][0],buffer.size()/channels*2,samplerate); if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: error creating stereo buffers for " + fileName); return false; } alSourcei (sources[i], AL_BUFFER, buffers[i] ); } } for(int i=0;i<channels;i++){ if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: error creating stereo sources for " + fileName); return false; } // only stereo panning if(i==0){ float pos[3] = {-1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); }else{ float pos[3] = {1,0,0}; alSourcefv(sources[i],AL_POSITION,pos); } alSourcef (sources[i], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[i], AL_SOURCE_RELATIVE, AL_TRUE); } } ofLogVerbose("ofOpenALSoundPlayer_TimelineAdditions: successfully loaded " + fileName); bLoadedOk = true; return true; }
ofMultiDeviceSoundPlayer::~ofMultiDeviceSoundPlayer(){ unloadSound(); }