예제 #1
0
 def __init__(self,
              md=125,
              density=0.8,
              reverbcutoff=22050,
              reverbtime=1.0):
     libaudioverse.initialize()
     self.server = libaudioverse.Server()
     self.server.set_output_device()
     self.world = libaudioverse.EnvironmentNode(self.server, "default")
     self.world.panning_strategy = libaudioverse.PanningStrategies.hrtf
     self.world.orientation = 0, 1, 0, 0, 0, 1
     self.world.max_distance = md
     self.world.distance_model = libaudioverse.DistanceModels.inverse_square
     self.world.min_reverb_level = 1
     self.world.max_reverb_level = 1
     self.reverb = libaudioverse.FdnReverbNode(self.server)
     send = self.world.add_effect_send(channels=4,
                                       is_reverb=True,
                                       connect_by_default=True)
     self.world.connect(send, self.reverb, 0)
     self.reverb.connect(0, self.server)
     self.reverb.density = density
     self.reverb.cutoff_frequency = reverbcutoff
     self.reverb.t60 = reverbtime
     self.reverb.default_reverb_distance = 50
예제 #2
0
	def __init__(self,speechPlayer,sampleRate):
		self.speechPlayer=speechPlayer
		libaudioverse.initialize()
		self.lavServer=libaudioverse.Server(22050,64)
		self.lavServer.set_output_device("default")
		self.lavPullNode=libaudioverse.PullNode(self.lavServer,sampleRate,1)
		self.lavPullNode.connect(0,self.lavServer)
		self.lavPullNode.set_audio_callback(self.lavPullNodeCallback)
예제 #3
0
#a simple command line media player.
import libaudioverse
import os.path
libaudioverse.initialize()

server = libaudioverse.Server()
server.set_output_device()

print("""Command line Media player.
Please enter the path to a file in a format supported by Libsndfile: typically wave or ogg."""
      )
filepath = input()
filepath = os.path.abspath(filepath)
filenode = libaudioverse.BufferNode(server)
buffer = libaudioverse.Buffer(server)
buffer.load_from_file(filepath)
filenode.buffer = buffer


#callback for when the file finishes.
def finished(obj):
    print("Finished playing.")


filenode.set_end_callback(finished)

filenode.connect(0, filenode.server)

commands = """Commands:
play
pause
예제 #4
0
    def __init__(self,
                 f,
                 duration,
                 min_x,
                 max_x,
                 min_y,
                 max_y,
                 x_ticks=None,
                 y_ticks=None,
                 zero_ticks=False,
                 hrtf=False,
                 axis_ticks=False):
        """Parameters:

f: A callable. Given a value for x, return a value for y.
duration: The total duration of the graph. We reach max_x at duration seconds, then stop.
min_x, max_x: The range of the X axis.
min_y, max_y: The range of the y axis.
x_ticks: If set to a value besides None, tick for every time we cross a multiple of the value.
y_ticks: x_ticks, but for y.
zero_ticks: tick when y crosses zero.
hrtf: If True, use HRTF panning.
axis_ticks: If True, tick for crossing x=0 or y=0.

x_ticks and y_ticks exist to allow representing graph lines through audio.
The visual equivalent of these values is the setting which allows one to specify the size of grid squares.
As this class graphs, it will produce distinct ticks as the value of f crosses multiples of x_ticks or y_ticks."""
        # This is around 3 milliseconds.  We can probably increase the resolution further.
        self.server = libaudioverse.Server(block_size=block_size,
                                           sample_rate=sr)
        self.main_tone = libaudioverse.AdditiveTriangleNode(self.server)
        self.main_tone.frequency = main_start_frequency
        self.main_tone.mul = main_volume
        # This helps HRTF a little.
        self.main_noise = libaudioverse.NoiseNode(self.server)
        self.main_noise.mul = 0.005
        self.undefined_noise = libaudioverse.NoiseNode(self.server)
        self.undefined_noise.mul = 0
        self.undefined_noise.noise_type = libaudioverse.NoiseTypes.pink
        self.panner = libaudioverse.MultipannerNode(self.server, "default")
        self.environment = libaudioverse.EnvironmentNode(
            self.server, "default")
        self.source = libaudioverse.SourceNode(self.server, self.environment)
        self.main_tone.connect(0, self.panner, 0)
        self.main_tone.connect(0, self.source, 0)
        if hrtf:
            self.main_noise.connect(0, self.source, 0)
            self.undefined_noise.connect(0, self.source, 0)
            self.environment.connect(0, self.server)
            self.environment.panning_strategy = libaudioverse.PanningStrategies.hrtf
            self.environment.position = (0, 0, hrtf_listener_offset)
        else:
            self.undefined_noise.connect(0, self.panner, 0)
            self.panner.connect(0, self.server)
        # These are for the small ticks. We don't necessarily use them, but we get them going anyway so that we can if we want.
        self.x_ticker = libaudioverse.AdditiveSquareNode(self.server)
        self.y_ticker = libaudioverse.AdditiveSawNode(self.server)
        self.zero_ticker = libaudioverse.AdditiveSawNode(self.server)
        self.x_ticker.mul = 0
        self.y_ticker.mul = 0
        self.zero_ticker.mul = 0
        self.x_ticker.frequency = 115
        self.x_ticker.connect(0, self.panner, 0)
        self.y_ticker.connect(0, self.panner, 0)
        self.zero_ticker.connect(0, self.panner, 0)
        self.x_ticker.connect(0, self.source, 0)
        self.y_ticker.connect(0, self.source, 0)
        self.zero_ticker.connect(0, self.source, 0)
        self.prev_x = min_x
        self.prev_y = min_y + (max_y - min_y) / 2
        try:
            tmp = f(min_x)
            if isinstance(tmp, float):
                self.prev_y = tmp
        except:
            pass
        if self.prev_y < 0: self.prev_y_sign = -1
        elif self.prev_y == 0: self.prev_y_sign = 0
        else: self.prev_y_sign = 1
        self.server.set_block_callback(self.model_update)
        # We start not faded out.
        self.faded_out = False
        # Copy everything.
        self.f = f
        self.duration = duration
        self.min_x = min_x
        self.min_y = min_y
        self.max_x = max_x
        self.max_y = max_y
        self.hrtf = hrtf
        self.x_ticks = x_ticks
        self.y_ticks = y_ticks
        self.zero_ticks = zero_ticks
        self.axis_ticks = axis_ticks
        self.finished = False
예제 #5
0
import libaudioverse

libaudioverse.initialize()

server = libaudioverse.Server(block_size=128)


def make_fm(carrier, ratio, index):
    carrier_node = libaudioverse.SineNode(server)
    modulator_node = libaudioverse.SineNode(server)
    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(0, carrier_node.frequency)
    return carrier_node


fm1 = make_fm(carrier=50, ratio=0.5, index=50)
fm2 = make_fm(carrier=90, ratio=1.03, index=15)

# A bit of noise makes the HRTF much more obvious.
noise = libaudioverse.NoiseNode(server)
noise.noise_type.value = libaudioverse.NoiseTypes.pink

fm1.mul.value = 0.1
fm2.mul.value = 0.1
noise.mul.value = 0.05

fm1.mul.set(time=28.0, value=0.1)