def test_tonic_identification(): pitch = numpy.array(json.load(open(os.path.join( "sample_data", "cab08727-d5c2-4fda-9d96-d107915a85ec.json"), 'r'))['pitch']) tonic_identifier = TonicLastNote() tonic, pitch, pitch_chunks, pitch_distribution, stable_pitches = \ tonic_identifier.identify(pitch) saved_tonic = json.load(open(os.path.join( 'sample_data', 'cab08727-d5c2-4fda-9d96-d107915a85ec_tonic.json'), 'r')) assert (numpy.isclose(tonic['value'], saved_tonic['value']))
def _stable_pitches_to_notes(self, stable_pitches_hz, theoretical_intervals, tonic_hz): stable_pitches_cent = Converter.hz_to_cent(stable_pitches_hz, tonic_hz) # Finding nearest theoretical values of each stable pitch, identify the # name of this value and write to output stable_notes = {} # Defining output (return) object for stable_pitch_cent, stable_pitch_hz in zip(stable_pitches_cent, stable_pitches_hz): note_cent = TonicLastNote.find_nearest( theoretical_intervals.values(), stable_pitch_cent) if abs(stable_pitch_cent - note_cent) < self.pitch_threshold: for key, val in theoretical_intervals.iteritems(): if val == note_cent: theoretical_pitch = Converter.cent_to_hz( note_cent, tonic_hz) stable_notes[key] = { "performed_interval": {"value": stable_pitch_cent, "unit": "cent"}, "theoretical_interval": {"value": note_cent, "unit": "cent"}, "theoretical_pitch": {"value": theoretical_pitch, "unit": "cent"}, "stable_pitch": {"value": stable_pitch_hz, "unit": "Hz"}} break return stable_notes