From fdf8ddd0f6934c031603b145a158e2060c715ca6 Mon Sep 17 00:00:00 2001 From: a1lazydog Date: Wed, 7 Aug 2024 20:04:08 -0700 Subject: [PATCH] Fixing drifting frames from samples (#26) * Merge from main (#16) * Modified NormalizedAmplitudeToNumber and added FloatArrayToGraph (#8) * added my 2 nodes * fixed broken new node mod got it working again * modifications example modified the normalized to float/int node to include an addative input, with ceiling control and threshold activation. added float array to graph node * Add Load VHS Audio node (#13) Add a node to load audio from Video Helper Suite, which exports a lambda for lazy loading. Co-authored-by: Isaac Emesowum * Return the limit of frames used rather than total if a limit is specificed in the AudioToFFTs * Clean up duplicate function * Updated basic example --------- Co-authored-by: PhotoniX Co-authored-by: iemesowum Co-authored-by: Isaac Emesowum * Updating the two amplitude example * Updated full example * Updated so that LoadAudio no longer name collison with ComfyUI's "LoadAudio": - Removed "LoadAudio" as a node. Instead use LoadVHSAudio or AudioToAudioData to either load from vhs node suite or from ComfyUI's LoadAudio - Changed the "AUDIO" type to "AUDIO_DATA" type to not clash with ComfyUI's "AUDIO" type * Removed LoadVHSAudio. No longer needed as "AudioToAudioData" can fulfill the role for both the VHS audio loading and the regular one * Updating the examples * Fixing sample frame drift due to rounding up errors. Instead, keep rounding through each loop. --------- Co-authored-by: PhotoniX Co-authored-by: iemesowum Co-authored-by: Isaac Emesowum --- nodes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodes.py b/nodes.py index 76405c1..9c6f1c2 100644 --- a/nodes.py +++ b/nodes.py @@ -85,7 +85,7 @@ class AudioToFFTs: # Number of samples in the audio data total_samples = len(audio_data) - samples_per_frame = int(np.ceil(audio.sample_rate / frames_per_second)) + samples_per_frame = audio.sample_rate / frames_per_second # Calculate the number of frames total_frames = int(np.ceil(total_samples / samples_per_frame)) @@ -112,8 +112,10 @@ class AudioToFFTs: if i_next >= total_samples: i_next = total_samples + i_current = i * samples_per_frame + # Extract the current frame of audio data - frame = audio_data[i * samples_per_frame : i_next] + frame = audio_data[round(i_current) : round(i_next)] ffts.append(AudioFFTData(frame, audio.sample_rate))