[pypy-svn] r55079 - in pypy/dist/pypy/rlib/rsdl: . test

karlb at codespeak.net karlb at codespeak.net
Wed May 21 19:32:49 CEST 2008


Author: karlb
Date: Wed May 21 19:32:44 2008
New Revision: 55079

Modified:
   pypy/dist/pypy/rlib/rsdl/RMix.py
   pypy/dist/pypy/rlib/rsdl/RSDL.py
   pypy/dist/pypy/rlib/rsdl/test/test_sdl_mixer.py
Log:
Added support for LoadWAV to RMix


Modified: pypy/dist/pypy/rlib/rsdl/RMix.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/RMix.py	(original)
+++ pypy/dist/pypy/rlib/rsdl/RMix.py	Wed May 21 19:32:44 2008
@@ -2,16 +2,47 @@
 from pypy.rpython.tool import rffi_platform as platform
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rlib.rsdl import RSDL
+import sys
 
-eci = ExternalCompilationInfo(
-    includes=['SDL_mixer.h'],
-    libraries=['SDL_mixer'],
+if sys.platform == 'darwin':
+    eci = ExternalCompilationInfo(
+        includes = ['SDL_mixer.h'],
+        frameworks = ['SDL_mixer'],
+        include_dirs = ['/Library/Frameworks/SDL_Mixer.framework/Versions/A/Headers']
     )
+else:
+    eci = ExternalCompilationInfo(
+        includes=['SDL_mixer.h'],
+        libraries=['SDL_mixer'],
+    )
+
 eci = eci.merge(RSDL.eci)
 
+ChunkPtr             = lltype.Ptr(lltype.ForwardReference())
+
+class CConfig:
+    _compilation_info_ = eci
+
+    Chunk              = platform.Struct('Mix_Chunk', [])
+
+globals().update(platform.configure(CConfig))
+
+ChunkPtr.TO.become(Chunk)
+
 def external(name, args, result):
     return rffi.llexternal(name, args, result, compilation_info=eci)
 
 OpenAudio = external('Mix_OpenAudio',
-                [rffi.INT, RSDL.Uint16, rffi.INT, rffi.INT],
-                rffi.INT)
+                     [rffi.INT, RSDL.Uint16, rffi.INT, rffi.INT],
+                     rffi.INT)
+
+CloseAudio = external('Mix_CloseAudio', [], lltype.Void)
+
+_LoadWAV   = external('Mix_LoadWAV_RW',
+                     [RSDL.RWopsPtr, rffi.INT],
+                     ChunkPtr)
+
+def LoadWAV(filename_ccharp):
+    _LoadWAV(RSDL.RWFromFile(filename_ccharp, rffi.str2charp('rb')), 1)
+
+

Modified: pypy/dist/pypy/rlib/rsdl/RSDL.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/RSDL.py	(original)
+++ pypy/dist/pypy/rlib/rsdl/RSDL.py	Wed May 21 19:32:44 2008
@@ -44,6 +44,7 @@
 MouseButtonEventPtr = lltype.Ptr(lltype.ForwardReference())
 MouseMotionEventPtr = lltype.Ptr(lltype.ForwardReference())
 KeyPtr              = lltype.Ptr(lltype.ForwardReference())
+RWopsPtr            = lltype.Ptr(lltype.ForwardReference())
 
 # ------------------------------------------------------------------------------
 
@@ -105,6 +106,7 @@
                                      ('xrel', rffi.INT),
                                      ('yrel', rffi.INT)])
     
+    RWops = platform.Struct('SDL_RWops', [])
 
 # ------------------------------------------------------------------------------
 
@@ -125,6 +127,7 @@
 KeyboardEventPtr.TO.become(KeyboardEvent)
 MouseButtonEventPtr.TO.become(MouseButtonEvent)
 MouseMotionEventPtr.TO.become(MouseMotionEvent)
+RWopsPtr.TO.become(RWops)
 
 # ------------------------------------------------------------------------------
 
@@ -238,6 +241,10 @@
                             [],
                             rffi.CCHARP)
 
+RWFromFile       = external('SDL_RWFromFile',
+                            [rffi.CCHARP, rffi.CCHARP],
+                            RWopsPtr)
+
 # ------------------------------------------------------------------------------
 
 

Modified: pypy/dist/pypy/rlib/rsdl/test/test_sdl_mixer.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/test/test_sdl_mixer.py	(original)
+++ pypy/dist/pypy/rlib/rsdl/test/test_sdl_mixer.py	Wed May 21 19:32:44 2008
@@ -7,3 +7,13 @@
     if RMix.OpenAudio(22050, RSDL.AUDIO_S16LSB, 2, 1024) != 0:
         error = rffi.charp2str(RSDL.GetError())
         raise Exception(error)
+    RMix.CloseAudio()
+
+def test_load_wav():
+    if RMix.OpenAudio(22050, RSDL.AUDIO_S16LSB, 2, 1024) != 0:
+        error = rffi.charp2str(RSDL.GetError())
+        raise Exception(error)
+    filename = rffi.str2charp('test.wav')
+    RMix.LoadWAV(filename)
+    rffi.free_charp(filename)
+    RMix.CloseAudio()



More information about the Pypy-commit mailing list