Showing the changes to python/tests (1 of 1 file). Show all
Unified · Split
| @@ -38,5 +38,44 @@ class aubio_notes_params(TestCase): · 37 unmodified lines | ||
| 38 | 38 | self.o.set_silence(val) |
| 39 | 39 | assert_equal (self.o.get_silence(), val) |
| 40 | 40 | |
| 41 | +from utils import list_all_sounds | |
| 42 | +list_of_sounds = list_all_sounds('sounds') | |
| 43 | + | |
| 44 | +class aubio_notes_sinewave(TestCase): | |
| 45 | + | |
| 46 | + def analyze_file(self, filepath, samplerate=0): | |
| 47 | + from aubio import source | |
| 48 | + import numpy as np | |
| 49 | + win_s = 512 # fft size | |
| 50 | + hop_s = 256 # hop size | |
| 51 | + | |
| 52 | + s = source(filepath, samplerate, hop_s) | |
| 53 | + samplerate = s.samplerate | |
| 54 | + | |
| 55 | + tolerance = 0.8 | |
| 56 | + | |
| 57 | + notes_o = notes("default", win_s, hop_s, samplerate) | |
| 58 | + total_frames = 0 | |
| 59 | + | |
| 60 | + results = [] | |
| 61 | + while True: | |
| 62 | + samples, read = s() | |
| 63 | + new_note = notes_o(samples) | |
| 64 | + if (new_note[0] != 0): | |
| 65 | + note_str = ' '.join(["%.2f" % i for i in new_note]) | |
| 66 | + results.append( [total_frames, np.copy(new_note)] ) | |
| 67 | + total_frames += read | |
| 68 | + if read < hop_s: break | |
| 69 | + return results | |
| 70 | + | |
| 71 | + def test_sinewave(self): | |
| 72 | + for filepath in list_of_sounds: | |
| 73 | + if '44100Hz_44100f_sine441.wav' in filepath: | |
| 74 | + results = self.analyze_file(filepath) | |
| 75 | + assert_equal (len(results), 1) | |
| 76 | + assert_equal (len(results[0]), 2) | |
| 77 | + assert_equal (results[0][0], 1280) | |
| 78 | + assert_equal (results[0][1], [69, 123, -1]) | |
| 79 | + | |
| 41 | 80 | if __name__ == '__main__': |
| 42 | 81 | main() |