示例#1
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
示例#2
0
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())

formatter.convert()

# no more need of input data, can close
audio.close()

if args.m:
    formatter.mul(args.m)

if args.b:
    formatter.bias(args.b)

# Save the converted channel
audio_out = AudioPCM()
audio_out.append_channel( formatter.channel )
audiodata.save( args.o, audio_out )

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