diff --git a/CMakeLists.txt b/CMakeLists.txt index 64d0033..3c68231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory(external/magic_enum) add_subdirectory(external/argparse) add_subdirectory(external/log4cxx) + file(GLOB_RECURSE sources src/*.cpp src/*.h) file(GLOB_RECURSE data resources/*) diff --git a/scripts/raw-to-wav.sh b/scripts/raw-to-wav.sh new file mode 100755 index 0000000..e66d024 --- /dev/null +++ b/scripts/raw-to-wav.sh @@ -0,0 +1,8 @@ +#! /bin/sh + +set -eux + +input_file="$1" +output_file="$2" + +sox -r 44100 -e signed-integer -b 16 -c 1 ${input_file} ${output_file} \ No newline at end of file diff --git a/scripts/samples.py b/scripts/samples.py index aa6b1b5..3307245 100755 --- a/scripts/samples.py +++ b/scripts/samples.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 -from tones import SQUARE_WAVE +from tones import SQUARE_WAVE, SINE_WAVE from tones.mixer import Mixer import csv import math @@ -14,7 +14,8 @@ def frequency_to_midi(frequency): f = 440 * 2 ^ (n - 69)/12 ''' note = 12 * (math.log(frequency/220)/math.log(2)) + 57 - return round(note) + #return round(note) + return note tones = {} with open('tones.csv', newline='') as csvfile: @@ -26,6 +27,27 @@ for tone in tones: print(f"{tone} is MIDI #{frequency_to_midi(tones[tone])}") mixer = Mixer(44100, 1) - mixer.create_track(0, SQUARE_WAVE) + mixer.create_track(0, SINE_WAVE) mixer.add_tone(0, frequency=tones[tone], duration=1.0) - mixer.write_wav(f'samples/{tone}.wav') \ No newline at end of file + mixer.write_wav(f'samples/{tone}.wav') + + +mixer = Mixer(44100, 1) +mixer.create_track(0, SQUARE_WAVE) +mixer.add_tone(0, frequency=440, duration=1.0) +mixer.write_wav(f'samples/MIDI-69-square.wav') + +mixer = Mixer(44100, 1) +mixer.create_track(0, SINE_WAVE) +mixer.add_tone(0, frequency=440, duration=1.0) +mixer.write_wav(f'samples/MIDI-69-sine.wav') + +mixer = Mixer(44100, 1) +mixer.create_track(0, SQUARE_WAVE) +mixer.add_tone(0, frequency=261.6256, duration=1.0) +mixer.write_wav(f'samples/MIDI-60-square.wav') + +mixer = Mixer(44100, 1) +mixer.create_track(0, SINE_WAVE) +mixer.add_tone(0, frequency=261.6256, duration=1.0) +mixer.write_wav(f'samples/MIDI-60-sine.wav') \ No newline at end of file diff --git a/scripts/selcal-detect.py b/scripts/selcal-detect.py index 8041239..cc080c9 100755 --- a/scripts/selcal-detect.py +++ b/scripts/selcal-detect.py @@ -14,6 +14,14 @@ with open('tones.csv', newline='') as csvfile: for row in reader: tones[row['designator']] = float(row['frequency']) +''' +def freq_of_key(midi_key): + return 440.0 * (2 ** ((midi_key - 69)/12)) + +tones = {} +for c in range(65, 90): + tones[c] = freq_of_key(c) +''' # Shamelessly lifted from # https://scipy.github.io/old-wiki/pages/Cookbook/ButterworthBandpass @@ -98,6 +106,14 @@ if __name__ == '__main__': line = plot.plot(correlation, pen=pg.mkPen(color=color), fillLevel=0.1, name=tone) legend.addItem(line, tone) + y_max = max(line.getData()[1]) # Maximum y-value + x_max = line.getData()[0][np.argmax(line.getData()[1])] # Corresponding x-coordinate + + label = pg.TextItem(html=f'