469,290 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

how to convert pymedia.audio.acodec ACString to ctypes.c_char_p

Hello All Experts,

I am quite new to Ctypes. I am using one c library and writing python
bindings for it.
I need to pass a character pointer to one function.

I am reading one mp3 file and decoding it to raw pcm using pymedia.
Now I need to pass this raw data in to a
C function. Here is my code.

Expand|Select|Wrap|Line Numbers
  1. # /*********
  2. from ctypes import *
  3. import pymedia.audio.acodec as codec
  4.  
  5. dec = None
  6. dm = muxer.Demuxer('mp3')
  7. fp = open('test.mp3', 'rb')
  8. fingerprinting_done = False
  9.  
  10. while  not fingerprinting_done:
  11.     s = fp.read(20000)
  12.     frames = dm.parse(s)
  13.  
  14.     for fr in frames:
  15.         if dec == None:
  16.             dec = codec.Decoder(dm.streams[0])
  17.  
  18.          r = dec.Decode(fr[1])
  19.  
  20.          if r and r.data:
  21.               # pass this r.data to the C function.
  22.               # r.data is ACString object
  23.               # I cannot do pcm_audio = c_char_p(r.data) . gives me  following error
  24.               # TypeError: string or integer address expected instead  of ACString   
  25.               # instance
  26.  
  27. # *************/
I am getting error while converting r.data (which is ACstring object)
in to ctypes.c_char_p.
can you help me solving this problem?

any help would be appericiated,
Thank you,
sanket
Dec 19 '08 #1
1 2868
try this line instead

Expand|Select|Wrap|Line Numbers
  1. pcm_audio = ctypes.py_object(r.data)
hope it helps :)
Jan 11 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by CptPicard | last post: by
1 post views Thread by Dmitry Borisov | last post: by
1 post views Thread by Dmitry Borisov | last post: by
1 post views Thread by Ron Provost | last post: by
1 post views Thread by sjdevnull | last post: by
3 posts views Thread by Chris AtLee | last post: by
reply views Thread by Carlos Leite | last post: by
6 posts views Thread by Jack | last post: by
2 posts views Thread by Sells, Fred | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.