[pypy-svn] r64465 - pypy/trunk/pypy/rlib/rsdl
cami at codespeak.net
cami at codespeak.net
Mon Apr 20 17:48:24 CEST 2009
Author: cami
Date: Mon Apr 20 17:48:23 2009
New Revision: 64465
Added:
pypy/trunk/pypy/rlib/rsdl/RMix_helper.py
Modified:
pypy/trunk/pypy/rlib/rsdl/RMix.py
Log:
adding some sound helpers
Modified: pypy/trunk/pypy/rlib/rsdl/RMix.py
==============================================================================
--- pypy/trunk/pypy/rlib/rsdl/RMix.py (original)
+++ pypy/trunk/pypy/rlib/rsdl/RMix.py Mon Apr 20 17:48:23 2009
@@ -18,6 +18,8 @@
)
eci = eci.merge(RSDL.eci)
+eci = eci.merge(eci)
+eci = eci.merge(eci)
ChunkPtr = lltype.Ptr(lltype.ForwardReference())
@@ -33,25 +35,33 @@
ChunkPtr.TO.become(Chunk)
+
+Buffer = rffi.CArray(RSDL.Uint8)
+
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)
-
-CloseAudio = external('Mix_CloseAudio', [], lltype.Void)
-
-LoadWAV_RW = external('Mix_LoadWAV_RW',
- [RSDL.RWopsPtr, rffi.INT],
- ChunkPtr)
+OpenAudio = external('Mix_OpenAudio',
+ [rffi.INT, RSDL.Uint16, rffi.INT, rffi.INT],
+ rffi.INT)
+
+CloseAudio = external('Mix_CloseAudio', [], lltype.Void)
+
+LoadWAV_RW = external('Mix_LoadWAV_RW',
+ [RSDL.RWopsPtr, rffi.INT],
+ ChunkPtr)
def LoadWAV(filename_ccharp):
return LoadWAV_RW(RSDL.RWFromFile(filename_ccharp, rffi.str2charp('rb')), 1)
-PlayChannelTimed = external('Mix_PlayChannelTimed',
- [rffi.INT, ChunkPtr, rffi.INT, rffi.INT],
- rffi.INT)
+
+PlayChannelTimed = external('Mix_PlayChannelTimed',
+ [rffi.INT, ChunkPtr, rffi.INT, rffi.INT],
+ rffi.INT)
def PlayChannel(channel,chunk,loops):
return PlayChannelTimed(channel, chunk, loops, -1)
+
+"""Returns zero if the channel is not playing.
+Otherwise if you passed in -1, the number of channels playing is returned"""
+ChannelPlaying = external('Mix_Playing', [ rffi.INT])
\ No newline at end of file
Added: pypy/trunk/pypy/rlib/rsdl/RMix_helper.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/rlib/rsdl/RMix_helper.py Mon Apr 20 17:48:23 2009
@@ -0,0 +1,24 @@
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rlib.rsdl import RMix, RSDL
+from pypy.rpython.tool import rffi_platform as platform
+
+
+def malloc_buffer_chunk(has_own_allocated_buffer, length_bytes, volume):
+ buffer_pointer = lltype.malloc(RMix.Buffer, length_bytes, flavor='raw')
+ return malloc_chunk(has_own_allocated_buffer, length_bytes, volume)
+
+def malloc_chunk(has_own_allocated_buffer, buffer_pointer, length_bytes, volume):
+ """
+ Creates a new Mix_Chunk.
+ has_own_allocated_buffer: if 1 struct has its own allocated buffer,
+ if 0 abuf should not be freed
+ buffer_pointer: pointer to audio data
+ length_bytes: length of audio data in bytes
+ volume: Per-sample volume, 0-128 (normally
+ MIX_MAX_VOLUME after loading)"""
+ p = lltype.malloc(RMix.Chunk, flavor='raw')
+ rffi.setintfield(p, 'c_allocated', has_own_allocated_buffer)
+ rffi.setintfield(p, 'c_abuf', buffer_pointer)
+ rffi.setintfield(p, 'c_alen', length_bytes)
+ rffi.setintfield(p, 'c_volume', volume)
+ return p
\ No newline at end of file
More information about the Pypy-commit
mailing list