示例#1
0
def main(args):
    if len(args) < 1:
        raise SystemExit(
            "Mixes one or more audio files. Arguments: inputfile...")
    hqresample = AudiofileToWavStream.supports_hq_resample()
    if not hqresample:
        print(
            "WARNING: ffmpeg isn't compiled with libsoxr, so hq resampling is not supported."
        )
    wav_streams = [
        AudiofileToWavStream(filename, hqresample=hqresample)
        for filename in args
    ]
    with StreamMixer(wav_streams, endless=True) as mixer:
        mixed_samples = iter(mixer)
        with Output(mixer.samplerate, mixer.samplewidth,
                    mixer.nchannels) as output:
            levelmeter = LevelMeter(rms_mode=False, lowest=-50)
            temp_stream = AudiofileToWavStream("samples/909_crash.wav",
                                               hqresample=hqresample)
            for timestamp, sample in mixed_samples:
                levelmeter.update(sample)
                output.play_sample(sample)
                time.sleep(sample.duration * 0.4)
                levelmeter.print(bar_width=60)
                if 5.0 <= timestamp <= 5.1:
                    mixer.add_stream(temp_stream)
                if 10.0 <= timestamp <= 10.1:
                    sample = Sample("samples/909_crash.wav").normalize()
                    mixer.add_sample(sample)
    print("done.")
示例#2
0
 def _start_from_thread():
     # start loading the track from a thread to avoid gui stutters when loading takes a bit of time
     tf.stream = AudiofileToWavStream(filename,
                                      hqresample=hqresample)
     self.mixer.add_stream(tf.stream, [tf.volumefilter])
     tf.playback_started = datetime.datetime.now()
     tf.state = TrackFrame.state_playing
     tf.volume = volume
示例#3
0
 def start_stream(self, mixer):
     self.stream = AudiofileToWavStream(self.current_track_filename,
                                        hqresample=hqresample)
     self.stream_started = time.time()
     self.after_idle(lambda s=self: s.set_state(s.state_playing))
     mixer.add_stream(self.stream, [self.volumefilter])
     if self.stream.format_probe and self.stream.format_probe.duration and not self.current_track_duration:
         # get the duration from the stream itself
         self.current_track_duration = self.stream.format_probe.duration
     self.stream_opened = True
示例#4
0
 def set_effect(self, effect_nr, filename):
     try:
         with AudiofileToWavStream(filename, hqresample=hqresample) as wav:
             sample = Sample(wav)
             self.effects[effect_nr] = sample
     except IOError as x:
         print("Can't load effect sample:", x)
     else:
         for button in self.buttons:
             if button.effect_nr == effect_nr:
                 button["state"] = tk.NORMAL
                 button["text"] = os.path.splitext(
                     os.path.basename(filename))[0]
                 break
示例#5
0
 def do_button_release(self, event):
     if event.state & 0x0100 == 0:
         return  # no left mouse button event
     shift = event.state & 0x0001
     if shift:
         filename = tkinter.filedialog.askopenfilename()
         if filename:
             with AudiofileToWavStream(filename,
                                       hqresample=hqresample) as wav:
                 sample = Sample(wav)
                 self.jingles[event.widget.jingle_nr] = sample
             event.widget["state"] = tk.NORMAL
             event.widget["text"] = os.path.splitext(
                 os.path.basename(filename))[0]
     else:
         sample = self.jingles[event.widget.jingle_nr]
         if sample:
             self.app.play_sample(sample)
示例#6
0
def main(args):
    if len(args) < 1:
        raise SystemExit("Mixes one or more audio files. Arguments: inputfile...")
    hqresample = AudiofileToWavStream.supports_hq_resample()
    if not hqresample:
        print("WARNING: ffmpeg isn't compiled with libsoxr, so hq resampling is not supported.")
    wav_streams = [AudiofileToWavStream(filename, hqresample=hqresample) for filename in args]
    with StreamMixer(wav_streams, endless=True) as mixer:
        mixed_samples = iter(mixer)
        with Output(mixer.samplerate, mixer.samplewidth, mixer.nchannels) as output:
            if not output.supports_streaming:
                raise RuntimeError("need api that supports streaming")
            levelmeter = LevelMeter(rms_mode=False, lowest=-50)
            output.register_notify_played(levelmeter.update)
            for timestamp, sample in mixed_samples:
                output.play_sample(sample)
                levelmeter.print(bar_width=60)
    print("done.")
示例#7
0
            self.pb_left.configure(style="yellow.Vertical.TProgressbar")
        else:
            self.pb_left.configure(style="green.Vertical.TProgressbar")
        if right > -3:
            self.pb_right.configure(style="red.Vertical.TProgressbar")
        elif right > -6:
            self.pb_right.configure(style="yellow.Vertical.TProgressbar")
        else:
            self.pb_right.configure(style="green.Vertical.TProgressbar")
        self.after(self.update_rate, self.update)


def play_gui(file_or_stream):
    root = tk.Tk()
    app = LevelGUI(file_or_stream, master=root)
    app.mainloop()


if __name__ == "__main__":
    if len(sys.argv) != 2:
        raise SystemExit("give audio file to play as an argument.")
    hqresample = AudiofileToWavStream.supports_hq_resample()
    with AudiofileToWavStream(sys.argv[1], hqresample=hqresample) as stream:
        print(stream.format_probe)
        if stream.conversion_required and not hqresample:
            print(
                "WARNING: ffmpeg isn't compiled with libsoxr, so hq resampling is not supported."
            )
        play_gui(stream)
    print("Done.")