def main(): custom_array = np.array( [[0, 0.035, 0], [-0.0303, 0.0175, 0], [-0.0303, -0.0175, 0], [0, -0.035, 0], [0.0303, -0.0175, 0], [0.0303, 0.0175, 0]]) src_coord = [1, 1, 1] lis_coord = [0.1, 0.1, 0.1] res = compute_array("cube.obj", src_coord, lis_coord, 0.5, 0.5, custom_array) w = WaveWriter('custom_array.wav', channels=np.shape(res['samples'])[0], samplerate=int(res['rate'])) w.write(np.array(res['samples']))
def main(): # Simulation using .obj file (and an optional .mtl file) ctx = ps.Context() ctx.diffuse_count = 20000 ctx.specular_count = 2000 ctx.channel_type = ps.ChannelLayoutType.stereo mesh1 = ps.loadobj( "cube.obj", "" ) # if the second argument is empty, the code will infer the .mtl name using .obj name scene = ps.Scene() scene.setMesh(mesh1) src_coord = [1, 1, 0.5] lis_coord = [5, 3, 0.5] src = ps.Source(src_coord) src.radius = 0.01 lis = ps.Listener(lis_coord) lis.radius = 0.01 res = scene.computeMultichannelIR(src, lis, ctx) with WaveWriter('test1.wav', channels=np.shape(res['samples'])[0], samplerate=int(res['rate'])) as w1: w1.write(np.array(res['samples'])) print("IR using .obj input written to test1.wav.") # Simulation using a shoebox definition ctx = ps.Context() ctx.diffuse_count = 20000 ctx.specular_count = 2000 ctx.channel_type = ps.ChannelLayoutType.stereo mesh2 = ps.createbox(10, 6, 2, 0.5, 0.5) scene = ps.Scene() scene.setMesh(mesh2) res = scene.computeMultichannelIR(src, lis, ctx) with WaveWriter('test2.wav', channels=np.shape(res['samples'])[0], samplerate=int(res['rate'])) as w: w2.write(np.array(res['samples'])) print("IR using shoebox input written to test2.wav.")
#!/usr/bin/env python ### Writting example from wavefile import WaveWriter, Format import numpy as np BUFFERSIZE = 512 NCHANNELS = 2 TITLE = "Some Noise" ARTIST = "The Artists" with WaveWriter( 'synth.ogg', channels=NCHANNELS, format=Format.OGG | Format.VORBIS, ) as w: w.metadata.title = "Some Noise" w.metadata.artist = "The Artists" data = np.zeros((NCHANNELS, BUFFERSIZE), np.float32) for x in range(256): # First channel: Saw wave sweep data[0, :] = (x * np.arange(BUFFERSIZE, dtype=np.float32) % BUFFERSIZE / BUFFERSIZE) # Second channel: Modulated square wave data[1, BUFFERSIZE - x * 2:] = 1 data[1, :BUFFERSIZE - x * 2] = -1 # Write it down w.write(data)
#!/usr/bin/env python ### Processing example import sys from wavefile import WaveReader, WaveWriter with WaveReader(sys.argv[1]) as r: with WaveWriter( 'output.wav', channels=r.channels, samplerate=r.samplerate, ) as w: w.metadata.title = r.metadata.title + " II" w.metadata.artist = r.metadata.artist for data in r.read_iter(size=512): sys.stdout.write("."); sys.stdout.flush() w.write(.8*data) # vim: noet ts=4 sw=4
from wavefile import WaveWriter, Format import numpy as np import pyaudio, sys SECONDS = 10 BUFFERSIZE = 512 SAMPLERATE = 48000 NCHANNELS = 2 TITLE = "Some Noise" ARTIST = "The Artists" NBUFFERS = int(SECONDS * SAMPLERATE / BUFFERSIZE) pa = pyaudio.PyAudio() with WaveWriter('recording.ogg', channels=NCHANNELS, samplerate=SAMPLERATE, format=Format.OGG | Format.VORBIS) as w: w.metadata.title = TITLE w.metadata.artist = ARTIST stream = pa.open( format=pyaudio.paFloat32, channels=NCHANNELS, rate=SAMPLERATE, frames_per_buffer=BUFFERSIZE, input=True, ) for x in range(NBUFFERS): data = stream.read(BUFFERSIZE)