Commit 6c44759a authored by Ed Rogers's avatar Ed Rogers
Browse files

Add 'graphic equaliser'

parent 37b2859b
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<orderEntry type="jdk" jdkName="Python 3.5 (pyGUI)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.6 (pyGUI)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyCompatibilityInspection" enabled="false" level="WARNING" enabled_by_default="false">
<option name="ourVersions">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="3.6" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5 (pyGUI)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (pyGUI)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -21,7 +21,6 @@ Display agregated scores in second window
import sounddevice as sd
import numpy as np
import matplotlib.pyplot as plt
import soundfile as sf
import time
from PyQt5 import QtCore, QtWidgets, QtGui
......@@ -31,6 +30,63 @@ from PyQt5.QtCore import QSize
import sys
from SoundLibrary import SoundLibrary
import random
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class HearingResult:
upper_lim = 100
lower_lim = 0
n_blocks = 20
@staticmethod
def get_block_size():
return (HearingResult.upper_lim - HearingResult.lower_lim)/HearingResult.n_blocks
def __init__(self, bands):
self.bands = bands
self.lower_bounds = np.ones_like(bands) * self.lower_lim
self.upper_bounds = np.ones_like(bands) * self.upper_lim
class HearingMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# self.compute_initial_figure()
FigureCanvas.__init__(self, fig)
self.setParent(parent)
fig.set_facecolor('k')
FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.plot_result(HearingResult(parent.library.freqs))
def plot_result(self, result: HearingResult):
inds = np.arange(0, result.bands.size)
baseline = -10
self.axes.set_axis_bgcolor('k')
self.axes.bar(inds, result.upper_bounds-baseline, color=(0, 0.5, 0), bottom=baseline)
self.axes.bar(inds, result.lower_bounds-baseline, color=(0, 1, 0), bottom=baseline)
xlim = self.axes.get_xlim()
for i in np.arange(result.lower_lim+baseline, result.upper_lim, result.get_block_size()):
self.axes.plot(self.axes.get_xlim(), np.ones(2)*i, color='k')
labels = [str(b) for b in result.bands]
labels.insert(0, '')
self.axes.set_xticklabels(labels)
print(result.bands)
print(labels)
print(result.lower_bounds)
self.axes.set_ylim(-10, 110)
self.axes.set_xlim(xlim)
class HearingTestThread(QtCore.QThread):
......@@ -76,8 +132,11 @@ class TestWindow(QMainWindow):
self.log.setReadOnly(True)
self.log.setFocusPolicy(QtCore.Qt.NoFocus)
self.graph = HearingMplCanvas(parent=self)
grid_layout.addWidget(self.title, 0, 0)
grid_layout.addWidget(self.log, 1, 0)
grid_layout.addWidget(self.graph, 2, 0)
def keyPressEvent(self, event: QtGui.QKeyEvent):
if not self.test_running:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment