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.")
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
def stereo_pan(): synth = WaveSynth() # panning a stereo source: wave = Sample("samples/SOS 020.wav").clip( 6, 12).normalize().fadein(0.5).fadeout(0.5).lock() osc = Sine(0.4) panning = wave.copy().pan(lfo=osc).fadeout(0.2) with Output.for_sample(panning) as out: out.play_sample(panning) # panning a generated mono source: fm = Sine(0.5, 0.1999, bias=0.2) wave = synth.triangle(220, 5, fm_lfo=fm).lock() osc = Sine(0.4) panning = wave.copy().pan(lfo=osc).fadeout(0.2) with Output.for_sample(panning) as out: out.play_sample(panning)
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)
def main(track_file, outputfile=None, interactive=False): discard_unused = not interactive if interactive: repl = Repl(discard_unused_instruments=discard_unused) repl.do_load(track_file) repl.cmdloop("Interactive Samplebox session. Type 'help' for help on commands.") else: song = Song() song.read(track_file, discard_unused_instruments=discard_unused) with Output() as out: if out.supports_streaming: # mix and stream output in real time print("Mixing and streaming to speakers...") out.play_samples(song.mix_generator(), False) print("\r ") else: # output can't stream, fallback on mixing everything to a wav print("(Sorry, streaming audio is not possible, perhaps because you don't have pyaudio installed?)") song.mix(outputfile) mix = Sample(wave_file=outputfile) print("Playing sound...") out.play_sample(mix)