Skip to content

TypeError: '_AudioCallbackUserdata' object is not callable #128

@splatpope

Description

@splatpope

``I am trying to repeatedly play a very small sound sample (1/60th of a second) using tcod's sdl.audio module.

Since I am having trouble synchronizing the audio buffer, I decided to try the pull approach with a callback.

Here is a minimal example :

import tcod
import tcod.sdl.audio
import numpy as np
from scipy import signal

device = tcod.sdl.audio.open(callback=True)

sample_rate = device.frequency
n_samples = device.buffer_samples
duration = n_samples // sample_rate

print(device.format)

t = np.linspace(0, duration, n_samples, endpoint=False)
wave = signal.square(t * 2 * np.pi * 440).astype(device.format)
wave = device.convert(wave)

def pull_wave(device: tcod.sdl.audio.AudioDevice, stream: np.ndarray):
    stream.data = wave.data

device.callback = pull_wave

And here is the error I am getting (same as with the more complicated usage inside my application) :

Exception ignored from cffi callback <function _sdl_audio_callback at 0x00000181C7418D30>:
Traceback (most recent call last):
  File "C:\Users\Splatpope\AppData\Roaming\Python\Python39\site-packages\tcod\sdl\audio.py", line 486, in _sdl_audio_callback
    data: _AudioCallbackUserdata = ffi.from_handle(userdata)()
TypeError: '_AudioCallbackUserdata' object is not callable
forrtl: error (200): program aborting due to control-C event
Image              PC                Routine            Line        Source
libifcoremd.dll    00007FFF7C4BDF54  Unknown               Unknown  Unknown
KERNELBASE.dll     00007FFFD5A929F3  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFFD66E7614  Unknown               Unknown  Unknown
ntdll.dll          00007FFFD81E26A1  Unknown               Unknown  Unknown

Platform : Windows 10
Python version : 3.9.13
tcod version from pip : 15.0.1

Notes :

  • I have not managed to find any examples of audio callback usage with python-tcod anywhere, so my implementation might be flawed

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions