Exemple #1
0
 def get(self, name):
     if name in self._sounds:
         return self._sounds[name]
     fname = self._sound_files[name]
     if os.path.splitext(fname)[1] != ".ogg":
         raise ValueError("Not an Ogg file.")
     relpath = os.path.relpath(fname, os.getcwd())
     fp = VorbisFile(relpath)
     sound = openal.Buffer(fp)
     self._sounds[name] = sound
     return sound
Exemple #2
0
 def __init__(s,
              n,
              x,
              y,
              fn,
              m,
              active=False,
              animated=False,
              mod_amp=False,
              offset=None,
              looping=True):
     cx, cy = x * m.pix[0], y * m.pix[1]
     s.n = n
     s.fn = fn
     s.m = m
     s.active = active
     s.solo = False
     s.selected = False
     s.animated = animated
     s.vx, s.vy = 0, 0
     s.speed = 5
     s.mod_amp = mod_amp
     if (offset is None) or (offset == 0.):
         s.offset = r() * 30.
     else:
         s.offset = offset
     s.source = m.contextlistener.get_source()
     s.source.buffer = openal.Buffer(fn)
     s.circ = m.w.create_oval(cx - m.cr,
                              cy - m.cr,
                              cx + m.cr,
                              cy + m.cr,
                              fill="white",
                              tags="C%u" % n)
     s.text = m.w.create_text(cx, cy, text="%u" % n, tags="T%u" % n)
     m.w.tag_bind("C%u" % n, "<Button-2>", s.clicked)
     m.w.tag_bind("T%u" % n, "<Button-2>", s.clicked)
     m.w.tag_bind("C%u" % n, "<Button-1>", s.sel)
     m.w.tag_bind("T%u" % n, "<Button-1>", s.sel)
     m.w.tag_bind("C%u" % n, "<B1-Motion>", s.moved)
     m.w.tag_bind("T%u" % n, "<B1-Motion>", s.moved)
     m.w.tag_bind("C%u" % n, "<Button-3>", s.makesolo)
     m.w.tag_bind("T%u" % n, "<Button-3>", s.makesolo)
     s.update_color()
     s.x, s.y = cx, cy
     s.source.looping = looping
     s.update_parameters()
Exemple #3
0
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.full_fn = self.app.resource_path(self.fn, throw=True)

            if self.ext == ".wav":
                # self.data = openal.oalOpen(self.fn)
                self.data = openal.Buffer(openal.WaveFile(self.full_fn))
                self.stream = False
            elif self.ext in (".mp3", ".ogg"):
                self.data = openal.oalStream(self.full_fn)
                # print(self.data)
                # self.stream = self.app.on_update.connect(
                #     self.data.update
                #     # WeakLambda([self], lambda t, self: self.data.update)
                # )
            elif not self.ext:
                self.data = None
                self.stream = False
                pass  # empty sound
            else:
                raise ValueError("invalid audio filetype")
Exemple #4
0
import sys
import time
import math
import random
import os

import openal

device = openal.Device()
contextlistener = device.ContextListener()
source = contextlistener.get_source()
source2 = contextlistener.get_source()
expsources = [contextlistener.get_source() for i in xrange(20)]
buffer = openal.Buffer(os.path.join('sounds', '440.wav'))
buffer2 = openal.Buffer(os.path.join('sounds', 'water.wav'))
expbuffers = [
    openal.Buffer(os.path.join('sounds', 'explodes', x))
    for x in os.listdir(os.path.join('sounds', 'explodes')) if x[0] != '.'
]

contextlistener.position = 0, 0, 0
contextlistener.velocity = 0, 0, 0
contextlistener.orientation = 0, 1, 0, 0, 0, 1

source2.buffer = buffer2
source2.looping = True
source2.gain = .5
source2.position = 3, 3, -3
source2.play()

source.buffer = buffer
Exemple #5
0
    def __init__(self, data: SoundData):
        self.handle = openal.Buffer(data.Format, data.Data, data.Length,
                                    data.SampleRate)
        self.data = data

        ObjectManager.AddObject(self)
 def create_sound(self, filepath):
     file_ = openal.WaveFile(filepath)
     buffer_ = openal.Buffer(file_)
     return buffer_
Exemple #7
0
  print
  print o
  for k in dir(o):
   if k[0] == '_': continue
   print "   ", k, repr(getattr(o, k))
  print

d = openal.Device()
po(d)
cl = d.ContextListener()
po(cl)
cl.position = 0,0,0
cl.velocity = 0,0,0
cl.orientation = 1,0,0 , 0,0,1 # forward, up

b = openal.Buffer(sys.argv[1])
po(b)

s = cl.get_source()
po(s)

s.buffer = b
s.looping = True
s.gain = 1
#s.position=10,10,0

t = 0
clock = pygame.time.Clock()
s.play()
while True:
    t += clock.tick()/1000
Exemple #8
0
import sys
import time
import math
import random
import os

import openal

device = openal.Device()
contextlistener = device.ContextListener()
source = contextlistener.get_source()
buffer = openal.Buffer(os.path.join('sounds', '440.wav'))

contextlistener.position = 0, 0, 0
contextlistener.velocity = 0, 0, 0
contextlistener.orientation = 0, 1, 0, 0, 0, 1

source.buffer = buffer
source.looping = True
source.gain = 1
source.play()

t = 0
amplitude = 1
freq = 1
while True:
    source.position = amplitude * math.sin(t * freq), amplitude * math.cos(
        t * freq), 0
    source.velocity = amplitude * freq * math.cos(
        t * freq), -amplitude * freq * math.sin(t * freq), 0
    print(t * 180 / math.pi) % 360