Audaspace File Paths Troubles

Hi everybody, long time!

So I’ve been trying to use Audaspace in UPBGE 0.3 but I’ve run into some complicated problems with - I believe, relative file pathing. I briefly got it to work by using an explicit path “C:\Users\Projects\etc”, but ofcourse I’d like this game to work regardless of where it’s installed on one’s harddrive, so I’ve tried to use relative paths. However, even though when debug-printing the paths, the relative path generated with ‘bge.logic.expandPath(’\‘)’ is identical to the explicit path, but UPBGE returns an error to the tune of ‘Object not of type Sound!’.

I’ve tried forcing a pathing error by deliberately pathing to a file that doesn’t exist, and the exact same error is returned: “Object no of type Sound!”. It couldn’t be finding an object, so it makes me think the string argument is being recognised as an Object for some reason. Has anyone run into this problem before? Or atleast, does anyone know what’s going on?

This is a class I created to handle instancing sounds in other scripts:

import bge
import aud

class soundObject():
    
    def playSound(fileName, volume, pitch):
        
        device = aud.Device()
        handle = device.play(fileName) # <--- This is the line the error claims is calling an "Object not of type Sound!"

        handle.pitch = pitch
        handle.volume = volume
        
    def classDebug(callBool, pathsBool, fileName):
        
        rootPath = bge.logic.expandPath("//")
        soundPath = rootPath[:len(rootPath) - 8] + "\\sounds"
        sound = soundPath + fileName
        
        if callBool:
        
            print ("Class SoundObject called")
            print ("Module classDebug called")
        
        if pathsBool:
        
            print ("Root path:           " + rootPath)
            print ("Sound path (folder): " + soundPath)
            print ("Sound path (file):   " + sound)
            print ("Ref. path (file):    " + "C:\\Users\\Thomas\\Documents\\Projects\\Games\\Doom-Like\\sounds\\Gun_Small_Fire.ogg")

And this is an excerpt of the script that is calling the function, and it is this call that generates the error:

if bge.logic.KX_INPUT_JUST_ACTIVATED in bge.logic.mouse.inputs[bge.events.LEFTMOUSE].queue:
                
            if cameraOb["shootReFire"] > reFireRate[self.equipped]:
                        
                cameraOb["shootReFire"] = 0.0                                            
                self.weapons[self.equipped][1] -= 1
                self.animLoop = True
                        
                if self.equipped == 0:
                        
                    sounds.soundObject.playSound("C:\\Users\Thomas\Documents\Projects\Games\Doom-Like\sounds\Gun_Small_Fire.ogg", 0.5, 1.0) # <--- This is the line that calls the function of the sound class that is causing the error

Verbatim error:

[ERROR] KX_PythonComponent[weaponOperations] - Failed to invoke the update callback.
Traceback (most recent call last):
  File "C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\Player_Controller.py", line 204, in update
  File "C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\sounds.py", line 9, in playSound
TypeError: Object is not of type Sound!

You need to wrap your sound file in an aud, factory container. Your playSound() function should be:

device = aud.Device()
factory = aud.Factory(fileName)
handle = device.play(factory)

handle.pitch = pitch
handle.volume = volume

Thanks for the reply, something I should have remembered lol. Strange that I got it to work without a Factory object, though more strangely, Blender isn’t recognising that ‘aud’ has a Factory function:

Traceback (most recent call last):
File “C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\Player_Controller.py”, line 204, in update
File “C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\sounds.py”, line 9, in playSound
AttributeError: module ‘aud’ has no attribute ‘Factory’ ( <— Strange)

When I try to add that factory = aud.Factory(fileName) line, I get that error. I might check out my UPBGE library files and see if maybe something has become corrupted, or is missing?

aud.Factory is deprecated in UPBGE 0.3+.

Here you have a simple example using expand path:

import aud, bge

device = aud.Device()
sName = bge.logic.expandPath("//") + "1360.wav"
sound = aud.Sound(sName)
sound_buffered = aud.Sound.buffer(sound.data(), 48000)

def sound_collision():
    device.play(sound_buffered)

Sound buffered.zip (275.7 KB)

3 Likes

Ayyy, that’s got it chief, problem solved! I’m having .volume and .pitch functions as ‘read-only’ troubles now, do you know of any up-to-date documentations I can use as a reference? Seems UPBGE.org is somewhat behind lol.

Again, big ups boss :grinning::point_right::point_right:, this has been eating at me for a week lol