void free_ship (RACE_DESC *raceDescPtr, BOOLEAN FreeIconData, BOOLEAN FreeBattleData) { if (raceDescPtr->uninit_func != NULL) (*raceDescPtr->uninit_func) (raceDescPtr); if (FreeBattleData) { DATA_STUFF *shipData = &raceDescPtr->ship_data; free_image (shipData->special); free_image (shipData->weapon); free_image (shipData->ship); DestroyDrawable ( ReleaseDrawable (shipData->captain_control.background)); DestroyMusic (shipData->victory_ditty); DestroySound (ReleaseSound (shipData->ship_sounds)); } if (FreeIconData) { SHIP_INFO *shipInfo = &raceDescPtr->ship_info; DestroyDrawable (ReleaseDrawable (shipInfo->melee_icon)); DestroyDrawable (ReleaseDrawable (shipInfo->icons)); DestroyStringTable (ReleaseStringTable (shipInfo->race_strings)); } DestroyCodeRes (ReleaseCodeRes (raceDescPtr->CodeRef)); }
void FreePause(void) { FreeSprite(PauseText); FreeSprite(SFXSliderGuide); FreeSprite(BGMSliderGuide); FreeSprite(SFXSliderBack); FreeSprite(BGMSliderBack); FreeSprite(PauseBackground); FreeSprite(EnableCheats); FreeSprite(CheckMark); FreeButton(CheatsButton); FreeSprite(EnableLookAt); FreeSprite(LookAtCheckMark); FreeButton(LookAtButton); FreeButton(SFXSlider); FreeButton(BGMSlider); FreeButton(ResumeButton); FreeButton(MainMenuButton); if(GetCurrentState() != GS_MapLevel) FreeButton(RestartButton); FreeText(SFXText); FreeText(BGMText); FreeText(SFXLabel); FreeText(BGMLabel); FreeMyAlloc(volumestring); ReleaseSound(BackgroundSnd.Sound); //Keep this here otherwise sound exists foreverrrrrrrr }
// //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// void SJ_ReloadSounds( ) { SJ_DestroySounds(); FILE* fSnd = NULL; sPCMHeader pcmHeader; int bytesRead = 0; long dataSize = 0; for ( int i = 0; i < IDS_MAX; ++i ) { swprintf_s( g_txt, L"%s/sounds/%s", g_skin, s_soundBank[i].name ); fSnd = _wfopen( g_txt, L"rb" ); if ( ! fSnd ) { ReleaseSound(i); continue; } // computes data size, because subchunk2size is not always correct fseek( fSnd, 0, SEEK_END ); dataSize = ftell(fSnd) - sizeof(sPCMHeader); fseek( fSnd, 0, SEEK_SET ); if ( fread( &pcmHeader, 1, sizeof(sPCMHeader), fSnd ) == sizeof(sPCMHeader) ) { if ( ! pcmHeader.IsValidFormat() ) continue; WAVEBANKENTRY& entry = s_sounds[i].entry; entry.Format.wFormatTag = WAVEBANKMINIFORMAT_TAG_PCM; entry.Format.wBitsPerSample = pcmHeader.bitsPerSample == 16 ? WAVEBANKMINIFORMAT_BITDEPTH_16 : WAVEBANKMINIFORMAT_BITDEPTH_8; entry.Format.nChannels = pcmHeader.numChannels; entry.Format.wBlockAlign = pcmHeader.blockAlign; entry.Format.nSamplesPerSec = s_sounds[i].sampleRate = pcmHeader.sampleRate; entry.Duration = DWORD(pcmHeader.Seconds()*pcmHeader.sampleRate); entry.PlayRegion.dwLength = dataSize; s_sounds[i].soundBuffer = (BYTE*)malloc( entry.PlayRegion.dwLength );// can we reuse last allocated chunk when is lesser this one? bytesRead = fread( s_sounds[i].soundBuffer, 1, entry.PlayRegion.dwLength, fSnd ); if ( bytesRead != entry.PlayRegion.dwLength ) { ReleaseSound(i); continue; } s_pXACTEngine->PrepareInMemoryWave( XACT_FLAG_UNITS_MS, s_sounds[i].entry, NULL, s_sounds[i].soundBuffer, 0, 0, &s_sounds[i].pWave ); fclose(fSnd); } } }
void FreeMainMenu(void) { //Keep the sound playing if were only going to the options menu if(GetNextState() != GS_Options) ReleaseSound(MenuBackSnd.Sound); // Freeing the objects and textures FreeAllLists(); }
RageSoundReader_Chain::~RageSoundReader_Chain() { /* Clear m_apActiveSounds. */ while( !m_apActiveSounds.empty() ) ReleaseSound( 0 ); map<CString, SoundReader *>::iterator it; for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it ) delete it->second; }
int RageSoundReader_Chain::SetPosition_Accurate( int ms ) { /* Clear m_apActiveSounds. */ while( !m_apActiveSounds.empty() ) ReleaseSound( 0 ); m_iCurrentFrame = int( int64_t(ms) * m_iActualSampleRate / 1000 ); /* Run through all sounds in the chain, and activate all sounds which have data * at ms. */ for( unsigned i = 0; i < m_Sounds.size(); ++i ) { sound &sound = m_Sounds[i]; /* If this sound is in the future, skip it. */ if( sound.iOffsetMS > ms ) continue; /* Find the SoundReader. */ int n = ActivateSound( sound ); SoundReader *pSound = m_apActiveSounds[n].pSound; int iOffsetMS = ms - sound.iOffsetMS; if( pSound->SetPosition_Accurate(iOffsetMS) == 0 ) { /* We're past the end of this sound. */ ReleaseSound( n ); continue; } } m_iNextSound = GetNextSoundIndex(); /* If no sounds were started, and we have no sounds ahead of us, we've seeked * past EOF. */ if( m_apActiveSounds.empty() && m_iNextSound == m_Sounds.size() ) return 0; return ms; }
static void UninitKernel (BOOLEAN ships) { UninitSpace (); DestroySound (ReleaseSound (MenuSounds)); DestroyFont (MicroFont); DestroyStringTable (ReleaseStringTable (GameStrings)); DestroyDrawable (ReleaseDrawable (StatusFrame)); DestroyDrawable (ReleaseDrawable (ActivityFrame)); DestroyFont (TinyFont); DestroyFont (StarConFont); UninitQueue (&race_q[0]); UninitQueue (&race_q[1]); if (ships) FreeMasterShipList (); ActivityFrame = 0; }
// //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// void SJ_DestroySounds( ) { for ( int i = 0; i < IDS_MAX; ++i ) ReleaseSound(i); }
int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames ) { /* How many samples should we read before we need to start up a sound? */ int iFramesToRead = INT_MAX; if( m_iNextSound < m_Sounds.size() ) { int iStartFrame = m_iCurrentFrame; int iOffsetFrame = m_Sounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate); ASSERT_M( iOffsetFrame >= iStartFrame, ssprintf("%i %i", iOffsetFrame, iStartFrame) ); iFramesToRead = iOffsetFrame - iStartFrame; } iFramesToRead = min( iFramesToRead, iFrames ); if( iFramesToRead > 0 && m_apActiveSounds.size() == 1 && m_apActiveSounds.front().fPan == 0 && m_apActiveSounds.front().pSound->GetNumChannels() == m_iChannels && m_apActiveSounds.front().pSound->GetSampleRate() == m_iActualSampleRate ) { /* We have only one source, and it matches our target. Don't mix; read * directly from the source into the destination. This is to optimize * the common case of having one BGM track and no autoplay sounds. */ int iBytes = m_apActiveSounds.front().pSound->Read( (char *) pBuffer, iFramesToRead * sizeof(int16_t) * m_iChannels ); if( iBytes == 0 ) ReleaseSound( 0 ); return iBytes / (sizeof(int16_t) * m_iChannels); } if( iFramesToRead > 0 && !m_apActiveSounds.empty() ) { RageSoundMixBuffer mix; /* Read iFramesToRead from each sound. */ int16_t Buffer[2048]; iFramesToRead = min( iFramesToRead, 1024 ); int iMaxFramesRead = 0; for( unsigned i = 0; i < m_apActiveSounds.size(); ) { ActiveSound &s = m_apActiveSounds[i]; SoundReader *pSound = s.pSound; int iSamples = min( iFramesToRead * pSound->GetNumChannels(), ARRAYLEN(Buffer) ); int iBytesRead = pSound->Read( (char *) Buffer, iSamples*sizeof(int16_t) ); if( iBytesRead == -1 || iBytesRead == 0 ) { /* The sound is at EOF. Release it. */ ReleaseSound( i ); continue; } int iSamplesRead = iBytesRead / sizeof(int16_t); int iFramesRead = iSamplesRead / pSound->GetNumChannels(); iMaxFramesRead = max( iMaxFramesRead, iFramesRead ); if( m_iChannels == 2 && pSound->GetNumChannels() == 1 ) { RageSoundUtil::ConvertMonoToStereoInPlace( Buffer, iSamplesRead ); iSamplesRead *= 2; } if( fabsf(s.fPan) > 0.0001f ) RageSoundUtil::Pan( Buffer, iFramesRead, s.fPan ); mix.write( Buffer, iSamplesRead ); ++i; } /* Read mixed frames into the output buffer. */ mix.read( (int16_t *) pBuffer ); return iMaxFramesRead; } /* If we have more sounds ahead of us, pretend we read the entire block, since * there's silence in between. Otherwise, we're at EOF. */ if( iFramesToRead > 0 ) { memset( pBuffer, 0, iFramesToRead * m_iChannels * sizeof(int16_t) ); return iFramesToRead; } return 0; }