Revert FFT ulab example to older API.

* Will not update ulab in this release.
This commit is contained in:
iabdalkader 2020-12-06 21:11:57 +02:00
parent feb0551629
commit d68bc7c779

View File

@ -1,6 +1,5 @@
import image, audio, time
from ulab import numpy as np
from ulab import scipy as sp
import image, audio, time, array, math, ulab as np
from ulab import extras, numerical
SIZE = 512//4
raw_buf = None
@ -18,7 +17,7 @@ audio.start_streaming(audio_callback)
def draw_fft(img, fft_buf):
fft_buf = (fft_buf / max(fft_buf)) * SIZE
fft_buf = np.log10(fft_buf + 1) * 20
fft_buf = np.vector.log10(fft_buf + 1) * 20
color = (0xFF, 0x0F, 0x00)
for i in range(0, SIZE):
img.draw_line(i, SIZE, i, SIZE-int(fft_buf[i]), color, 1)
@ -32,11 +31,11 @@ def draw_audio_bar(img, level, offset):
while (True):
if (raw_buf != None):
pcm_buf = np.frombuffer(raw_buf, dtype=np.int16)
pcm_buf = pcm_buf = np.array(array.array('h', raw_buf))
raw_buf = None
fft_buf = sp.signal.spectrogram(pcm_buf[0::2])
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
r_lvl = int((np.mean(abs(pcm_buf[0::2])) / 32768)*100)
fft_buf = extras.spectrogram(pcm_buf[0::2])
l_lvl = int((numerical.mean(abs(pcm_buf[1::2])) / 32768)*100)
r_lvl = int((numerical.mean(abs(pcm_buf[0::2])) / 32768)*100)
fb.clear()
draw_fft(fb, fft_buf)
draw_audio_bar(fb, l_lvl, 0)