Beispiel #1
0
 def get_appended(self, wave_state):
     wave_state = wave_state.to_same_format(self)
     WaveUtils.get_sum_channels(
         self.channels,
         WaveUtils.get_appended(self.channels, wave_state.channels))
     return self.get_with_changed_channels(
         WaveUtils.get_appended(self.channels, wave_state.channels))
 def check_change_channel_resolution(self, channel,
                                     expected_changed_channel, data_type):
     coefficient = len(expected_changed_channel) / len(channel)
     self.assert_numpy_array_equal(
         WaveUtils.change_channel_resolution(channel, coefficient,
                                             data_type),
         expected_changed_channel)
Beispiel #3
0
 def get_with_changed_sample_width(self, new_sample_width):
     if new_sample_width not in WaveUtils.TYPES:
         raise Exception("Incorrect sample width")
     return WaveState(
         new_sample_width, self.frame_rate,
         WaveUtils.change_channels_sample_width(
             self.channels, new_sample_width / self.sample_width))
Beispiel #4
0
 def read_from_file(file_name):
     with wave.open(file_name, "rb") as wave_read:
         sample_width = wave_read.getsampwidth()
         frame_rate = wave_read.getframerate()
         channels = WaveUtils.frames_to_channels(
             wave_read.readframes(wave_read.getnframes()), sample_width,
             wave_read.getnchannels())
         return WaveState(sample_width, frame_rate, channels)
Beispiel #5
0
 def save_to_file(self, file_name):
     with wave.open(file_name, "wb") as wave_write:
         wave_write.setparams(
             (self.channels_number, self.sample_width, self.frame_rate,
              self.frames_number, 'NONE', 'not compressed'))
         frames = WaveUtils.channels_to_frames(self.channels,
                                               self.sample_width)
         wave_write.writeframes(frames)
Beispiel #6
0
 def get_with_changed_channels_number(self, new_channels_number):
     average_channel = WaveUtils.get_average_channel(self.channels)
     if new_channels_number > self.channels_number:
         new_channels = [
             self.channels[i]
             if i < self.channels_number else average_channel
             for i in range(new_channels_number)
         ]
     else:
         new_channels = [
             average_channel for i in range(new_channels_number)
         ]
     return self.get_with_changed_channels(new_channels)
 def check_get_appended(self, channels1, channels2, expected):
     self.assert_numpy_array_equal(
         WaveUtils.get_appended(self.channelsToNumpy(channels1),
                                self.channelsToNumpy(channels2)), expected)
 def check_change_channel_sample_width(self, channel, expected_changed,
                                       multiplier):
     self.assert_numpy_array_equal(
         WaveUtils.change_channels_sample_width(
             [self.to_numpy_array(channel)], multiplier),
         [expected_changed])
 def check_get_average_channel(self, channels, expected_average_channel):
     self.assert_numpy_array_equal(
         WaveUtils.get_average_channel(self.channelsToNumpy(channels)),
         expected_average_channel)
Beispiel #10
0
 def check_channels_to_samples(self, channels, expected_samples):
     self.assert_numpy_array_equal(WaveUtils.channels_to_samples(channels),
                                   self.to_numpy_array(expected_samples))
Beispiel #11
0
 def check_samples_to_channels(self, samples, expected_channels):
     self.assert_numpy_array_equal(
         WaveUtils.samples_to_channels(samples, len(expected_channels)),
         expected_channels)
Beispiel #12
0
 def check_samples_to_frames(self, samples, sample_width, expected_frames):
     self.assertSequenceEqual(
         WaveUtils.samples_to_frames(self.to_numpy_array(samples),
                                     sample_width), expected_frames)
Beispiel #13
0
 def check_frames_to_samples(self, frames, sample_width, expected_samples):
     self.assert_numpy_array_equal(
         WaveUtils.frames_to_samples(bytes(frames), sample_width),
         expected_samples)
Beispiel #14
0
 def check_get_reversed(self, channels, expected_reversed):
     self.assert_numpy_array_equal(
         WaveUtils.get_reversed(self.channelsToNumpy(channels)),
         expected_reversed)
Beispiel #15
0
 def get_with_changed_frame_rate(self, new_frame_rate):
     coefficient = new_frame_rate / self.frame_rate
     new_channels = WaveUtils.change_channels_resolution(
         self.channels, coefficient, self.SAMPLE_TYPE)
     return self.get_with_changed_channels(new_channels)