Compare commits

..

No commits in common. "809d3ce9fe116092e144e2a09f9ffc0d18c838f2" and "e4b0645ac6ecb19bb91dfce9f77873a752d67dff" have entirely different histories.

5 changed files with 22 additions and 21 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
build/ build/
.*/

View File

@ -5,11 +5,29 @@ from scipy.io import wavfile
from scipy.fft import fft from scipy.fft import fft
from filters import anti_alias from filters import anti_alias
from tones import TONES from tones import TONES
from utilities import *
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import sys import sys
file_name = sys.argv[1] file_name = sys.argv[1]
def decibels(f):
return 10 * np.log10(f)
def find_top_two_keys(d, threshold):
sorted_items = sorted(d.items(), key=lambda item: item[1], reverse=True)
if len(sorted_items) < 3:
return None
top_two = sorted_items[:2]
third_value = sorted_items[2][1]
if top_two[0][1] - third_value < threshold or top_two[1][1] - third_value < threshold:
return None
return top_two[0][0], top_two[1][0]
# Step 1: Read the WAV file
sample_rate, data = wavfile.read(file_name) sample_rate, data = wavfile.read(file_name)
# Handle stereo audio by converting to mono if needed # Handle stereo audio by converting to mono if needed
@ -74,7 +92,7 @@ for i in range(num_segments):
# Only import if we're actually plotting, these imports are pretty heavy. # Only import if we're actually plotting, these imports are pretty heavy.
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets, QtCore from pyqtgraph.Qt import QtGui, QtWidgets, QtCore, mkQApp
app = pg.mkQApp("ImageView Example") app = pg.mkQApp("ImageView Example")
window = QtWidgets.QMainWindow() window = QtWidgets.QMainWindow()
@ -90,7 +108,8 @@ fft_view.setImage(fft_results)
fft_view.setRect(QtCore.QRectF(0, 0, len(data) // sample_rate, max_freq)) fft_view.setRect(QtCore.QRectF(0, 0, len(data) // sample_rate, max_freq))
plot.addItem(fft_view) plot.addItem(fft_view)
colormap = pg.colormap.get("inferno") # Note JMT: Requires matplotlib installed to use this colormap
colormap = pg.colormap.get("CMRmap", source='matplotlib')
colorbar = pg.ColorBarItem( values=(0,1), colorMap=colormap) colorbar = pg.ColorBarItem( values=(0,1), colorMap=colormap)
colorbar.setImageItem(fft_view, insert_in=plot) colorbar.setImageItem(fft_view, insert_in=plot)

View File

@ -1,17 +0,0 @@
import numpy as np
def decibels(f):
return 10 * np.log10(f)
def find_top_two_keys(d, threshold):
sorted_items = sorted(d.items(), key=lambda item: item[1], reverse=True)
if len(sorted_items) < 3:
return None
top_two = sorted_items[:2]
third_value = sorted_items[2][1]
if top_two[0][1] - third_value < threshold or top_two[1][1] - third_value < threshold:
return None
return top_two[0][0], top_two[1][0]

BIN
soundfonts/sine.sf2 Normal file

Binary file not shown.

Binary file not shown.