acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

spectrum.py (691B)

      1 import numpy as np
      2 import librosa
      3 import math
      4 import sys
      5 
      6 print("Loading file")
      7 audio, sample_rate = librosa.load(sys.argv[1], duration=60, offset=0, sr=15360)
      8 
      9 print("Getting spectrum")
     10 spectrum = librosa.stft(audio)
     11 S = np.abs(spectrum)
     12 
     13 fout = open("spectrum.h", "w")
     14 
     15 print("Writing file")
     16 fn = 36
     17 fs = int(len(S) / fn)
     18 fout.write("const uint16_t spectrum[][4] = {\n")
     19 for t in range(0,len(S[0]-1)):
     20   fout.write("{ ")
     21   f_prev = 0
     22   for f in [8, 45, 300, 600]:
     23     v = 0
     24     for i in range(f_prev, f): v += S[i][t]
     25     if v != 0: v = int(v/30)
     26     if v < 0:  v = 0
     27     f_prev = f
     28     fout.write(str(int(v)) + ", ")
     29   fout.write("},\n")
     30 fout.write("};\n")
     31 fout.close()
     32 
     33 print("Finished")