By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

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

P: 16
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
Share this Question
Share on Google+
1 Reply


P: 9
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.