def test_Sync(self):
        self._sample_1.extract_channel(0)
        self._sample_2.extract_channel(0)

        channel = self._sample_1.get_channel(0)

        formatter = ChannelFormatter(self._sample_2.get_channel(0))
        formatter.sync(channel)

        self.assertEqual(channel.get_framerate(), formatter.channel.get_framerate())
        self.assertEqual(channel.get_sampwidth(), formatter.channel.get_sampwidth())
Esempio n. 2
0
def format_channel(channel, framerate, sampwith):
    """
    Return a channel with the requested framerate and sampwidth.

    """
    fm = channel.get_framerate()
    sp = channel.get_sampwidth()
    if fm != framerate or sp != sampwith:
        formatter = ChannelFormatter( channel )
        formatter.set_framerate( framerate )
        formatter.set_sampwidth( sampwith )
        formatter.convert()
        return formatter.get_channel()

    return channel
Esempio n. 3
0
    print "Wrong bitrate value"
    sys.exit(1)

# ----------------------------------------------------------------------------

print (time.strftime("%H:%M:%S"))
audio = audiodata.io.open(args.w)

# Get the expected channel
idx = audio.extract_channel(args.c-1)
# no more need of input data, can close
audio.close()
print (time.strftime("%H:%M:%S"))

# Do the job (do not modify the initial channel).
formatter = ChannelFormatter( audio.get_channel(idx) )
if args.r:
    formatter.set_framerate(args.r)
if args.b:
    formatter.set_sampwidth(args.b)
formatter.convert()
print (time.strftime("%H:%M:%S"))

# Save the converted channel
audio_out = AudioPCM()
audio_out.append_channel( formatter.channel )
audiodata.save( args.o, audio_out )
print (time.strftime("%H:%M:%S"))

# ----------------------------------------------------------------------------
Esempio n. 4
0
    def test_Mix(self):
        self._sample_1.extract_channel(0)
        self._sample_2.extract_channel(0)

        formatter1 = ChannelFormatter(self._sample_1.get_channel(0))
        formatter1.set_framerate(16000)
        formatter1.set_sampwidth(2)
        formatter1.convert()

        formatter2 = ChannelFormatter(self._sample_2.get_channel(0))
        formatter2.set_framerate(16000)
        formatter2.set_sampwidth(2)
        formatter2.convert()

        mixer = ChannelsMixer()
        mixer.append_channel(formatter1.get_channel())
        mixer.append_channel(formatter2.get_channel())
        mixer.norm_length()

        self.assertEqual(mixer.get_channel(0).get_nframes(), mixer.get_channel(1).get_nframes())

        newchannel = mixer.mix()

        self.assertEqual(newchannel.get_nframes(), mixer.get_channel(0).get_nframes())
        self.assertEqual(newchannel.get_nframes(), mixer.get_channel(1).get_nframes())
Esempio n. 5
0
# ----------------------------------------------------------------------------

if len(sys.argv) <= 1:
    sys.argv.append('-h')

args = parser.parse_args()

# ----------------------------------------------------------------------------

audio = audiodata.open(args.w)

# Get the expected channel
idx = audio.extract_channel(args.c-1)

# Do the job (do not modify the initial channel).
formatter = ChannelFormatter( audio.get_channel(idx) )

if args.r:
    formatter.set_framerate(args.r)
else:
    formatter.set_framerate(audio.get_framerate())


if args.b:
    if not args.b in [1,2,4]:
        print "Wrong bitrate value"
        sys.exit(1)
    formatter.set_sampwidth(args.b)
else:
    formatter.set_sampwidth(audio.get_sampwidth())
Esempio n. 6
0
    def ApplyChanges(self, from_time=None, to_time=None):
        """
        Return a channel with changed applied.

        @param from_time (float)
        @param to_time (float)
        @return (Channel) new channel or None if nothing changed

        """
        # Get the list of modifiable values from wx objects
        fm     = int(self._wxobj["framerate"][1].GetValue())
        sp     = int(int(self._wxobj["sampwidth"][1].GetValue())/8)
        mul    = float(self._wxobj["mul"][1].GetValue())
        bias   = int(self._wxobj["bias"][1].GetValue())
        offset = self._wxobj["offset"][1].GetValue()

        dirty = False
        if from_time is None:
            from_frame = 0
        else:
            from_frame = int( from_time * fm )
            dirty = True
        if to_time is None:
            to_frame = self._channel.get_nframes()
        else:
            dirty = True
            to_frame = int(to_time * fm)

        channel = self._channel.extract_fragment(from_frame,to_frame)

        # If something changed, apply this/these change-s to the channel
        if fm != self._channel.get_framerate() or sp != self._channel.get_sampwidth() or mul != 1. or bias != 0 or offset is True:
            wx.BeginBusyCursor()
            b = wx.BusyInfo("Please wait while formatting data...")
            channelfmt = ChannelFormatter( channel )
            channelfmt.set_framerate(fm)
            channelfmt.set_sampwidth(sp)
            channelfmt.convert()
            channelfmt.mul(mul)
            channelfmt.bias(bias)
            if offset is True:
                channelfmt.remove_offset()
            channel = channelfmt.get_channel()
            dirty = True
            b.Destroy()
            b = None
            wx.EndBusyCursor()

        if dirty is True:
            return channel
        return None