[ctypes-users] Dereferencing a pointer
Brought to you by:
theller
|
From: Bryan D R. <bdr...@ju...> - 2004-06-28 02:18:49
|
I am currently working with pyFMOD (python extensions to FMOD, a sound
library) to add callback functionality to the python library. Several
functions in FMOD/pyFMOD return void pointers, notably the callback
functions
FOUND_STREAMCALLBACK
Callback used with user streams.
signed char FOUND_STREAMCALLBACK(
FOUND_STREAM *stream,
void *buff,
int len,
int param
);
FOUND_DSPCALLBACK
Callback definition for DSP units.
void *FSOUND_DSPCALLBACK(
void *originalbuffer,
void *newbuffer,
int length,
int param
);
Here is my callback code which is located in pyFMOD
#Bryan's Callback Code:
_FSOUND_DSPCALLBACK = CFUNCTYPE(c_void_p, pointer(c_int), pointer(c_int),
c_int, c_int)
_FSOUND_STREAMCALLBACK = CFUNCTYPE(c_byte, c_int, c_void_p, c_int, c_int)
_FSOUND_ALLOCCALLBACK = CFUNCTYPE(c_void_p, c_uint)
_FSOUND_REALLOCCALLBACK = CFUNCTYPE(c_void_p, c_void_p, c_uint)
_FSOUND_READCALLBACK = CFUNCTYPE(c_int, c_void_p, c_int, c_uint)
_FSOUND_TELLCALLBACK = CFUNCTYPE(c_int, c_uint)
#The next function had a void return type. I'm not sure how to do that
in ctypes.
#If this doesn't work, I'll try posting to the mailing list.
_FSOUND_FREECALLBACK = CFUNCTYPE(c_void_p, c_void_p)
#The next function should return void as well.
_FSOUND_CLOSECALLBACK = CFUNCTYPE(c_void_p, c_uint)
#This function uses a signed character for input 3, the last one.
#Not sure if c_byte is the correct type or not.
_FSOUND_SEEKCALLBACK = CFUNCTYPE(c_int, c_uint, c_int, c_byte)
#This function used a signed character as well.
_FSOUND_OPENCALLBACK = CFUNCTYPE(c_uint, c_char_p)
This is the code I am trying to run and get the error with
import pyFMOD
from ctypes import *
def myDSP_Callback(originalbuffer, newbuffer, length, param):
print "timmy"
originalbuffer.contents
pyFMOD.FSOUND_Init(44100, 32, 0);
s = pyFMOD.FSOUND_Stream_OpenFile(".\\forkbomb.ogg", pyFMOD.FSOUND_2D, 0)
a = pyFMOD.FSOUND_Stream_CreateDSP(s, myDSP_Callback, 301, 0)
pyFMOD.FSOUND_DSP_SetActive(a, True)
pyFMOD.FSOUND_Stream_Play(0, s)
print "started"
for i in range(1000000):
pass
print "stopped"
pyFMOD.FSOUND_Stream_Stop(s)
This is the error I get
Traceback (most recent call last):
File "C:\Source\Python\pyDanceR\fmodTest.py", line 1, in ?
import pyFMOD
File "C:\PYTHON23\lib\site-packages\pyFMOD.py", line 6, in ?
_FSOUND_DSPCALLBACK = CFUNCTYPE(c_void_p, pointer(c_int),
pointer(c_int), c_int, c_int)
File "C:\PYTHON23\Lib\site-packages\ctypes\__init__.py", line 206, in
pointer
return POINTER(type(inst))(inst)
File "C:\PYTHON23\Lib\site-packages\ctypes\__init__.py", line 189, in
POINTER
{'_type_': cls})
TypeError: _type_ must have storage info
How do I acess and modify the pointer original buffer? I know it's
length(from a function) and size(It is set to 32 or 16 bit depending on
the processor.). |