From 740d52cf5b0ad71419fe30b3465041755907f0ac Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 18 Mar 2010 04:26:22 +0000 Subject: [PATCH] - Added support for Blood's SFX loop start markers. SVN r2221 (trunk) --- src/s_advsound.cpp | 13 ++++++------- src/s_sound.cpp | 8 +++++++- src/s_sound.h | 2 ++ src/sound/fmodsound.cpp | 17 +++++++++++++++-- src/sound/fmodsound.h | 2 +- src/sound/i_sound.cpp | 2 +- src/sound/i_sound.h | 2 +- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 59ec131d4..2d02432b5 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -509,6 +509,7 @@ int S_AddSoundLump (const char *logicalname, int lump) newsfx.Rolloff.RolloffType = ROLLOFF_Doom; newsfx.Rolloff.MinDistance = 0; newsfx.Rolloff.MaxDistance = 0; + newsfx.LoopStart = -1; return (int)S_sfx.Push (newsfx); } @@ -1366,18 +1367,15 @@ static void S_AddSNDINFO (int lump) static void S_AddBloodSFX (int lumpnum) { - char name[13]; - FMemLump sfxlump = Wads.ReadLump (lumpnum); + FMemLump sfxlump = Wads.ReadLump(lumpnum); const FBloodSFX *sfx = (FBloodSFX *)sfxlump.GetMem(); - int rawlump = Wads.CheckNumForName (sfx->RawName, ns_bloodraw); + int rawlump = Wads.CheckNumForName(sfx->RawName, ns_bloodraw); int sfxnum; if (rawlump != -1) { - Wads.GetLumpName (name, lumpnum); - name[8] = 0; - strcat (name, ".SFX"); - sfxnum = S_AddSound (name, rawlump); + const char *name = Wads.GetLumpFullName(lumpnum); + sfxnum = S_AddSound(name, rawlump); if (sfx->Format == 5) { S_sfx[sfxnum].bForce22050 = true; @@ -1387,6 +1385,7 @@ static void S_AddBloodSFX (int lumpnum) S_sfx[sfxnum].bForce11025 = true; } S_sfx[sfxnum].bLoadRAW = true; + S_sfx[sfxnum].LoopStart = LittleLong(sfx->LoopStart); } } diff --git a/src/s_sound.cpp b/src/s_sound.cpp index f309499df..356d5ac33 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -165,6 +165,7 @@ void S_NoiseDebug (void) screen->DrawText (SmallFont, CR_GOLD, 340, y, "pri", TAG_DONE); screen->DrawText (SmallFont, CR_GOLD, 380, y, "flags", TAG_DONE); screen->DrawText (SmallFont, CR_GOLD, 460, y, "aud", TAG_DONE); + screen->DrawText (SmallFont, CR_GOLD, 520, y, "pos", TAG_DONE); y += 8; if (Channels == NULL) @@ -253,6 +254,11 @@ void S_NoiseDebug (void) mysnprintf(temp, countof(temp), "%.4f", GSnd->GetAudibility(chan)); screen->DrawText(SmallFont, color, 460, y, temp, TAG_DONE); + // Position + mysnprintf(temp, countof(temp), "%u", GSnd->GetPosition(chan)); + screen->DrawText(SmallFont, color, 520, y, temp, TAG_DONE); + + y += 8; if (chan->PrevChan == &Channels) { @@ -1322,7 +1328,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) } sfxstart = sfxdata + 8; } - sfx->data = GSnd->LoadSoundRaw(sfxstart, len, frequency, 1, 8); + sfx->data = GSnd->LoadSoundRaw(sfxstart, len, frequency, 1, 8, sfx->LoopStart); } else { diff --git a/src/s_sound.h b/src/s_sound.h index 9ba10ac73..b616b9137 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -59,6 +59,8 @@ struct sfxinfo_t WORD bSingular:1; WORD bTentative:1; + int LoopStart; // -1 means no specific loop defined + unsigned int link; enum { NO_LINK = 0xffffffff }; diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index f8f01f2a9..f5b338295 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -2190,12 +2190,16 @@ void FMODSoundRenderer::UpdateSounds() // //========================================================================== -SoundHandle FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits) +SoundHandle FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart) { FMOD_CREATESOUNDEXINFO exinfo; SoundHandle retval = { NULL }; + int numsamples; - if (length == 0) return retval; + if (length <= 0) + { + return retval; + } InitCreateSoundExInfo(&exinfo); exinfo.length = length; @@ -2212,14 +2216,17 @@ SoundHandle FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int length, int frequ case -8: exinfo.format = FMOD_SOUND_FORMAT_PCM8; + numsamples = length; break; case 16: exinfo.format = FMOD_SOUND_FORMAT_PCM16; + numsamples = length >> 1; break; case 32: exinfo.format = FMOD_SOUND_FORMAT_PCM32; + numsamples = length >> 2; break; default: @@ -2236,6 +2243,12 @@ SoundHandle FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int length, int frequ DPrintf("Failed to allocate sample: Error %d\n", result); return retval; } + + if (loopstart >= 0) + { + sample->setLoopPoints(loopstart, FMOD_TIMEUNIT_PCM, numsamples - 1, FMOD_TIMEUNIT_PCM); + } + retval.data = sample; return retval; } diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index 3f31481bf..1460b697b 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -14,7 +14,7 @@ public: void SetSfxVolume (float volume); void SetMusicVolume (float volume); SoundHandle LoadSound(BYTE *sfxdata, int length); - SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits); + SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart); void UnloadSound (SoundHandle sfx); unsigned int GetMSLength(SoundHandle sfx); unsigned int GetSampleLength(SoundHandle sfx); diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 0009b48e2..b25bbd6fb 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -123,7 +123,7 @@ public: SoundHandle retval = { NULL }; return retval; } - SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits) + SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart) { SoundHandle retval = { NULL }; return retval; diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index 31f401093..d8cf166fc 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -92,7 +92,7 @@ public: virtual void SetSfxVolume (float volume) = 0; virtual void SetMusicVolume (float volume) = 0; virtual SoundHandle LoadSound(BYTE *sfxdata, int length) = 0; - virtual SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits) = 0; + virtual SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart) = 0; virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency