def test_speed_down(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") first_sample_rate = test_file.sampleRate rate = 1.5 test_file.speed_down(rate) second_sample_rate = int(first_sample_rate // rate) self.assertEqual(second_sample_rate, test_file.sampleRate)
def start(self): mainloop = True app = wx.App(False) open_file_dialog = wx.FileDialog(None, "Wave files", ".", ".", "Wave files (*.wav)|*.wav") if open_file_dialog.ShowModal() == wx.ID_CANCEL: print("No selected file") sys.exit(0) path = open_file_dialog.GetPath() open_file_dialog.Destroy() self.file = wav.Wave(path) print("Selected file: {0}".format(path)) while mainloop: command = input("Enter command: ") if command == "exit": mainloop = False if command == "save": dlg = wx.FileDialog(None, message="Save file as", defaultDir=".", defaultFile="", wildcard="*.*", style=wx.FD_SAVE) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if path[-4:] != ".wav": path += ".wav" wav.save_changes_in_file(path, self.file) mainloop = False else: self.execute_command(command)
def test_concatenation(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") fragment1 = fragment.Fragment(test_file.get_fragment(0, 550000)) fragment2 = fragment.Fragment(test_file.get_fragment(1000000, 1250000)) temp = fragment.concatenate_fragments((fragment1, fragment2)) concat = fragment.Fragment(temp) self.assertEqual(len(concat.channels), 2) self.assertEqual(len(concat.channels[0]), 800000) self.assertEqual(len(concat.channels[1]), 800000)
def test_reverse_fragment(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") fragment1 = fragment.Fragment(test_file.get_fragment(0, 600000)) self.assertEqual(len(fragment1.channels[0]), 600000) test_value = fragment1.channels[0][12345] fragment1.reverse() self.assertEqual( fragment1.channels[0][len(fragment1.channels[0]) - 12346], test_value)
def test_change_volume(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") test_value = test_file.channels[0][55555] test_value = int(test_value * 0.7) test_file.change_volume(0.7) self.assertEqual(test_file.channels[0][55555], test_value) test_value = int(test_value * 1.5) test_file.change_volume(1.5) self.assertEqual(test_file.channels[0][55555], test_value)
def test_reverse(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") test_value = (test_file.channels[0][12345], test_file.channels[1][12345]) test_file.reverse() test_reversed_value = \ (test_file.channels[0][len(test_file.channels[0]) - 12345 - 1], test_file.channels[1][len(test_file.channels[1]) - 12345 - 1]) self.assertEqual(test_value[0], test_reversed_value[0]) self.assertEqual(test_value[1], test_reversed_value[1])
def on_open(self, e): open_file_dialog = wx.FileDialog(None, "Wave files", ".", "", "Wave files (*.wav)|*.wav") if open_file_dialog.ShowModal() == wx.ID_OK: path = open_file_dialog.GetPath() open_file_dialog.Destroy() self.file = wav.Wave(path) self.draw_track() if self.file.audioFormat != 1: self.show_notification( "File is encrypted! Some functions may not work", "Warning!")
def test_union_with_different_length(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") fragment1 = fragment.Fragment(test_file.get_fragment(0, 600000)) fragment2 = fragment.Fragment(test_file.get_fragment(550000, 900000)) union = fragment.collect_fragments_to_one((fragment1, fragment2), test_file.channels[0].dtype) union_fragment = fragment.Fragment(union) self.assertEqual(len(union_fragment.channels), 2) self.assertEqual(len(union_fragment.channels[0]), 600000) test_value = fragment1.channels[0][12345] + fragment2.channels[0][ 12345] self.assertEqual(union_fragment.channels[0][12345], test_value)
def test_fade_in_and_out(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") array = np.linspace(0, 1, test_file.sampleRate * 3) test_value = test_file.channels[0][12345] test_file.fade_in(3) self.assertEqual(test_file.channels[0][12345], int(test_value * array[12345])) test_value2 = test_file.channels[0][len(test_file.channels[0]) - 12346] test_file.fade_out(3) self.assertEqual( test_file.channels[0][len(test_file.channels[0]) - 12346], int(test_value2 * array[12345]))
def test_create_wave(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") self.assertEqual(test_file.chunkId, "RIFF") self.assertEqual(test_file.chunkSize, 44251779) self.assertEqual(test_file.format, "WAVE") self.assertEqual(test_file.subchunk1Id, "fmt ") self.assertEqual(test_file.subchunk1Size, 16) self.assertEqual(test_file.audioFormat, 1) self.assertEqual(test_file.numChannels, 2) self.assertEqual(test_file.sampleRate, 44100) self.assertEqual(test_file.byteRate, 176400) self.assertEqual(test_file.blockAlign, 4) self.assertEqual(test_file.bitsPerSample, 16) self.assertEqual(test_file.subchunk2Id, "data") self.assertEqual(test_file.subchunk2Size, 44126396)
def test_get_fragment(self): test_file = wave_file.Wave("../Files/01 Bloody Nose.wav") fr = fragment.Fragment(test_file.get_fragment(150000, 1500000)) for channel in fr.channels: self.assertEqual(len(channel), 1350000)