Problem with a class I'm writing

3 views
Skip to first unread message

Marcus99

unread,
Aug 1, 2018, 12:48:49 PM8/1/18
to libaudioverse
So, I've been trying to write a class to help make things a lot simpler when it comes to working with Libaudioverse. I'm very new to it, so the likelihood  of making some kind of simple mistake that I can't identify is quite high. I will paste the short class below, and if anyone can take a look and see if they can figure out why the play function outputs no audio, I would appreciate it. (when calling the function, I do use time.sleep to make sure that the program stays open long enough for any sound to play) Part of me knows what I'm doing, the other half doesn't.

import libaudioverse

class sound_bank(object):

def __init__(self):
libaudioverse.initialize()
self.server=libaudioverse.Server()
self.environment=libaudioverse.EnvironmentNode(self.server, "default")
self.environment.panning_strategy=libaudioverse.PanningStrategies.hrtf
self.environment.output_channels=2
self.environment.connect(0, self.server)
self.server.set_output_device("-1")
self.cache={}

def load(self, path):
if path not in self.cache:
buffer=libaudioverse.Buffer(self.server)
buffer.load_from_file(path)
self.cache[path]=buffer
return True
return False
def play(self, path, loop=False):
result=self.load(path)
player=libaudioverse.BufferNode(self.server)
player.looping=loop
if result==True:
player.buffer=self.cache[path]
source=libaudioverse.SourceNode(self.server, self.environment)
player.connect(0, source, 0)
if result==False:
player.position=0
player.state=libaudioverse.NodeStates.playing

Srinids Kher

unread,
Sep 23, 2018, 6:37:46 AM9/23/18
to libaudioverse
Hi,
I'm using a similar approach, a class that wraps the Libaudioverse basic setups.
With your implementation, thoug, you can load only one file in the one buffer, I could suggest a modification adding a class that handles "audio object management", if you want two or more audio objects obviously.
Class like this.

class AudioObj(object):
  def __init__(self, name, loop, ...ecc...):
    self.name = name
    self.loop = loop
    ...

   
  def create(self):
    #create buffers ecc
    self.buf=libaudioverse.Buffer( s)
    self.bNode=libaudioverse.BufferNode( s)
    ...

  def load(self):
    self.buf.load_from_file( self.name)
    self.bNode.buffer=self.buf
    ...
   

  def play(self,loop):
    #handle playing
    ....
 
def stop(self):
   # stops audio/buffer
   ...
    

I took this approach because of my OO programming experience, I could be wrong but it works for me :)
I hope it's not too late to answer.   
Reply all
Reply to author
Forward
0 new messages