neXyon / audaspace

A high level and feature rich audio library written in C++ with language bindings.
Apache License 2.0
57 stars 25 forks source link

Play sound with AUD_PlaybackManager_play() from PyObject #41

Closed RafaelTavars closed 4 months ago

RafaelTavars commented 4 months ago

Hi neXyon! I'm working to implement KX_Speaker for BGE and recently I'm having trouble reading your API, is there any way to play a sound in Python's playbackManager in C++ ?

For example, I write in Python by passing the aud.PlaybackManager into an object:

import aud

manager = aud.PlaybackManager(aud.Device())
own.playbackManager = manager 

I want to play a sound with this PyObject, but I can't figure out what to do, since there are AUD_PlaybackManager_play() binding and PlaybackManager_play() for Python

Is there any way to convert this object in python to AUD_PlaybackManager ?

AUD_PlaybackManager *self = static_cast<AUD_PlaybackManager *>(m_playback); // m_playback: PyObject -> an aud.Playbackmanager in python
AUD_PlaybackManager_play(m_playback, sound, m_playback_catkey); // sound: AUD_Sound
RafaelTavars commented 4 months ago

Today I discovered how to do this:

PlaybackManagerP *playback = checkPlaybackManager(m_playback);
if (playback) {
    AUD_PlaybackManager_play(playback->playbackManager, sound, m_playback_catkey);
}

lol I've been stuck on this for 3 days, it was simpler than I thought 😄, sorry for bothering you