Trigger sounds: overlap instead of cutting off, and play once per frame
- A sound can play over itself: each play uses a track that isn't busy (reusing finished ones), so close triggers no longer restart each other. Rendered audio mixes them the same way. - The preview plays each frame's trigger sound once as playback reaches the frame, instead of on every tick spent in it, and no longer skips the sound of a frame passed over between ticks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef5796d667
commit
2ce8795b4a
3 files changed
+41
-28
No files matched your search
@@ -177,17 +177,22 @@ namespace anm2ed::imgui
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!manager.isRecording && !document.sounds.empty() && isSound)
|
||||
{
|
||||
if (auto soundID = trigger_sound_id_get(document, animation, playback.time); soundID != -1)
|
||||
if (auto sound = document.sound_get(soundID)) audio::play(*sound, false, mixer);
|
||||
}
|
||||
|
||||
auto fps = std::max(model.info.fps, 1);
|
||||
auto range = model::animation_play_range_get(*animation);
|
||||
if (!wasPlaybackPlaying) soundFrame = (int)std::floor(playback.time) - 1;
|
||||
playback.tick(fps, range.x, range.y, (animation->isLoop || settings.playbackIsLoop) && !manager.isRecording,
|
||||
deltaSeconds);
|
||||
|
||||
// Each frame playback reaches plays its trigger's sound once, however many ticks it lasts or skips.
|
||||
auto frame = (int)std::floor(playback.time);
|
||||
for (int step = 0; soundFrame != frame && step < range.y - range.x; ++step)
|
||||
{
|
||||
soundFrame = soundFrame + 1 >= range.y || soundFrame + 1 < range.x ? range.x : soundFrame + 1;
|
||||
if (manager.isRecording || document.sounds.empty() || !isSound) continue;
|
||||
if (auto soundID = trigger_sound_id_get(document, animation, (float)soundFrame); soundID != -1)
|
||||
if (auto sound = document.sound_get(soundID)) audio::play(*sound, false, mixer);
|
||||
}
|
||||
|
||||
frameTime = playback.time;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace anm2ed::imgui
|
||||
MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
||||
AudioStream audioStream = AudioStream(mixer);
|
||||
bool wasPlaybackPlaying{};
|
||||
int soundFrame{-1};
|
||||
bool isMoveDragging{};
|
||||
glm::vec2 moveOffset{};
|
||||
glm::vec2 nullRectScaleAnchor{};
|
||||
|
||||
Reference in new issue
Block a user