コード例 #1
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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))
コード例 #2
0
 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)
コード例 #3
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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))
コード例 #4
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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)
コード例 #5
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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)
コード例 #6
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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)
コード例 #7
0
 def check_get_appended(self, channels1, channels2, expected):
     self.assert_numpy_array_equal(
         WaveUtils.get_appended(self.channelsToNumpy(channels1),
                                self.channelsToNumpy(channels2)), expected)
コード例 #8
0
 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])
コード例 #9
0
 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)
コード例 #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))
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #14
0
 def check_get_reversed(self, channels, expected_reversed):
     self.assert_numpy_array_equal(
         WaveUtils.get_reversed(self.channelsToNumpy(channels)),
         expected_reversed)
コード例 #15
0
ファイル: WaveState.py プロジェクト: Van10000/sound_editor
 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)