Re: oss emulation under alsa? (LONG)
Justin Guerin <jguerin@cso.atmel.com> wrote:
On Wednesday 13 April 2005 12:45, Marc Shapiro wrote:
I am runing Sarge with the stock debian kernel 2.6.7-1-k7 which has ALSA
sound built in. I am trying to run a Python program which was written
for OSS. How do I get ALSA to emulate OSS so that these, or other
programs written for OSS will run?
I have added the following to /etc/modutils/sndconfig:
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss
and then I ran update-modules and rebooted, but I still get an error
message saying:
Traceback (most recent call last):
File "./morse.py", line 151, in ?
main()
File "./morse.py", line 99, in main
dev = audiodev.AudioDev()
File "/usr/lib/python2.3/audiodev.py", line 229, in AudioDev
raise error, 'no audio device'
audiodev.error: no audio device
Do you have the module snd_pcm_oss loaded? That's the OSS emulation layer
for ALSA. If you're using udev, then /dev/dsp should be created when you
load the module. Let us know which, if either, of the above isn't
happening, and we'll go from there.
The module is loaded and /dev/dps is a symlink to /dev/dsp0. The output
of lsmod and 'ls /dev/dsp*' follows:
$ lsmod
Module Size Used by
ipv6 253024 10
lp 10948 0
ide_cd 43204 0
cdrom 39904 1 ide_cd
floppy 60308 0
tsdev 7360 0
mousedev 10444 2
psmouse 20232 0
evdev 9536 0
pcspkr 3688 0
rtc 12728 1
ehci_hcd 31300 0
ohci_hcd 21444 0
snd_intel8x0 36140 1
snd_ac97_codec 69572 1 snd_intel8x0
snd_pcm_oss 54312 0
snd_mixer_oss 19904 2 snd_pcm_oss
snd_pcm 97508 2 snd_intel8x0,snd_pcm_oss
snd_timer 25540 1 snd_pcm
snd_page_alloc 11720 2 snd_intel8x0,snd_pcm
gameport 4736 1 snd_intel8x0
snd_mpu401_uart 8000 1 snd_intel8x0
snd_rawmidi 25408 1 snd_mpu401_uart
snd_seq_device 8264 1 snd_rawmidi
snd 56932 9
snd_intel8x0,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device
soundcore 10400 2 snd
shpchp 101100 0
pciehp 97900 0
pci_hotplug 34352 2 shpchp,pciehp
sis_agp 8196 1
agpgart 33960 1 sis_agp
ext2 72296 2
capability 4616 0
commoncap 7232 1 capability
sis900 20292 0
crc32 4352 1 sis900
usbserial 29808 0
parport_pc 34944 1
parport 41544 2 lp,parport_pc
usb_storage 67904 0
usbkbd 7424 0
usbcore 113952 7
ehci_hcd,ohci_hcd,usbserial,usb_storage,usbkbd
ext3 126760 5
jbd 61592 1 ext3
mbcache 9220 2 ext2,ext3
ide_disk 19264 9
ide_generic 1472 0
sis5513 16776 1
ide_core 141592 5
ide_cd,usb_storage,ide_disk,ide_generic,sis5513
sd_mod 21696 0
ata_piix 8004 0
libata 41412 1 ata_piix
scsi_mod 124556 3 usb_storage,sd_mod,libata
unix 28528 130
font 8448 0
vesafb 6688 0
cfbcopyarea 3776 1 vesafb
cfbimgblt 3072 1 vesafb
cfbfillrect 3712 1 vesafb
$ ls /dev/dsp*
lrwxrwxrwx 1 root root 9 Jul 12 2004 /dev/dsp ->
/dev/dsp0
crw-rw---- 1 root audio 14, 3 Jul 12 2004 /dev/dsp0
crw-rw---- 1 root audio 14, 19 Jul 12 2004 /dev/dsp1
crw-rw---- 1 root audio 14, 35 Jul 12 2004 /dev/dsp2
crw-rw---- 1 root audio 14, 51 Jul 12 2004 /dev/dsp3
---------
Total: ( 1 Files) 65
As you can see from the following, I am listed as a member of the audio
group.
$ groups
mns disk dialout cdrom floppy audio lpadmin
Sound seems to be working perfectly, otherwise. The only problem I am
having is with this one Python script. Possibly the problem is with the
script, and not with my configuration. The script is one of the
Python2.3 demos, but maybe it has a problem. Does anyone know if there
is a problem with the audiodev.py module? Here is a copy of the
offending script:
$ cat morse.py
#! /usr/bin/python
# DAH should be three DOTs.
# Space between DOTs and DAHs should be one DOT.
# Space between two letters should be one DAH.
# Space between two words should be DOT DAH DAH.
import sys, math, audiodev
DOT = 30
DAH = 3 * DOT
OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ...
morsetab = {
'A': '.-', 'a': '.-',
'B': '-...', 'b': '-...',
'C': '-.-.', 'c': '-.-.',
'D': '-..', 'd': '-..',
'E': '.', 'e': '.',
'F': '..-.', 'f': '..-.',
'G': '--.', 'g': '--.',
'H': '....', 'h': '....',
'I': '..', 'i': '..',
'J': '.---', 'j': '.---',
'K': '-.-', 'k': '-.-',
'L': '.-..', 'l': '.-..',
'M': '--', 'm': '--',
'N': '-.', 'n': '-.',
'O': '---', 'o': '---',
'P': '.--.', 'p': '.--.',
'Q': '--.-', 'q': '--.-',
'R': '.-.', 'r': '.-.',
'S': '...', 's': '...',
'T': '-', 't': '-',
'U': '..-', 'u': '..-',
'V': '...-', 'v': '...-',
'W': '.--', 'w': '.--',
'X': '-..-', 'x': '-..-',
'Y': '-.--', 'y': '-.--',
'Z': '--..', 'z': '--..',
'0': '-----',
'1': '.----',
'2': '..---',
'3': '...--',
'4': '....-',
'5': '.....',
'6': '-....',
'7': '--...',
'8': '---..',
'9': '----.',
',': '--..--',
'.': '.-.-.-',
'?': '..--..',
';': '-.-.-.',
':': '---...',
"'": '.----.',
'-': '-....-',
'/': '-..-.',
'(': '-.--.-',
')': '-.--.-',
'_': '..--.-',
' ': ' '
}
# If we play at 44.1 kHz (which we do), then if we produce one sine
# wave in 100 samples, we get a tone of 441 Hz. If we produce two
# sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz
# appears to be a nice one for playing morse code.
def mkwave(octave):
global sinewave, nowave
sinewave = ''
for i in range(100):
val = int(math.sin(math.pi * float(i) * octave / 50.0)
* 30000) sinewave = sinewave + chr((val >> 8) & 255) +
chr(val & 255)
nowave = '\0' * 200
mkwave(OCTAVE)
def main():
import getopt, string
try:
opts, args = getopt.getopt(sys.argv[1:], 'o:p:')
except getopt.error:
sys.stderr.write('Usage ' + sys.argv[0] +
' [ -o outfile ] [ args ] ...\n')
sys.exit(1)
dev = None
for o, a in opts:
if o == '-o':
import aifc
dev = aifc.open(a, 'w')
dev.setframerate(44100)
dev.setsampwidth(2)
dev.setnchannels(1)
if o == '-p':
mkwave(string.atoi(a))
if not dev:
import audiodev
dev = audiodev.AudioDev()
dev.setoutrate(44100)
dev.setsampwidth(2)
dev.setnchannels(1)
dev.close = dev.stop
dev.writeframesraw = dev.writeframes
if args:
line = string.join(args)
else:
line = sys.stdin.readline()
while line:
mline = morse(line)
play(mline, dev)
if hasattr(dev, 'wait'):
dev.wait()
if not args:
line = sys.stdin.readline()
else:
line = ''
dev.close()
# Convert a string to morse code with \001 between the characters in
# the string.
def morse(line):
res = ''
for c in line:
try:
res = res + morsetab[c] + '\001'
except KeyError:
pass
return res
# Play a line of morse code.
def play(line, dev):
for c in line:
if c == '.':
sine(dev, DOT)
elif c == '-':
sine(dev, DAH)
else: # space
pause(dev, DAH + DOT)
pause(dev, DOT)
def sine(dev, length):
for i in range(length):
dev.writeframesraw(sinewave)
def pause(dev, length):
for i in range(length):
dev.writeframesraw(nowave)
if __name__ == '__main__' or sys.argv[0] == __name__:
main()
--
Marc Shapiro
mshapiro_42@yahoo.com
Reply to: