/pypy/rlib/rsdl/RMix.py

https://github.com/ssadler/pypy
Python | 68 lines | 47 code | 19 blank | 2 comment | 3 complexity | db09c645b07d31d0eca21a9d67773df0 MD5 | raw file
  1. import sys
  2. from pypy.rpython.lltypesystem import lltype, rffi
  3. from pypy.rpython.tool import rffi_platform as platform
  4. from pypy.translator.tool.cbuild import ExternalCompilationInfo
  5. from pypy.rlib.rsdl import RSDL
  6. if sys.platform == 'darwin':
  7. eci = ExternalCompilationInfo(
  8. includes = ['SDL_mixer.h'],
  9. frameworks = ['SDL_mixer'],
  10. include_dirs = ['/Library/Frameworks/SDL_Mixer.framework/Headers']
  11. )
  12. else:
  13. eci = ExternalCompilationInfo(
  14. includes=['SDL_mixer.h'],
  15. libraries=['SDL_mixer'],
  16. )
  17. eci = eci.merge(RSDL.eci)
  18. eci = eci.merge(eci)
  19. eci = eci.merge(eci)
  20. ChunkPtr = lltype.Ptr(lltype.ForwardReference())
  21. class CConfig:
  22. _compilation_info_ = eci
  23. Chunk = platform.Struct('Mix_Chunk', [('allocated', rffi.INT),
  24. ('abuf', RSDL.Uint8P),
  25. ('alen', RSDL.Uint32),
  26. ('volume', RSDL.Uint8)])
  27. globals().update(platform.configure(CConfig))
  28. ChunkPtr.TO.become(Chunk)
  29. Buffer = rffi.CArray(RSDL.Uint8)
  30. def external(name, args, result):
  31. return rffi.llexternal(name, args, result, compilation_info=eci)
  32. OpenAudio = external('Mix_OpenAudio',
  33. [rffi.INT, RSDL.Uint16, rffi.INT, rffi.INT],
  34. rffi.INT)
  35. CloseAudio = external('Mix_CloseAudio', [], lltype.Void)
  36. LoadWAV_RW = external('Mix_LoadWAV_RW',
  37. [RSDL.RWopsPtr, rffi.INT],
  38. ChunkPtr)
  39. def LoadWAV(filename_ccharp):
  40. with rffi.scoped_str2charp('rb') as mode:
  41. return LoadWAV_RW(RSDL.RWFromFile(filename_ccharp, mode), 1)
  42. PlayChannelTimed = external('Mix_PlayChannelTimed',
  43. [rffi.INT, ChunkPtr, rffi.INT, rffi.INT],
  44. rffi.INT)
  45. def PlayChannel(channel,chunk,loops):
  46. return PlayChannelTimed(channel, chunk, loops, -1)
  47. """Returns zero if the channel is not playing.
  48. Otherwise if you passed in -1, the number of channels playing is returned"""
  49. ChannelPlaying = external('Mix_Playing', [rffi.INT], rffi.INT)