예제 #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, pos, s, oc=2, o=(0, 1, 0, 0, 0, 1)):
		"""Takes a server and a position (usually the position of the player) and sets the listener their. Optionally, takes a number of output channels."""
		self.position = pos
		self.environment = libaudioverse.EnvironmentNode(s, "default")
		self.environment.panning_strategy = libaudioverse.PanningStrategies.hrtf
		self.environment.output_channels = oc
		self.environment.position = tuple(pos)
		self.environment.orientation = tuple(o)
		#self.environment.default_size = 100.0
		self.environment.connect(0, s)
		self.server = s
예제 #3
0
파일: sim3d.py 프로젝트: zmxu/libaudioverse
#demonstrates how to use the 3d simulation.
import libaudioverse
import collections
libaudioverse.initialize()

sim = libaudioverse.Simulation()
sim.set_output_device(-1)
world = libaudioverse.EnvironmentNode(sim, "default")
source = libaudioverse.SourceNode(sim, world)
print "Enter a path to a sound file."
filepath = raw_input()
n = libaudioverse.BufferNode(sim)
b = libaudioverse.Buffer(sim)
b.load_from_file(filepath)
n.buffer = b
n.connect(0, source, 0)

n.looping.value = True

world.connect_simulation(0)

print """Enter python expressions that evaluate to 3-tuples (x, y, z).
Positive x is to your right, positive y is above you, and positive z is behind you.
Enter quit to quit."""
while True:
    command = raw_input()
    if command == 'quit':
        break
    vect = eval(command)
    if not isinstance(vect, collections.Sized) or len(vect) != 3:
        print "Must evaluate to a 3-tuple.  Try again"
예제 #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