mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update ulab to 2.1.3
This commit is contained in:
parent
b276f5a91c
commit
2a190f35c0
@ -1,5 +1,6 @@
|
||||
import image, audio, time, array, math, ulab as np
|
||||
from ulab import extras, numerical
|
||||
import image, audio, time
|
||||
from ulab import numpy as np
|
||||
from ulab import scipy as sp
|
||||
|
||||
CHANNELS = 1
|
||||
SIZE = 256//(2*CHANNELS)
|
||||
@ -19,7 +20,7 @@ audio.start_streaming(audio_callback)
|
||||
|
||||
def draw_fft(img, fft_buf):
|
||||
fft_buf = (fft_buf / max(fft_buf)) * SIZE
|
||||
fft_buf = np.vector.log10(fft_buf + 1) * 20
|
||||
fft_buf = np.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)
|
||||
@ -33,20 +34,19 @@ def draw_audio_bar(img, level, offset):
|
||||
|
||||
while (True):
|
||||
if (raw_buf != None):
|
||||
pcm_buf = np.array(array.array('h', raw_buf))
|
||||
pcm_buf = np.frombuffer(raw_buf, dtype=np.int16)
|
||||
raw_buf = None
|
||||
|
||||
if CHANNELS == 1:
|
||||
fft_buf = extras.spectrogram(pcm_buf)
|
||||
l_lvl = int((numerical.mean(abs(pcm_buf)) / 32768)*100)
|
||||
fft_buf = sp.signal.spectrogram(pcm_buf)
|
||||
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
|
||||
else:
|
||||
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)
|
||||
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)
|
||||
|
||||
fb.clear()
|
||||
draw_fft(fb, fft_buf)
|
||||
|
||||
draw_audio_bar(fb, l_lvl, 0)
|
||||
if CHANNELS == 2:
|
||||
draw_audio_bar(fb, r_lvl, 25)
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import image, audio, time, array, math, ulab as np
|
||||
from ulab import extras, numerical
|
||||
import image, audio, time
|
||||
from ulab import numpy as np
|
||||
from ulab import scipy as sp
|
||||
|
||||
CHANNELS = 2
|
||||
SIZE = 512//(2*CHANNELS)
|
||||
|
||||
SIZE = 512//4
|
||||
raw_buf = None
|
||||
fb = image.Image(SIZE+50, SIZE, image.RGB565, copy_to_fb=True)
|
||||
audio.init(channels=2, frequency=16000, gain=24, highpass=0.9883)
|
||||
audio.init(channels=CHANNELS, frequency=16000, gain_db=24, highpass=0.9883)
|
||||
|
||||
def audio_callback(buf):
|
||||
# NOTE: do Not call any function that allocates memory.
|
||||
@ -17,7 +20,7 @@ audio.start_streaming(audio_callback)
|
||||
|
||||
def draw_fft(img, fft_buf):
|
||||
fft_buf = (fft_buf / max(fft_buf)) * SIZE
|
||||
fft_buf = np.vector.log10(fft_buf + 1) * 20
|
||||
fft_buf = np.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)
|
||||
@ -31,15 +34,22 @@ def draw_audio_bar(img, level, offset):
|
||||
|
||||
while (True):
|
||||
if (raw_buf != None):
|
||||
pcm_buf = pcm_buf = np.array(array.array('h', raw_buf))
|
||||
pcm_buf = np.frombuffer(raw_buf, dtype=np.int16)
|
||||
raw_buf = None
|
||||
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)
|
||||
|
||||
if CHANNELS == 1:
|
||||
fft_buf = sp.signal.spectrogram(pcm_buf)
|
||||
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
|
||||
else:
|
||||
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)
|
||||
|
||||
fb.clear()
|
||||
draw_fft(fb, fft_buf)
|
||||
draw_audio_bar(fb, l_lvl, 0)
|
||||
draw_audio_bar(fb, r_lvl, 25)
|
||||
if CHANNELS == 2:
|
||||
draw_audio_bar(fb, r_lvl, 25)
|
||||
fb.flush()
|
||||
|
||||
# Stop streaming
|
||||
|
||||
@ -62,6 +62,7 @@ OMV_BOARD_CONFIG_DIR=$(TOP_DIR)/$(OMV_DIR)/boards/$(TARGET)/
|
||||
MP_BOARD_CONFIG_DIR=$(TOP_DIR)/$(MICROPY_DIR)/ports/$(PORT)/boards/$(TARGET)/
|
||||
MPY_LIB_DIR=$(TOP_DIR)/../scripts/libraries
|
||||
FROZEN_MANIFEST=$(OMV_BOARD_CONFIG_DIR)/manifest.py
|
||||
OMV_COMMON_DIR=$(TOP_DIR)/$(OMV_DIR)/common
|
||||
|
||||
# Debugging/Optimization
|
||||
ifeq ($(DEBUG), 1)
|
||||
@ -117,6 +118,7 @@ endif
|
||||
|
||||
ifeq ($(MICROPY_PY_ULAB), 1)
|
||||
MPY_CFLAGS += -DMICROPY_PY_ULAB=1
|
||||
MPY_CFLAGS += -DULAB_CONFIG_FILE="\"$(OMV_COMMON_DIR)/ulab_config.h\""
|
||||
MICROPY_ARGS += MICROPY_PY_ULAB=1
|
||||
endif
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit a12263ba27bc9b63beb83d91bf55331af5f18ab1
|
||||
Subproject commit 696b1d15e2c18e8d2004576c10a4c26803b264c0
|
||||
12
src/omv/common/ulab_config.h
Normal file
12
src/omv/common/ulab_config.h
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013-2016 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* Ulab config file.
|
||||
*
|
||||
*/
|
||||
#ifndef __ULAB_CONFIG_H__
|
||||
#define __ULAB_CONFIG_H__
|
||||
// Override ulab defaults here.
|
||||
#endif //__ULAB_CONFIG_H__
|
||||
@ -296,18 +296,27 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/modules/,\
|
||||
|
||||
ifeq ($(MICROPY_PY_ULAB), 1)
|
||||
FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/extmod/ulab/,\
|
||||
code/fft.o \
|
||||
code/linalg.o \
|
||||
code/ndarray.o \
|
||||
code/numerical.o \
|
||||
code/poly.o \
|
||||
code/ulab.o \
|
||||
code/vectorise.o \
|
||||
code/create.o \
|
||||
code/approx.o \
|
||||
code/filter.o \
|
||||
code/compare.o \
|
||||
code/extras.o \
|
||||
code/scipy/optimize/optimize.o \
|
||||
code/scipy/signal/signal.o \
|
||||
code/scipy/special/special.o \
|
||||
code/ndarray_operators.o \
|
||||
code/ulab_tools.o \
|
||||
code/ndarray.o \
|
||||
code/numpy/approx/approx.o \
|
||||
code/numpy/compare/compare.o \
|
||||
code/ulab_create.o \
|
||||
code/numpy/fft/fft.o \
|
||||
code/numpy/fft/fft_tools.o \
|
||||
code/numpy/filter/filter.o \
|
||||
code/numpy/linalg/linalg.o \
|
||||
code/numpy/linalg/linalg_tools.o \
|
||||
code/numpy/numerical/numerical.o \
|
||||
code/numpy/poly/poly.o \
|
||||
code/numpy/vector/vector.o \
|
||||
code/user/user.o \
|
||||
code/numpy/numpy.o \
|
||||
code/scipy/scipy.o \
|
||||
code/ulab.o \
|
||||
)
|
||||
endif
|
||||
|
||||
|
||||
@ -376,18 +376,27 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/drivers/,\
|
||||
|
||||
ifeq ($(MICROPY_PY_ULAB), 1)
|
||||
FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/extmod/ulab/,\
|
||||
code/fft.o \
|
||||
code/linalg.o \
|
||||
code/ndarray.o \
|
||||
code/numerical.o \
|
||||
code/poly.o \
|
||||
code/ulab.o \
|
||||
code/vectorise.o \
|
||||
code/create.o \
|
||||
code/approx.o \
|
||||
code/filter.o \
|
||||
code/compare.o \
|
||||
code/extras.o \
|
||||
code/scipy/optimize/optimize.o \
|
||||
code/scipy/signal/signal.o \
|
||||
code/scipy/special/special.o \
|
||||
code/ndarray_operators.o \
|
||||
code/ulab_tools.o \
|
||||
code/ndarray.o \
|
||||
code/numpy/approx/approx.o \
|
||||
code/numpy/compare/compare.o \
|
||||
code/ulab_create.o \
|
||||
code/numpy/fft/fft.o \
|
||||
code/numpy/fft/fft_tools.o \
|
||||
code/numpy/filter/filter.o \
|
||||
code/numpy/linalg/linalg.o \
|
||||
code/numpy/linalg/linalg_tools.o \
|
||||
code/numpy/numerical/numerical.o \
|
||||
code/numpy/poly/poly.o \
|
||||
code/numpy/vector/vector.o \
|
||||
code/user/user.o \
|
||||
code/numpy/numpy.o \
|
||||
code/scipy/scipy.o \
|
||||
code/ulab.o \
|
||||
)
|
||||
endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user