mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
* added support ossaudiodev
git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@61 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
parent
58704aa73a
commit
55d12b8842
3 changed files with 85 additions and 4 deletions
|
@ -878,10 +878,10 @@ class Game:
|
||||||
#
|
#
|
||||||
|
|
||||||
def playSample(self, name, priority=0, loop=0):
|
def playSample(self, name, priority=0, loop=0):
|
||||||
|
##print "Game.playSample:", name, priority, loop
|
||||||
if self.app.opt.sound_samples.has_key(name) and \
|
if self.app.opt.sound_samples.has_key(name) and \
|
||||||
not self.app.opt.sound_samples[name]:
|
not self.app.opt.sound_samples[name]:
|
||||||
return 0
|
return 0
|
||||||
##print "playSample:", name, priority, loop
|
|
||||||
if self.app.audio:
|
if self.app.audio:
|
||||||
return self.app.audio.playSample(name, priority=priority, loop=loop)
|
return self.app.audio.playSample(name, priority=priority, loop=loop)
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -48,7 +48,7 @@ from resource import Tile
|
||||||
from gamedb import GI
|
from gamedb import GI
|
||||||
from app import Application
|
from app import Application
|
||||||
from pysolaudio import thread, pysolsoundserver
|
from pysolaudio import thread, pysolsoundserver
|
||||||
from pysolaudio import AbstractAudioClient, PysolSoundServerModuleClient, Win32AudioClient
|
from pysolaudio import AbstractAudioClient, PysolSoundServerModuleClient, Win32AudioClient, OSSAudioClient
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from pysoltk import tkversion, wm_withdraw, wm_set_icon, loadImage
|
from pysoltk import tkversion, wm_withdraw, wm_set_icon, loadImage
|
||||||
|
@ -243,6 +243,8 @@ def pysol_init(app, args):
|
||||||
app.audio = PysolSoundServerModuleClient()
|
app.audio = PysolSoundServerModuleClient()
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
app.audio = Win32AudioClient()
|
app.audio = Win32AudioClient()
|
||||||
|
elif os.name == 'posix':
|
||||||
|
app.audio = OSSAudioClient()
|
||||||
if app.audio:
|
if app.audio:
|
||||||
app.audio.startServer()
|
app.audio.startServer()
|
||||||
if app.audio.server is None:
|
if app.audio.server is None:
|
||||||
|
@ -418,7 +420,8 @@ Please check your %s installation.
|
||||||
app.wm_withdraw()
|
app.wm_withdraw()
|
||||||
|
|
||||||
# warn about audio problems
|
# warn about audio problems
|
||||||
if not opts["nosound"] and os.name == "posix" and pysolsoundserver is None:
|
if (not opts["nosound"] and os.name == "posix" and
|
||||||
|
not app.audio and pysolsoundserver is None):
|
||||||
if 1 and app.opt.sound and re.search(r"linux", sys.platform, re.I):
|
if 1 and app.opt.sound and re.search(r"linux", sys.platform, re.I):
|
||||||
warn_pysolsoundserver = 1
|
warn_pysolsoundserver = 1
|
||||||
if thread is None:
|
if thread is None:
|
||||||
|
|
|
@ -39,6 +39,8 @@ import os, re, string, sys, time, types
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import thread
|
import thread
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pysolsoundserver
|
import pysolsoundserver
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -101,6 +103,7 @@ class AbstractAudioClient:
|
||||||
self.stopMusic()
|
self.stopMusic()
|
||||||
|
|
||||||
def playSample(self, name, priority=0, loop=0, volume=-1):
|
def playSample(self, name, priority=0, loop=0, volume=-1):
|
||||||
|
##print 'AbstractAudioClient.playSample', name
|
||||||
if self.audiodev is None or not self.app or not self.app.opt.sound:
|
if self.audiodev is None or not self.app or not self.app.opt.sound:
|
||||||
return 0
|
return 0
|
||||||
if priority <= self.sample_priority and self.sample_loop:
|
if priority <= self.sample_priority and self.sample_loop:
|
||||||
|
@ -301,7 +304,7 @@ class Win32AudioClient(AbstractAudioClient):
|
||||||
def startServer(self):
|
def startServer(self):
|
||||||
# use the built-in winsound module
|
# use the built-in winsound module
|
||||||
try:
|
try:
|
||||||
import winsound #keep#
|
import winsound
|
||||||
self.audiodev = winsound
|
self.audiodev = winsound
|
||||||
del winsound
|
del winsound
|
||||||
self.server = 0 # success - see also tk/menubar.py
|
self.server = 0 # success - see also tk/menubar.py
|
||||||
|
@ -329,3 +332,78 @@ class Win32AudioClient(AbstractAudioClient):
|
||||||
a.PlaySound(None, flags)
|
a.PlaySound(None, flags)
|
||||||
|
|
||||||
|
|
||||||
|
# /***********************************************************************
|
||||||
|
# // OSS audio
|
||||||
|
# ************************************************************************/
|
||||||
|
|
||||||
|
class OSSAudioClient(AbstractAudioClient):
|
||||||
|
|
||||||
|
def startServer(self):
|
||||||
|
try:
|
||||||
|
import ossaudiodev, wave
|
||||||
|
self.server = 0 # success - see also tk/menubar.py
|
||||||
|
self.audiodev = ossaudiodev #.open('w')
|
||||||
|
except:
|
||||||
|
if traceback: traceback.print_exc()
|
||||||
|
self.server = None
|
||||||
|
self.audiodev = None
|
||||||
|
|
||||||
|
|
||||||
|
def _playSample(self, filename, priority, loop, volume):
|
||||||
|
##print '_playSample:', filename, loop
|
||||||
|
if loop:
|
||||||
|
self._play_loop = True
|
||||||
|
th = Thread(target=self._playLoop, args=(filename, priority))
|
||||||
|
th.start()
|
||||||
|
return 1
|
||||||
|
th = Thread(target=self._play, args=(filename, priority))
|
||||||
|
th.start()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def _playLoop(self, filename, priority):
|
||||||
|
##print '_playLoop:', filename
|
||||||
|
try:
|
||||||
|
import ossaudiodev, wave
|
||||||
|
#audiodev = self.audiodev
|
||||||
|
audiodev = ossaudiodev.open('w')
|
||||||
|
w = wave.open(filename)
|
||||||
|
fmt = ossaudiodev.AFMT_U8
|
||||||
|
#fmt = ossaudiodev.AFMT_S8
|
||||||
|
nch = w.getnchannels()
|
||||||
|
rate = w.getframerate()
|
||||||
|
frames = w.readframes(w.getnframes())
|
||||||
|
#audiodev.nonblock()
|
||||||
|
audiodev.setparameters(fmt, nch, rate)
|
||||||
|
while self._play_loop:
|
||||||
|
audiodev.write(frames)
|
||||||
|
audiodev.reset()
|
||||||
|
audiodev.close()
|
||||||
|
#self.audiodev = ossaudiodev.open('w')
|
||||||
|
return 1
|
||||||
|
except:
|
||||||
|
if traceback: traceback.print_exc()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _play(self, filename, priority):
|
||||||
|
##print '_play:', filename
|
||||||
|
try:
|
||||||
|
import ossaudiodev, wave
|
||||||
|
#audiodev = self.audiodev
|
||||||
|
audiodev = ossaudiodev.open('w')
|
||||||
|
audiodev.nonblock()
|
||||||
|
w = wave.open(filename)
|
||||||
|
fmt = ossaudiodev.AFMT_U8
|
||||||
|
#fmt = ossaudiodev.AFMT_S8
|
||||||
|
nch = w.getnchannels()
|
||||||
|
rate = w.getframerate()
|
||||||
|
frames = w.readframes(w.getnframes())
|
||||||
|
audiodev.setparameters(fmt, nch, rate)
|
||||||
|
audiodev.write(frames)
|
||||||
|
return 1
|
||||||
|
except:
|
||||||
|
if traceback: traceback.print_exc()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _stopSamples(self):
|
||||||
|
self._play_loop = False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue