This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
points = 256 | |
y = np.zeros(points, dtype="complex64") | |
y[20] = np.complex(1,0) | |
ifft_y = fft.irfft(y) * points | |
plt.figure(figsize=(10, 3)) | |
plt.plot(ifft_y) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
points = 256 | |
y = np.zeros(points, dtype="complex64") | |
y[20] = np.complex(1,0) # stick a 1 into the 20th position | |
plt.figure(figsize=(10, 3)) | |
plt.bar(np.arange(100), np.absolute(y)[:100]) # Show the first 100 points | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate an integer-period sine wave to | |
# eliminate spectral leak. | |
hz = 20 | |
x = np.linspace(0, 2 * np.pi * hz, 128 * hz) | |
y = np.sin(x) | |
plt.figure(figsize=(10, 3)) | |
plt.plot(x, y) | |
plt.show() | |
# We're only interested in the real components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# Generate Sine wave | |
hz = 20 | |
x = np.arange(0, 1, 0.001) # 1 second | |
y = np.sin(2 * np.pi * hz * x) | |
plt.figure(figsize=(10, 3)) | |
plt.plot(x, y) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files = os.listdir("samples") | |
np.random.shuffle(files) | |
notes = ['A', 'As', 'B', 'C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs'] | |
note_map = {} | |
for i, note_name in enumerate(notes): | |
note_map[note_name] = i | |
count_by_key = np.zeros((8 * 12)) | |
errors_by_key = np.zeros((8 * 12)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.model.fit(training_xs, training_ys, epochs=150, batch_size=32, | |
callbacks=[tf.keras.callbacks.EarlyStopping(monitor='val_mse', patience=25)], | |
validation_data=(testing_xs, testing_ys)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for octave in range(2, 8): | |
random.shuffle(GM_PATCHES) | |
for patch in range(0, 15): | |
program = GM_PATCHES[patch] | |
for key in Note.names: | |
sample = Sample("samples/note-%s%s-P%s" % (key, octave, program), | |
program=program, key=key, octave=octave) | |
sample.make_wav() | |
for pitch_shift_hz in np.concatenate((np.array([0]), np.random.randint(10, 80, 5))): | |
sample.transform_wav( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.model = tf.keras.models.Sequential([ | |
# Add features/channels dim for Conv2D layer | |
layers.Reshape((self.s_rows, self.s_cols, 1), input_shape=(self.s_rows, self.s_cols)), | |
tf.keras.layers.Dropout(0.2), | |
tf.keras.layers.Conv2D(64, (3,3), activation='relu'), | |
tf.keras.layers.MaxPooling2D(pool_size=(2,2)), | |
tf.keras.layers.Conv2D(128, (3,3), activation='relu'), | |
tf.keras.layers.MaxPooling2D(pool_size=(2,2)), | |
tf.keras.layers.Conv2D(128, (3,3), activation='relu'), | |
tf.keras.layers.MaxPooling2D(pool_size=(2,2)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DefaultConfig = Config( | |
rows=513, | |
cols = 90, | |
s_nperseg = 256, | |
s_nfft = 1024, | |
s_noverlap = 200, | |
resample = 16000) | |
def spectrogram(file, config=DefaultConfig): | |
fs, data = wavfile.read(file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Note: | |
values = { | |
"c": 0, | |
"d": 2, | |
"e": 4, | |
"f": 5, | |
"g": 7, | |
"a": 9, | |
"b": 11 | |
} |