Marcus von Appen avatar Marcus von Appen committed 12e1f82

- moved loaders into own package
- only add the user-specified path for DLL loading to %PATH%, if the DLL could
be loaded successfully

Comments (0)

Files changed (6)

 SUBDIRS = \
 	$(top_srcdir)/doc \
 	$(top_srcdir)/openal \
+	$(top_srcdir)/openal/loaders \
 	$(top_srcdir)/openal/test \
 	$(top_srcdir)/openal/test/util \
 	$(top_srcdir)/examples

openal/__init__.py

 
 __all__ = ["get_dll_file", "version_info"]
 
+
 def _findlib(libnames, path=None):
     """Internal helper function to find the requested DLL(s)."""
     platform = sys.platform
                 warnings.warn(exc, ImportWarning)
         if self._dll is None:
             raise RuntimeError("could not load any library for %s" % libinfo)
+        if path is not None and sys.platform in ("win32", "cli") and \
+            path in self._libfile:
+            os.environ["PATH"] += ";%s" % path
 
     def bind_function(self, funcname, args=None, returns=None):
         """Binds the passed argument and return value types to the specified
         self.frequency = frequency
         self.data = data
         if dformat is None:
-            formatmap = {(1, 8) : al.AL_FORMAT_MONO8,
-                         (2, 8) : al.AL_FORMAT_STEREO8,
+            formatmap = {(1, 8): al.AL_FORMAT_MONO8,
+                         (2, 8): al.AL_FORMAT_STEREO8,
                          (1, 16): al.AL_FORMAT_MONO16,
-                         (2, 16) : al.AL_FORMAT_STEREO16
+                         (2, 16): al.AL_FORMAT_STEREO16
                          }
             dformat = formatmap.get((channels, bitrate), None)
         self.format = dformat
         self.dataproperties[al.AL_POSITION] = position
         self.dataproperties[al.AL_VELOCITY] = velocity
         self.dataproperties[al.AL_ORIENTATION] = orientation
-        self.changedproperties = [al.AL_POSITION, al.AL_VELOCITY, al.AL_ORIENTATION]
+        self.changedproperties = [al.AL_POSITION, al.AL_VELOCITY,
+                                  al.AL_ORIENTATION]
 
     def __getattr__(self, name):
         if name in ("dataproperties", "changedproperties"):
         self.dataproperties[al.AL_PITCH] = pitch
         self.dataproperties[al.AL_POSITION] = position
         self.dataproperties[al.AL_VELOCITY] = velocity
-        self.changedproperties = [al.AL_GAIN, al.AL_PITCH, al.AL_POSITION, al.AL_VELOCITY]
+        self.changedproperties = [al.AL_GAIN, al.AL_PITCH, al.AL_POSITION,
+                                  al.AL_VELOCITY]
 
     def __getattr__(self, name):
         if name in ("dataproperties", "changedproperties", "bufferqueue"):
             state = al.ALint()
             al.alGetSourcei(sid, al.AL_SOURCE_STATE, ctypes.byref(state))
             if state not in (al.AL_PAUSED, al.AL_PLAYING):
-                al.alBufferData(bufid, data.format, bufdata, bufsize, data.frequency)
+                al.alBufferData(bufid, data.format, bufdata, bufsize,
+                                data.frequency)
                 _continue_or_raise()
                 al.alSourceQueueBuffers(sid, 1, bufid)
                 _continue_or_raise()

openal/loaders.py

-"""Utility functions for loading sounds."""
-import os
-import wave
-from .audio import SoundData
-
-__all__ = ["load_wav_file", "load_file"]
-
-def load_wav_file(fname):
-    """Loads a WAV encoded audio file into a SoundData object."""
-    fp = wave.open(fname, "rb")
-    channels = fp.getnchannels()
-    bitrate = fp.getsampwidth() * 8
-    samplerate = fp.getframerate()
-    buf = fp.readframes(fp.getnframes())
-    return SoundData(buf, channels, bitrate, len(buf), samplerate)
-
-
-# supported extensions
-_EXTENSIONS = {".wav": load_wav_file}
-
-
-#try:
-#    from ..ogg import vorbisfile as vorbis
-#
-#    @experimental
-#    def load_ogg_file(fname):
-#        """Loads an Ogg-Vorbis encoded audio file into a SoundData object."""
-#        fp = vorbis.fopen(fname)
-#        finfo = vorbis.info(fp)
-#        length = vorbis.pcm_total(fp)
-#        buf = vorbis.read(fp, length, word=2)[0]
-#        return SoundData(buf, finfo.channels, 16, length, finfo.rate)
-#
-#    _EXTENSIONS[".ogg"] = load_ogg_file
-#
-#except ImportError:
-#    pass
-
-
-def load_file(fname):
-    """Loads an audio file into a SoundData object."""
-    ext = os.path.splitext(fname)[1].lower()
-    funcptr = _EXTENSIONS.get(ext, None)
-    if not funcptr:
-        raise ValueError("unsupported audio file type")
-    return funcptr(fname)
-
-
-def load_stream(source):
-    """Loads an audio stream into a SoundData object."""
-    raise NotImplementedError("not implemented yet")
-

openal/loaders/__init__.py

+"""Utility functions for loading sounds."""
+import os
+import sys
+import wave
+from ..audio import SoundData
+
+
+__all__ = ["load_wav_file", "load_file"]
+
+
+def load_wav_file(fname):
+    """Loads a WAV encoded audio file into a SoundData object."""
+    fp = wave.open(fname, "rb")
+    channels = fp.getnchannels()
+    bitrate = fp.getsampwidth() * 8
+    samplerate = fp.getframerate()
+    buf = fp.readframes(fp.getnframes())
+    return SoundData(buf, channels, bitrate, len(buf), samplerate)
+
+
+# supported extensions
+_FILEEXTENSIONS = {".wav": load_wav_file}
+
+
+def load_file(fname):
+    """Loads an audio file into a SoundData object."""
+    ext = os.path.splitext(fname)[1].lower()
+    funcptr = _FILEEXTENSIONS.get(ext, None)
+    if not funcptr:
+        raise ValueError("unsupported audio file type")
+    return funcptr(fname)
+
+
+def load_stream(source):
+    """Loads an audio stream into a SoundData object."""
+    raise NotImplementedError("not implemented yet")

openal/test/loaders_test.py

 
 RESPATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources")
 
+
 class OpenALAudioTest(unittest.TestCase):
 
     def test_load_file(self):
         self.assertEqual(snddata.size, 122880)
 
     @unittest.skip("not implemented")
-    def test_load_ogg_file(self):
-        pass
-        #oggfile = os.path.join(RESPATH, "hey.ogg")
-        #snddata = loaders.load_ogg_file(oggfile)
-
-    @unittest.skip("not implemented")
     def test_load_stream(self):
         pass
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.