1 Star 0 Fork 0

schou0419/graphic-eq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gui.py 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
Aydin O'Leary 提交于 2020-12-18 03:05 . Semi-functional live filter! :)
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import filters as f
import numpy as np
import struct
CHUNK = 1024 * 1
RATE = 44100
FFT_X = np.linspace(0,RATE,CHUNK)
DEFAULT_BANDS = 8
PLOTTING = True
class App:
def __init__(self, master):
self.master = master
self.n = DEFAULT_BANDS
self.gain = [0] * self.n
self.gen_bands()
def gen_bands(self):
self.band = []
for i in range(self.n):
self.band.append(tk.Scale(orient='vertical', from_=10, to=-10, resolution=.01, command=self.update_spectrum, width=15))
self.band[i].pack(fill=tk.Y, side=tk.LEFT, expand=True, padx=5, pady=5)
self.A = f.filtarray(n=self.n, preset='default') # todo: implement n-band
# Create a container
frame = tk.Frame(self.master)
# # Create 2 buttons
# self.button_left = tk.Button(frame,text="< Decrease Slope",
# command=self.decrease)
# self.button_left.pack(side="left")
# self.button_right = tk.Button(frame,text="Increase Slope >",
# command=self.increase)
# self.button_right.pack(side="left")
fig = Figure()
ax = fig.add_subplot(111)
self.line, = ax.semilogx(FFT_X, [1] * len(FFT_X))
ax.set_ylim([0,2])
# ax.xscale('log')
ax.grid()
self.canvas = FigureCanvasTkAgg(fig,master=self.master)
self.canvas.draw()
self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
frame.pack()
def update_spectrum(self, val):
for i in range(self.n):
self.gain[i] = self.band[i].get()
self.A.filters[i].g = self.gain[i]
self.T = self.A.build()
if PLOTTING:
self.line.set_ydata(self.T)
self.canvas.draw()
# print(self.T)
return
def get_spectrum(self):
return self.T
def decrease(self):
self.n -= 1
self.gen_bands()
def increase(self):
self.n += 1
self.gen_bands()
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
root.mainloop()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/schou0419/graphic-eq.git
git@gitee.com:schou0419/graphic-eq.git
schou0419
graphic-eq
graphic-eq
main

搜索帮助