]> OzVa Git service - audio-over-stft/commitdiff
Changed loop.py to chache spectrograms
authorwill <greenwoodw50@gmail.com>
Tue, 10 Sep 2024 16:27:32 +0000 (17:27 +0100)
committerwill <greenwoodw50@gmail.com>
Tue, 10 Sep 2024 17:05:46 +0000 (18:05 +0100)
fft.py [changed mode: 0644->0755]
loop.py

diff --git a/fft.py b/fft.py
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/loop.py b/loop.py
index e0c534ad0e37bbef24ba737842d8deadebd33621..3665bc8789deb5b68472f3a93bf2eb24b67ad9b5 100755 (executable)
--- a/loop.py
+++ b/loop.py
@@ -90,6 +90,8 @@ def process_loop(
        print("caching data...")
        caching = True
 
+       all_spectrums = np.zeros((segment_count, window_height, window_size, 3), dtype=np.uint8)
+
        for segment_index in tqdm(range(segment_count)):
                # get the specturm of the current sample
                segment_start = segment_index * segment_samples
@@ -108,7 +110,8 @@ def process_loop(
                if segment_index == 10:
                        cv.imwrite("spectrum_sample.jpg", spectrum)
 
-               np.save(f"cache/frame{segment_index}.npy", spectrum)
+               all_spectrums[segment_index] = spectrum
+               #np.save(f"cache/frame{segment_index}.npy", spectrum)
 
        segment_index = 0
        print("cached!")
@@ -116,7 +119,7 @@ def process_loop(
 
        while segment_index < segment_count:
 
-               spectrum = np.load(f"cache/frame{segment_index}.npy")
+               spectrum = all_spectrums[segment_index]#np.load(f"cache/frame{segment_index}.npy")
 
                # display and capture
                camera.display(spectrum)
@@ -164,6 +167,8 @@ notes:
        bigger windows are exponentially better so you should prefer this if possible
        obviously the biggest you can use is the size of your display unless you have
        some way of arranging the pixles independant of the orrigional spectrogram.
+       This should ideally be one of n^2 (possibly n^2 * m^3????).
+       e.g.: 64 81 100 121 144 169 192 225
 - Window height
        This is the height of the image, or, the number of ffts performed in one "batch".
        This batching is multithreaded and therefore has some effect on process speed.
@@ -171,9 +176,11 @@ notes:
 
 # define parameters
 sample_rate = 22_050
-window_size = 150
+window_size = 144
 window_height = 80
 
+hop_size = window_size // 2
+
 caching = False
 
 if __name__ == "__main__":