- allow setting loop points for WAV sounds or other simple formats.

This commit is contained in:
Christoph Oelckers 2023-01-15 15:18:57 +01:00
parent 57695a3e07
commit 841402a776
8 changed files with 33 additions and 8 deletions

View file

@ -131,7 +131,7 @@ public:
void SetMusicVolume (float volume)
{
}
SoundHandle LoadSound(uint8_t *sfxdata, int length)
SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end)
{
SoundHandle retval = { NULL };
return retval;

View file

@ -105,7 +105,7 @@ public:
virtual bool IsNull() { return false; }
virtual void SetSfxVolume (float volume) = 0;
virtual void SetMusicVolume (float volume) = 0;
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length) = 0;
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end) = 0;
SoundHandle LoadSoundVoc(uint8_t *sfxdata, int length);
virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1) = 0;
virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory

View file

@ -1096,7 +1096,7 @@ SoundHandle OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, int length, int
return retval;
}
SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length)
SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end)
{
SoundHandle retval = { NULL };
ALenum format = AL_NONE;
@ -1106,7 +1106,16 @@ SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length)
uint32_t loop_start = 0, loop_end = ~0u;
zmusic_bool startass = false, endass = false;
if (def_loop_start < 0)
{
FindLoopTags(sfxdata, length, &loop_start, &startass, &loop_end, &endass);
}
else
{
loop_start = def_loop_start;
loop_end = def_loop_end;
startass = endass = true;
}
auto decoder = CreateDecoder(sfxdata, length, true);
if (!decoder)
return retval;

View file

@ -34,7 +34,7 @@ public:
virtual void SetSfxVolume(float volume);
virtual void SetMusicVolume(float volume);
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length);
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end);
virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1);
virtual void UnloadSound(SoundHandle sfx);
virtual unsigned int GetMSLength(SoundHandle sfx);

View file

@ -382,7 +382,7 @@ static float CalcPitch(int pitchmask, float defpitch, float defpitchmax)
{
if (defpitchmax > 0.0 && defpitch != defpitchmax)
{
defpitch = pr_soundpitch.GenRand_Real1() * (defpitchmax - defpitch) + defpitch;
defpitch = (float)pr_soundpitch.GenRand_Real1() * (defpitchmax - defpitch) + defpitch;
}
return defpitch;
}
@ -769,7 +769,7 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx)
// If that fails, let the sound system try and figure it out.
else
{
sfx->data = GSnd->LoadSound(sfxdata.Data(), size);
sfx->data = GSnd->LoadSound(sfxdata.Data(), size, sfx->LoopStart, sfx->LoopEnd);
}
}

View file

@ -102,6 +102,7 @@ constexpr FSoundID INVALID_SOUND = FSoundID::fromInt(-1);
int RawRate = 0; // Sample rate to use when bLoadRAW is true
int LoopStart = -1; // -1 means no specific loop defined
int LoopEnd = -1; // -1 means no specific loop defined
FSoundID link = NO_LINK;
constexpr static FSoundID NO_LINK = FSoundID::fromInt(-1);

View file

@ -62,6 +62,7 @@ enum SICommands
SI_PitchSet,
SI_PitchSetDuke,
SI_DukeFlags,
SI_Loop,
};
@ -95,6 +96,7 @@ static const char *SICommandStrings[] =
"$pitchset",
"$pitchsetduke",
"$dukeflags",
"$loop",
NULL
};
@ -380,6 +382,19 @@ static void S_AddSNDINFO (int lump)
}
case SI_Loop: {
// dukesound <logical name> <start> <end>
// Sets loop points for the given sound in samples. Only really useful for WAV - for Ogg and FLAC use the metadata they can contain.
sc.MustGetString();
auto sfxid = soundEngine->FindSoundTentative(sc.String, DEFAULT_LIMIT);
auto sfx = soundEngine->GetWritableSfx(sfxid);
sc.MustGetNumber();
sfx->LoopStart = sc.Number;
if (sc.CheckNumber())
sfx->LoopEnd = sc.Number;
break;
}
default:
{ // Got a logical sound mapping

View file

@ -526,7 +526,7 @@ int S_PlaySound3D(FSoundID soundid, DDukeActor* actor, const DVector3& pos, int
{
if (explosion && underwater)
{
pitch = chan->Pitch? chan->Pitch * (0.55 / 128) : 0.55; // todo: fix pitch storage in backend.
pitch = float(chan->Pitch? chan->Pitch * (0.55 / 128) : 0.55); // todo: fix pitch storage in backend.
soundEngine->SetPitch(chan, pitch);
}
chan->UserData = (currentCommentarySound != NO_SOUND);