void Button::PlaySound(int n) { Sound* sound = 0; switch (n) { default: case SND_BUTTON: if (button_sound) sound = button_sound->Duplicate(); break; case SND_CLICK: if (click_sound) sound = click_sound->Duplicate(); break; case SND_SWISH: if (swish_sound) sound = swish_sound->Duplicate(); break; case SND_CHIRP: if (chirp_sound) sound = chirp_sound->Duplicate(); break; case SND_ACCEPT: if (accept_sound) sound = accept_sound->Duplicate(); break; case SND_REJECT: if (reject_sound) sound = reject_sound->Duplicate(); break; case SND_CONFIRM: if (confirm_sound) sound = confirm_sound->Duplicate(); break; case SND_LIST_SELECT: if (list_select_sound) sound = list_select_sound->Duplicate(); break; case SND_LIST_SCROLL: if (list_scroll_sound) sound = list_scroll_sound->Duplicate(); break; case SND_LIST_DROP: if (list_drop_sound) sound = list_drop_sound->Duplicate(); break; case SND_COMBO_OPEN: if (combo_open_sound) sound = combo_open_sound->Duplicate(); break; case SND_COMBO_CLOSE: if (combo_close_sound) sound = combo_close_sound->Duplicate(); break; case SND_COMBO_HILITE: if (combo_hilite_sound) sound = combo_hilite_sound->Duplicate(); break; case SND_COMBO_SELECT: if (combo_select_sound) sound = combo_select_sound->Duplicate(); break; case SND_MENU_OPEN: if (menu_open_sound) sound = menu_open_sound->Duplicate(); break; case SND_MENU_CLOSE: if (menu_close_sound) sound = menu_close_sound->Duplicate(); break; case SND_MENU_SELECT: if (menu_select_sound) sound = menu_select_sound->Duplicate(); break; case SND_MENU_HILITE: if (menu_hilite_sound) sound = menu_hilite_sound->Duplicate(); break; } if (sound) { sound->SetVolume(gui_volume); sound->Play(); } }
Sound * Sound::CreateFX(const String & fileName, eType type, int32 priority /*= 0*/) { Sound * sound = new Sound(fileName, type, priority); SoundSystem::Instance()->GroupFX()->AddSound(sound); sound->Init(); return sound; }
size_t yarp::sig::file::soundStreamReader::readBlock(Sound& dest, size_t block_size) { int expected_bytes = block_size*(soundInfo.bits/8)*soundInfo.channels; //this probably works only if soundInfo.bits=16 int expected_words=expected_bytes/(soundInfo.bits/8); NetInt16 *data = new NetInt16 [expected_words]; int bytes_read = fread(data,1,expected_bytes,fp); int samples_read = bytes_read/(soundInfo.bits/8)/soundInfo.channels; dest.resize(samples_read,soundInfo.channels); dest.setFrequency(soundInfo.freq); int ct = 0; for (int i=0; i<samples_read; i++) { for (int j=0; j<soundInfo.channels; j++) { dest.set(data[ct],i,j); ct++; } } index+=samples_read; delete [] data; return samples_read; }
Sound* SoundSystem::PlayStreamingSound(SoundID soundID, int loopCount, float volumeLevel) { Sound* soundPicked = NULL; SoundMap ::iterator soundIDIter = m_soundMap.find(soundID); if(soundIDIter!= m_soundMap.end()) { //bool playedSound = false; Sounds& sounds = soundIDIter->second; for (Sounds::iterator soundIter = sounds.begin(); soundIter != sounds.end(); ++soundIter) { Sound* sound = (*soundIter); if(sound->IsPlaying() &&sound->IsReady()) continue; sound->Play(loopCount,volumeLevel); // playedSound = true; soundPicked = sound; break; } /* if(soundPicked) { } */ } return soundPicked ; }
void destroy_on_finish(ga_Handle* in_handle, void* in_context) { Sound* sound = (Sound*)in_handle->sound; sound->m_Count--; if (sound->m_Count == 0) sound->stop(); }
std::string Sound::nextSoundValue(int direction, std::string sound) { if ( sound == "UNSET" ) sound = SoundBank[0][0][0]; std::map<std::string,Sound>::iterator it = Sounds.find(sound); if ( it == Sounds.end() ) { NosuchDebug("Hey! no sound=%s in Sound!? returning same sound",sound.c_str()); return sound; } int pnum = Sounds[sound].patchnum(); std::string synth = Sounds[sound].synth(); int npnum = pnum + direction; if ( npnum < 0 ) npnum = 0; // Go through the sounds and find the same synth with the new patchnum it = Sounds.begin(); NosuchDebug("Looking for sound for synth=%s patchnum=%d",synth.c_str(),npnum); for ( ; it!=Sounds.end(); it++ ) { std::string soundname = it->first; Sound s = it->second; if ( s.synth() == synth && s.patchnum() == npnum ) { NosuchDebug("Found sound! name=%s",soundname.c_str()); return soundname; } } NosuchErrorOutput("Unable to find next sound dir=%d sound=%s",direction,sound.c_str()); return sound; }
void TestScene::Init() { font = new DxFont(); this->AppendObject(font, 1, true); this->AppendItemBox("font", font); tex = new Texture("soccerball.png"); sprite = new Sprite(tex); this->AppendItemBox("tex", tex); this->AppendItemBox("sprite", sprite); r=0.f; AppendObject(new BGMusic("Kalimba.mp3"), 5, "BGM", true); AppendItemBox("BGM", FindObject("BGM")); bgm = dynamic_cast<BGMusic*>(this->FindItemBox("BGM")); //if(bgm) bgm->Play(); input = (Input*)FindObject("input"); if(input == NULL){ input = new Input(); AppendObject(input, 0, "input", true); } sound.Load("missile.wav"); Sound *se = new Sound(*(Sound*)FindItemBox("burst")); //se->EnableDeleteByEnd(); se->Play(); }
Sound* SoundD3D::Duplicate() { Sound* sound = 0; if (flags & RESOURCE) { sound = Sound::Create(flags & ~RESOURCE, &wfex); if (sound && !(flags & STREAMED)) { sound->SetMinDistance(min_dist); sound->SetMaxDistance(max_dist); if (!buffer) { sound->Load(data_len, data); } else { SoundD3D* s3d = (SoundD3D*) sound; soundcard->DuplicateSoundBuffer(buffer, &s3d->buffer); sound->Rewind(); } } } return sound; }
void WPN_Init(TextureManager& textureManager, Sound& sound, Console& console) { std::set<Int32> nearestFilterBoom = { 5, 6, 9, 13, 14, 15, 16 }; console.printLine("\n===Weapon initialization==="); for (Weapon& weap : d6WpnDef) { const std::string wpnPath = Format("{0}{1,3|0}") << D6_TEXTURE_WPN_PATH << weap.index; weap.textures.boom = textureManager.load(Format("{0}/boom/") << wpnPath, nearestFilterBoom.find(weap.index) != nearestFilterBoom.end() ? GL_NEAREST : GL_LINEAR, true); weap.textures.gun = textureManager.load(Format("{0}/gun/") << wpnPath, GL_NEAREST, true); weap.textures.shot = textureManager.load(Format("{0}/shot/") << wpnPath, GL_NEAREST, true); if (weap.shotSound) { weap.shotSample = sound.loadSample(std::string(D6_FILE_WEAPON_SOUNDS) + weap.shotSound); } if (weap.boomSound) { weap.boomSample = sound.loadSample(std::string(D6_FILE_WEAPON_SOUNDS) + weap.boomSound); } } Color brownColor(83, 44, 0); PlayerSkinColors skinColors(brownColor); brownSkin = std::make_unique<PlayerSkin>("textures/man/", skinColors, textureManager); }
void Sound::play(int name) { if (!f_enabled) { return; } Sound* sound = f_sound_objects.value(name); if (!sound || !sound->isValid()) { return; } QSound* qsound = 0; QList<QSound*>& sounds = f_sounds[sound->m_id]; int count = sounds.count(); for (int i = 0; i < count; ++i) { if (sounds.at(i)->isFinished()) { qsound = sounds.at(i); break; } } if (qsound == 0) { qsound = new QSound(sounds.first()->fileName()); sounds.append(qsound); } qsound->play(); }
Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) { Sound sound; bool isInline = false; TextValue *v = (TextValue *)cl->value(); ParamList params = cl->paramList(); ParamListIterator it( params ); for( ; it.current(); ++it ) { if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) isInline = true; } if ( isInline ) { QByteArray data; if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); if ( file.open( IO_ReadOnly ) ) { data = file.readAll(); file.close(); } } else { KCodecs::base64Decode( v->asString(), data ); } sound.setData( data ); } else { sound.setUrl( QString::fromUtf8( v->asString() ) ); } return sound; }
bool Slider::OnMouseClick() { if (OnMouseHover() == true) { if (MouseManager::GetInstance()->ButtonPressed(eMouseButtons::eLeft) == true) { if (myIsDraggingKnob == false) { Sound* SoundPtr = SoundFileHandler::GetInstance()->GetSound("ButtonClick"); SoundPtr->SetLooping(false); SoundPtr->PlaySound(); SoundPtr->SetVolume(0.4f); } return true; } else { return false; } } return false; }
bool Slider::OnMouseHover() { if (MouseManager::GetInstance()->GetPosition().x >= myKnob->GetPosition().x - myKnob->GetSize().x / 2 && MouseManager::GetInstance()->GetPosition().x <= myKnob->GetPosition().x + myKnob->GetSize().x / 2) { if (MouseManager::GetInstance()->GetPosition().y + 0.010f >= myKnob->GetPosition().y - myKnob->GetSize().y / 2 && MouseManager::GetInstance()->GetPosition().y - 0.010f <= myKnob->GetPosition().y + myKnob->GetSize().y / 2) { if (myIsHoveringKnob == false) { Sound* SoundPtr = SoundFileHandler::GetInstance()->GetSound("ButtonHover"); SoundPtr->SetVolume(0.6f); SoundPtr->SetLooping(false); SoundPtr->PlaySound(); } return true; } else { return false; } } return false; }
Explosion::Explosion() { Sound *s = Client::getSound(); _nbrSprite = 0; _delete = false; s->playSound("explosion1"); }
/**\brief Update function on every frame. */ void Ship::Update( lua_State *L ) { Sprite::Update( L ); // update momentum and other generic sprite attributes if( status.isAccelerating == false && status.isRotatingLeft == false && status.isRotatingRight == false) { flareAnimation->Reset(); } flareAnimation->Update(); Coordinate momentum = GetMomentum(); momentum.EnforceMagnitude( shipStats.GetMaxSpeed()*engineBooster ); // Show the hits taken as part of the radar color if(IsDisabled()) SetRadarColor( GREY ); else SetRadarColor( RED * GetHullIntegrityPct() ); // Ship has taken as much damage as possible... // It Explodes! if( status.hullDamage >= (float)shipStats.GetHullStrength() ) { SpriteManager *sprites = Simulation_Lua::GetSimulation(L)->GetSpriteManager(); Camera* camera = Simulation_Lua::GetSimulation(L)->GetCamera(); // Play explode sound if(OPTION(int, "options/sound/explosions")) { Sound *explodesnd = Sound::Get("Resources/Audio/Effects/18384__inferno__largex.wav.ogg"); explodesnd->Play( GetWorldPosition() - camera->GetFocusCoordinate()); } // Create Explosion sprites->Add( new Effect( GetWorldPosition(), "Resources/Animations/explosion1.ani", 0) ); // Remove this Sprite from the SpriteManager sprites->Delete( (Sprite*)this ); }
void MasterControl::Start() { new InputMaster(context_, this); cache_ = GetSubsystem<ResourceCache>(); graphics_ = GetSubsystem<Graphics>(); renderer_ = GetSubsystem<Renderer>(); CreateSineLookupTable(); // Get default style defaultStyle_ = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml"); //Create console and debug HUD. CreateConsoleAndDebugHud(); //Create the scene content CreateScene(); //Create the UI content CreateUI(); //Hook up to the frame update and render post-update events SubscribeToEvents(); Sound* music = cache_->GetResource<Sound>("Resources/Music/Alien Chaos - Disorder.ogg"); //Battle music->SetLooped(true); Node* musicNode = world.scene->CreateChild("Music"); SoundSource* musicSource = musicNode->CreateComponent<SoundSource>(); musicSource->SetGain(0.32f); musicSource->SetSoundType(SOUND_MUSIC); musicSource->Play(music); }
void Game::playerBeenHit() { Sound* playerHitSound = m_soundManager->GetSound("Assets/Sounds/hit.wav"); playerHitSound->Play(); m_player->updateHealth(-1); m_player->SetPosition(Vector3::Zero); m_player->Update(0.28); //send the objects away from you so you won't be hit right away for (int i = 0; i < m_gameObjects.size(); i++) { if (m_gameObjects[i]->GetObjectType() == "BoxEnemy") { m_gameObjects[i]->SetPosition(Vector3(rand() % 40, 0.8f, rand() % 40)); } if (m_gameObjects[i]->GetObjectType() == "SphereEnemy") { static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->SetPosition(static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->Owner->GetPosition()); static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->setState(1); } } }
/******************************************************************************** Hero Move Up Down ********************************************************************************/ void CPlayerInfo::MoveUpDown(const bool mode, CAIManager* ai_manager, int tileSize, Sound soundMove) { if (mode) { theHeroTargetPosNode = theHeroTargetPosNode->up; heroAnimationInvert = false; heroAnimationDirection = UP; if(!CPlayerInfo::CheckCollisionTarget(ai_manager, tileSize)) { vel.Set(0, movementSpeed, 0); currentState = MOVING; soundMove.playSound(Sound::FOOTSTEP); } else { theHeroTargetPosNode = theHeroCurrentPosNode; } } else { theHeroTargetPosNode = theHeroTargetPosNode->down; heroAnimationInvert = false; heroAnimationDirection = DOWN; if(!CPlayerInfo::CheckCollisionTarget(ai_manager, tileSize)) { vel.Set(0, -movementSpeed, 0); currentState = MOVING; soundMove.playSound(Sound::FOOTSTEP); } else { theHeroTargetPosNode = theHeroCurrentPosNode; } } }
Command *Command::opStopPlayingSound(const ResourceReference &soundRef) { Sound *soundObj = soundRef.resolve<Sound>(); soundObj->stop(); return nextCommand(); }
/******************************************************************************** Hero Move Left Right ********************************************************************************/ void CPlayerInfo::MoveLeftRight(const bool mode, CAIManager* ai_manager, int tileSize, Sound soundMove) { if (mode) { theHeroTargetPosNode = theHeroTargetPosNode->left; heroAnimationInvert = true; heroAnimationDirection = LEFT; if(!CPlayerInfo::CheckCollisionTarget(ai_manager, tileSize)) { vel.Set(-movementSpeed, 0, 0); currentState = MOVING; soundMove.playSound(Sound::FOOTSTEP); } else { theHeroTargetPosNode = theHeroCurrentPosNode; } } else { theHeroTargetPosNode = theHeroTargetPosNode->right; heroAnimationInvert = false; heroAnimationDirection = RIGHT; if(!CPlayerInfo::CheckCollisionTarget(ai_manager, tileSize)) { vel.Set(movementSpeed, 0, 0); currentState = MOVING; soundMove.playSound(Sound::FOOTSTEP); } else { theHeroTargetPosNode = theHeroCurrentPosNode; } } }
void Source::setSound( const SoundHandle& soundHandle ) { sound = soundHandle; Sound* sound = soundHandle.Resolve(); if( !sound ) return; if( sound->getStreamed() ) mode = SourceMode::Streaming; if( !audioSource ) { AudioDevice* device = GetAudioDevice(); AudioContext* context = device->getMainContext(); audioSource = AllocateThis(AudioSource, context); } audioSource->setSound(soundHandle); setVolume(volume); setPitch(pitch); setRolloff(rolloff); setMode(mode); setState(state); }
void swap(Sound& first, Sound& second) { second.mLoops.store(first.mLoops.exchange(second.mLoops.load())); // swap the atomic loop counts // store the state of the sound's rtaudio stream bool firstSetUp = first.mRtAudioSetup; bool secondSetUp = second.mRtAudioSetup; // ensure both sound's rtaudio streams are closed first.CloseRtAudioStream(); second.CloseRtAudioStream(); std::swap(first.mSampleRate, second.mSampleRate); std::swap(first.mBufferFrames, second.mBufferFrames); std::swap(first.mNumChannels, second.mNumChannels); std::swap(first.mSamplePosition, second.mSamplePosition); std::swap(first.mSampleDataPtr, second.mSampleDataPtr); std::swap(first.mSoundBuffer, second.mSoundBuffer); if (secondSetUp) { // if the second sound's rtaudio stream was initialised... first.OpenRtAudioStream(first.mNumChannels); // initialise the first sound's rtaudio stream } if (firstSetUp) { second.OpenRtAudioStream(second.mNumChannels); } }
int Sound::load(lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_checkany(L, 2); // string or lightuserdata lua_getfield(L, 1, "udata"); if(lua_isuserdata(L, -1)) { Sound * sound = *static_cast<Sound **>(lua_touserdata(L, -1)); if(lua_type(L, 2) == LUA_TLIGHTUSERDATA) // works! { void * data = (void *)lua_touserdata(L, 2); // get data luaL_checktype(L, 3, LUA_TNUMBER); // get size luaL_checktype(L, 4, LUA_TNUMBER); // get bitrate luaL_checktype(L, 5, LUA_TNUMBER); // get channels luaL_checktype(L, 6, LUA_TNUMBER); // get samplerate //lua_pushboolean(L, static_cast<int>(sound->load(data, static_cast<int>(lua_tonumber(L, 3)), static_cast<int>(lua_tonumber(L, 4)), static_cast<int>(lua_tonumber(L, 5)), static_cast<int>(lua_tonumber(L, 6)) ))); return 1; } if(lua_type(L, 2) == LUA_TSTRING) { lua_pushboolean(L, sound->load(lua_tostring(L, 2))); return 1; } } lua_pushboolean(L, false); return 1; }
Resource* OGG_Loader::prepare(ResourceLoadOptions& options) { ResourceLoadOption& option = options.option; bool streamed = option.key == SOUND_LOAD_STREAM && option.value; Sound* sound = AllocateThis(Sound); if( !streamed) return sound; sound->setStreamed(true); options.keepStreamOpen = true; options.resource = sound; OggVorbis_File* oggFile = AllocateThis(OggVorbis_File); if( !initOgg(oggFile, options) ) { Deallocate(oggFile); Deallocate(sound); return nullptr; } OggStream* oggStream = AllocateThis(OggStream); oggStream->loader = this; oggStream->stream = options.stream; oggStream->ogg = oggFile; oggStream->begin = oggStream->ogg->offset; sound->stream = oggStream; return sound; }
Player::Player(float x, float y,GameObject* planet): deathAnimation(),body("img/Sprites_Corpo_LUP.png",0.15,4,8),speed(),dmgCD(),knockback(),energiaCD() { body.SetScaleX(0.5); body.SetScaleY(0.5); int novox = x - (body.GetFrameWidth()/2); int novoy = y - (body.GetHeight()/2); novoy += body.GetHeight()*3/2; box.setX(novox); box.setY(novoy); box.setH(body.GetHeight()); box.setW(body.GetWidth()); hp = 100; xp = 0; speed.x = 15; speed.y = 15; jumpState = DJUMP; orientation = RIGHT; jumped = 250; player = this; loopStart = 0; loopEnd = 0; this->planet = planet; knockback.Update(10); Sound* sound = new Sound("audio/Start.wav"); sound->Play(0); delete(sound); qntEnergia = 0; deveMudarDeFase = false; jumpY = 0; energyUpdate = false; kbDirection = RIGHT; c = 0; }
void s3dge::dispose_sound_callback(ga_Handle* handle, void* context) { Sound* sound = (Sound*)context; sound->_count--; if (!sound->_count) sound->Stop(); }
bool yarp::sig::file::write(const Sound& src, const char *dest) { FILE *fp = fopen(dest, "wb"); if (!fp) { printf("cannot open file %s for writing\n", dest); return false; } PcmWavHeader header; header.setup_to_write(src, fp); ManagedBytes bytes(header.dataLength); NetInt16 *data = reinterpret_cast<NetInt16*>(bytes.get()); int ct = 0; int samples = src.getSamples(); int channels = src.getChannels(); for (int i=0; i<samples; i++) { for (int j=0; j<channels; j++) { int v = src.get(i,j); data[ct] = v; ct++; } } fwrite(bytes.get(),bytes.length(),1,fp); fclose(fp); return true; }
Sound* SoundManager::Create(const String& pSoundFileName, Bool pIs3DSound) { // Ask the sound subsystem to create a sound for us. Sound* sound = Cast<Sound>(SoundSubsystem::Instance()->Create(Sound::StaticClass())); std::map<String, SoundData*>::iterator itFind = mLoadedSounds.find(pSoundFileName); if(itFind != mLoadedSounds.end()) { itFind->second->AddRef(); sound->Create(itFind->second, pIs3DSound); } else { ResourceImporter* importer = ResourceManager::Instance()->GetImporterForFile(pSoundFileName, SoundData::StaticClass()); GD_ASSERT(importer); SoundData* soundData = Cast<SoundData>(importer->Import(pSoundFileName)); mLoadedSounds[pSoundFileName] = soundData; sound->Create(soundData, pIs3DSound); sound->AddRef(); } sound->Init(); return sound; }
Sound * Sound::CreateMusic(const String & fileName, eType type, int32 priority /*= 0*/) { if(TYPE_STATIC != type && TYPE_STREAMED != type && TYPE_MANAGED != type) return 0; #if defined(__DAVAENGINE_IPHONE__) Sound * sound = new MusicIos(fileName); if(!sound->Init()) { SafeRelease(sound); } else { SoundSystem::Instance()->GroupMusic()->AddSound(sound); } return sound; #else Sound * sound = new Sound(fileName, type, priority); if(!sound->Init()) { SafeRelease(sound); } else { SoundSystem::Instance()->GroupMusic()->AddSound(sound); } return sound; #endif //#if defined(__DAVAENGINE_IPHONE__) }
void ClientConnection::processTalk(const Atlas::Objects::Operation::Talk& tk) { if (m_server->m_rooms.count(tk->getTo())) return m_server->talkInRoom(tk, tk->getTo()); if (m_server->m_accounts.count(tk->getTo())) { ClientConnection* cc = m_server->getConnectionForAccount(tk->getTo()); if (!cc) { sendError("oog chat: account is offline", tk); return; } Sound snd; snd->setFrom(m_account); snd->setArgs1(tk); snd->setTo(cc->m_account); cc->send(snd); return; } if (tk->getTo().empty()) { // lobby chat return m_server->talkInRoom(tk, "_lobby"); } sendError("bad TO for OOG TALK op: " + tk->getTo(), tk); }