def make_fm(carrier, ratio, index): carrier_node = libaudioverse.SineNode(simulation) modulator_node = libaudioverse.SineNode(simulation) modulator_frequency = ratio * carrier modulator_amplitude = index * modulator_frequency carrier_node.frequency.value = carrier modulator_node.frequency.value = modulator_frequency modulator_node.mul.value = modulator_amplitude modulator_node.connect_property(0, carrier_node.frequency) return carrier_node
def __init__(self, width, height, lowFreq=500, highFreq=5000, sweepDelay=0.5, sweepDuration=4, sweepCount=4, reverseBrightness=False): self.width = width self.height = height self.baseFreq = lowFreq self.octiveCount = math.log(highFreq / lowFreq, 2) self.sweepDelay = sweepDelay self.sweepDuration = sweepDuration self.sweepCount = sweepCount self.reverseBrightness = reverseBrightness self.lavSim = libaudioverse.Simulation() self.lavPanner = libaudioverse.MultipannerNode(self.lavSim, "default") self.lavPanner.strategy = libaudioverse.PanningStrategies.hrtf self.lavPanner.should_crossfade = False self.lavPanner.connect_simulation(0) self.lavWaves = [] for x in xrange(self.height): lavPanner = libaudioverse.AmplitudePannerNode(self.lavSim) lavPanner.should_crossfade = False lavPanner.connect_simulation(0) lavWave = libaudioverse.SineNode(self.lavSim) lavWave.mul = 0 lavWave.frequency.value = self.baseFreq * ( (2**self.octiveCount)**(x / self.height)) lavWave.connect(0, lavPanner, 0) lavWave.connect(0, self.lavPanner, 0) self.lavWaves.append((lavWave, lavPanner)) self.lavSim.set_output_device(-1)
def __init__(self, width, height, lowFreq=90, highFreq=4000): self.width = width self.height = height self.lowFreq = lowFreq self.highFreq = highFreq self.lavSim = libaudioverse.Simulation() self.lavWave = libaudioverse.AdditiveSawNode(self.lavSim) self.lavWave.mul = 0 self.lavWave.frequency.value = lowFreq self.lavWave.connect_simulation(0) self.lavWave2 = libaudioverse.SineNode(self.lavSim) self.lavWave2.mul = 0 self.lavWave2.frequency.value = lowFreq * (highFreq / lowFreq) self.lavWave2.connect_simulation(0) self.lavNoise = libaudioverse.NoiseNode(self.lavSim) self.lavNoise.mul.value = 0 self.lavNoise.noise_type.value = libaudioverse.NoiseTypes.brown self.lavNoise.connect_simulation(0) self.lavSim.set_output_device(-1)
fm2.mul.value = 0.1 noise.mul.value = 0.05 fm1.mul.set(time=28.0, value=0.1) fm2.mul.set(time=28.0, value=0.1) noise.mul.set(time=28.0, value=0.05) fm1.mul.linear_ramp_to_value(time=29.8, value=0.0) fm2.mul.linear_ramp_to_value(time=29.8, value=0.0) noise.mul.linear_ramp_to_value(time=29.8, value=0.0) #pass everything through a ringmod. rm = libaudioverse.RingmodNode(simulation) fm1.connect(0, rm, 0) fm2.connect(0, rm, 0) noise.connect(0, rm, 0) modulator = libaudioverse.SineNode(simulation) modulator.frequency.value = 300 modulator.connect(0, rm, 1) #The ringmod starts fading out at 30 seconds. rm.mul.set(time=28.0, value=1.0) rm.mul.linear_ramp_to_value(time=30.0, value=0.0) #This is the 3D infrastructure. world = libaudioverse.EnvironmentNode(simulation, "default") world.orientation.value = (0, 1, 0, 0, 0, 1) #Turn on HRTF. world.default_panning_strategy.value = libaudioverse.PanningStrategies.hrtf world.output_channels.value = 2
import libaudioverse import threading libaudioverse.initialize() server = libaudioverse.Server() server.set_output_device() s1 = libaudioverse.SineNode(server) s1.frequency = 100 s2 = libaudioverse.SineNode(server) s2.frequency = 200 s3 = libaudioverse.SineNode(server) s3.frequency = 400 fader = libaudioverse.CrossfaderNode(server, channels=2, inputs=3) s1.connect(0, fader, 0) s2.connect(0, fader, 1) s3.connect(0, fader, 2) fader.connect(0, fader.server) #Let's crossfade back and fortha cross all the inputs repeatedly. crossfade_sem = threading.Semaphore(value=0) def done(*args): crossfade_sem.release() fader.set_finished_callback(done)
fm2.mul.value = 0.1 noise.mul.value = 0.05 fm1.mul.set(time=28.0, value=0.1) fm2.mul.set(time=28.0, value=0.1) noise.mul.set(time=28.0, value=0.05) fm1.mul.linear_ramp_to_value(time=29.8, value=0.0) fm2.mul.linear_ramp_to_value(time=29.8, value=0.0) noise.mul.linear_ramp_to_value(time=29.8, value=0.0) # pass everything through a ringmod. rm = libaudioverse.RingmodNode(server) fm1.connect(0, rm, 0) fm2.connect(0, rm, 0) noise.connect(0, rm, 0) modulator = libaudioverse.SineNode(server) modulator.frequency.value = 300 modulator.connect(0, rm, 1) # The ringmod starts fading out at 30 seconds. rm.mul.set(time=28.0, value=1.0) rm.mul.linear_ramp_to_value(time=30.0, value=0.0) # This is the 3D infrastructure. world = libaudioverse.EnvironmentNode(server, "default") world.orientation.value = (0, 1, 0, 0, 0, 1) # Turn on HRTF. world.panning_strategy.value = libaudioverse.PanningStrategies.hrtf world.output_channels.value = 2
import libaudioverse import time #initialize libaudioverse. libaudioverse.initialize() #make a device using the default (always stereo) output. sim = libaudioverse.Simulation() sim.set_output_device() #make a sine node. sine_node = libaudioverse.SineNode(sim) sine_node.frequency.value = 440 sine_node.connect_simulation(0) time.sleep(5.0) libaudioverse.shutdown()
#Implements a ringmod using the custom object. import libaudioverse import time libaudioverse.initialize() sim = libaudioverse.Simulation() sim.set_output_device(-1) def ringmod(obj, frames, input_count, inputs, output_count, outputs): for i in xrange(frames): outputs[0][i] = inputs[0][i]*inputs[1][i] ringmod_node= libaudioverse.CustomNode(sim, 2, 1, 1, 1) ringmod_node.set_processing_callback(ringmod) w1=libaudioverse.SineNode(sim) w2=libaudioverse.SineNode(sim) w1.frequency.value = 30 w2.frequency.value = 300 w1.connect(0, ringmod_node, 0) w2.connect(0, ringmod_node, 1) ringmod_node.connect_simulation(0) time.sleep(5.0)
import libaudioverse import time #initialize libaudioverse. libaudioverse.initialize() #make a device using the default (always stereo) output. server = libaudioverse.Server() server.set_output_device() #make a sine node. sine_node = libaudioverse.SineNode(server) sine_node.frequency = 440 sine_node.connect(0, sine_node.server) time.sleep(5.0) libaudioverse.shutdown()
import libaudioverse import threading libaudioverse.initialize() sim = libaudioverse.Simulation() sim.set_output_device(-1) s1 = libaudioverse.SineNode(sim) s1.frequency = 100 s2 = libaudioverse.SineNode(sim) s2.frequency = 200 s3 = libaudioverse.SineNode(sim) s3.frequency = 400 fader = libaudioverse.CrossfaderNode(sim, channels = 2, inputs = 3) s1.connect(0, fader, 0) s2.connect(0, fader, 1) s3.connect(0, fader, 2) fader.connect_simulation(0) #Let's crossfade back and fortha cross all the inputs repeatedly. crossfade_sem = threading.Semaphore(value = 0) def done(*args): crossfade_sem.release() fader.finished_event = done for i in xrange(5): fader.crossfade(duration = 0.5, input = 1)
#Synthesize binaural beats, play for 5 seconds. #But also record this using a graph listener. #Note: this is not production quality. #If this example is made too long, it will run out of ram; the solution is to write the wave file in a thread. import libaudioverse import wave import time import queue import struct libaudioverse.initialize() server = libaudioverse.Server() server.set_output_device() w1 = libaudioverse.SineNode(server) w2 = libaudioverse.SineNode(server) listener = libaudioverse.GraphListenerNode(server, channels=2) merger = libaudioverse.ChannelMergerNode(server, channels=2) w1.connect(0, merger, 0) w2.connect(0, merger, 1) merger.connect(0, listener, 0) #settings for binaural beats: 300 and 305. w1.frequency = 300 w2.frequency = 305 #the queue and callback for recording. audio_queue = queue.Queue() def callback(obj, frames, channels, buffer):