mirror of
https://github.com/larsimmisch/pyalsaaudio.git
synced 2026-05-24 15:15:31 +00:00
Make tests more robust, use devices or card indices.
This commit is contained in:
@@ -33,7 +33,7 @@ wish (even commercial purposes). There is no warranty whatsoever.
|
|||||||
currently fairly complete for PCM devices and Mixer access. MIDI sequencer
|
currently fairly complete for PCM devices and Mixer access. MIDI sequencer
|
||||||
support is low on our priority list, but volunteers are welcome.
|
support is low on our priority list, but volunteers are welcome.
|
||||||
|
|
||||||
If you find bugs in the wrappers please use the SourceForge bug tracker.
|
If you find bugs in the wrappers please use thegithub issue tracker.
|
||||||
Please don't send bug reports regarding ALSA specifically. There are several
|
Please don't send bug reports regarding ALSA specifically. There are several
|
||||||
bugs in this API, and those should be reported to the ALSA team - not me.
|
bugs in this API, and those should be reported to the ALSA team - not me.
|
||||||
|
|
||||||
|
|||||||
@@ -21,17 +21,17 @@ import getopt
|
|||||||
import alsaaudio
|
import alsaaudio
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print('usage: playbacktest.py [-c <card>] <file>', file=sys.stderr)
|
print('usage: playbacktest.py [-d <device>] <file>', file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
card = 'default'
|
device = 'default'
|
||||||
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'c:')
|
opts, args = getopt.getopt(sys.argv[1:], 'd:')
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-c':
|
if o == '-d':
|
||||||
card = a
|
device = a
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
@@ -39,7 +39,7 @@ if __name__ == '__main__':
|
|||||||
f = open(args[0], 'rb')
|
f = open(args[0], 'rb')
|
||||||
|
|
||||||
# Open the device in playback mode.
|
# Open the device in playback mode.
|
||||||
out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, card=card)
|
out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, device=device)
|
||||||
|
|
||||||
# Set attributes: Mono, 44100 Hz, 16 bit little endian frames
|
# Set attributes: Mono, 44100 Hz, 16 bit little endian frames
|
||||||
out.setchannels(1)
|
out.setchannels(1)
|
||||||
|
|||||||
12
playwav.py
12
playwav.py
@@ -40,23 +40,23 @@ def play(device, f):
|
|||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print('usage: playwav.py [-c <card>] <file>', file=sys.stderr)
|
print('usage: playwav.py [-d <device>] <file>', file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
card = 'default'
|
device = 'default'
|
||||||
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'c:')
|
opts, args = getopt.getopt(sys.argv[1:], 'd:')
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-c':
|
if o == '-d':
|
||||||
card = a
|
device = a
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
f = wave.open(args[0], 'rb')
|
f = wave.open(args[0], 'rb')
|
||||||
device = alsaaudio.PCM(card=card)
|
device = alsaaudio.PCM(device=device)
|
||||||
|
|
||||||
play(device, f)
|
play(device, f)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
##
|
##
|
||||||
## This is an example of a simple sound capture script.
|
## This is an example of a simple sound capture script.
|
||||||
##
|
##
|
||||||
## The script opens an ALSA pcm forsound capture. Set
|
## The script opens an ALSA pcm device for sound capture, sets
|
||||||
## various attributes of the capture, and reads in a loop,
|
## various attributes of the capture, and reads in a loop,
|
||||||
## writing the data to standard out.
|
## writing the data to standard out.
|
||||||
##
|
##
|
||||||
@@ -22,17 +22,17 @@ import getopt
|
|||||||
import alsaaudio
|
import alsaaudio
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print('usage: recordtest.py [-c <card>] <file>', file=sys.stderr)
|
print('usage: recordtest.py [-d <device>] <file>', file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
card = 'default'
|
device = 'default'
|
||||||
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'c:')
|
opts, args = getopt.getopt(sys.argv[1:], 'd:')
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-c':
|
if o == '-d':
|
||||||
card = a
|
device = a
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
@@ -42,7 +42,7 @@ if __name__ == '__main__':
|
|||||||
# Open the device in nonblocking capture mode. The last argument could
|
# Open the device in nonblocking capture mode. The last argument could
|
||||||
# just as well have been zero for blocking mode. Then we could have
|
# just as well have been zero for blocking mode. Then we could have
|
||||||
# left out the sleep call in the bottom of the loop
|
# left out the sleep call in the bottom of the loop
|
||||||
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card)
|
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, device=device)
|
||||||
|
|
||||||
# Set attributes: Mono, 44100 Hz, 16 bit little endian samples
|
# Set attributes: Mono, 44100 Hz, 16 bit little endian samples
|
||||||
inp.setchannels(1)
|
inp.setchannels(1)
|
||||||
|
|||||||
21
test.py
21
test.py
@@ -44,16 +44,11 @@ class MixerTest(unittest.TestCase):
|
|||||||
def testMixer(self):
|
def testMixer(self):
|
||||||
"""Open the default Mixers and the Mixers on every card"""
|
"""Open the default Mixers and the Mixers on every card"""
|
||||||
|
|
||||||
for d in ['default'] + list(range(len(alsaaudio.cards()))):
|
for c in alsaaudio.card_indexes():
|
||||||
if type(d) == type(0):
|
mixers = alsaaudio.mixers(cardindex=c)
|
||||||
kwargs = { 'cardindex': d }
|
|
||||||
else:
|
|
||||||
kwargs = { 'device': d }
|
|
||||||
|
|
||||||
mixers = alsaaudio.mixers(**kwargs)
|
|
||||||
|
|
||||||
for m in mixers:
|
for m in mixers:
|
||||||
mixer = alsaaudio.Mixer(m, **kwargs)
|
mixer = alsaaudio.Mixer(m, cardindex=c)
|
||||||
mixer.close()
|
mixer.close()
|
||||||
|
|
||||||
def testMixerAll(self):
|
def testMixerAll(self):
|
||||||
@@ -90,14 +85,10 @@ class PCMTest(unittest.TestCase):
|
|||||||
"""Test PCM objects"""
|
"""Test PCM objects"""
|
||||||
|
|
||||||
def testPCM(self):
|
def testPCM(self):
|
||||||
"Open a PCM object on every device"
|
"Open a PCM object on every card"
|
||||||
|
|
||||||
for pd in alsaaudio.pcms():
|
for c in alsaaudio.card_indexes():
|
||||||
pcm = alsaaudio.PCM(device=pd)
|
pcm = alsaaudio.PCM(cardindex=c)
|
||||||
pcm.close()
|
|
||||||
|
|
||||||
for pd in alsaaudio.pcms(alsaaudio.PCM_CAPTURE):
|
|
||||||
pcm = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, device=pd)
|
|
||||||
pcm.close()
|
pcm.close()
|
||||||
|
|
||||||
def testPCMAll(self):
|
def testPCMAll(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user