代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。