From dc51fa75b5f35eaf66f241deb588ebaca1f165a4 Mon Sep 17 00:00:00 2001 From: Lars Immisch Date: Wed, 22 Feb 2017 23:55:17 +0100 Subject: [PATCH] Make tests more robust, use devices or card indices. --- doc/pyalsaaudio.rst | 2 +- playbacktest.py | 12 ++++++------ playwav.py | 12 ++++++------ recordtest.py | 14 +++++++------- test.py | 21 ++++++--------------- 5 files changed, 26 insertions(+), 35 deletions(-) diff --git a/doc/pyalsaaudio.rst b/doc/pyalsaaudio.rst index 136429d..f3cb6c2 100644 --- a/doc/pyalsaaudio.rst +++ b/doc/pyalsaaudio.rst @@ -33,7 +33,7 @@ wish (even commercial purposes). There is no warranty whatsoever. currently fairly complete for PCM devices and Mixer access. MIDI sequencer 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 bugs in this API, and those should be reported to the ALSA team - not me. diff --git a/playbacktest.py b/playbacktest.py index 8d1f012..592ee92 100755 --- a/playbacktest.py +++ b/playbacktest.py @@ -21,17 +21,17 @@ import getopt import alsaaudio def usage(): - print('usage: playbacktest.py [-c ] ', file=sys.stderr) + print('usage: playbacktest.py [-d ] ', file=sys.stderr) sys.exit(2) 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: - if o == '-c': - card = a + if o == '-d': + device = a if not args: usage() @@ -39,7 +39,7 @@ if __name__ == '__main__': f = open(args[0], 'rb') # 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 out.setchannels(1) diff --git a/playwav.py b/playwav.py index b456494..cdf92b3 100755 --- a/playwav.py +++ b/playwav.py @@ -40,23 +40,23 @@ def play(device, f): def usage(): - print('usage: playwav.py [-c ] ', file=sys.stderr) + print('usage: playwav.py [-d ] ', file=sys.stderr) sys.exit(2) 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: - if o == '-c': - card = a + if o == '-d': + device = a if not args: usage() f = wave.open(args[0], 'rb') - device = alsaaudio.PCM(card=card) + device = alsaaudio.PCM(device=device) play(device, f) diff --git a/recordtest.py b/recordtest.py index e12d6cf..a4ed94f 100755 --- a/recordtest.py +++ b/recordtest.py @@ -4,7 +4,7 @@ ## ## 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, ## writing the data to standard out. ## @@ -22,17 +22,17 @@ import getopt import alsaaudio def usage(): - print('usage: recordtest.py [-c ] ', file=sys.stderr) + print('usage: recordtest.py [-d ] ', file=sys.stderr) sys.exit(2) 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: - if o == '-c': - card = a + if o == '-d': + device = a if not args: usage() @@ -42,7 +42,7 @@ if __name__ == '__main__': # Open the device in nonblocking capture mode. The last argument could # just as well have been zero for blocking mode. Then we could have # 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 inp.setchannels(1) diff --git a/test.py b/test.py index 0aa450d..c5f61f0 100755 --- a/test.py +++ b/test.py @@ -44,16 +44,11 @@ class MixerTest(unittest.TestCase): def testMixer(self): """Open the default Mixers and the Mixers on every card""" - for d in ['default'] + list(range(len(alsaaudio.cards()))): - if type(d) == type(0): - kwargs = { 'cardindex': d } - else: - kwargs = { 'device': d } - - mixers = alsaaudio.mixers(**kwargs) + for c in alsaaudio.card_indexes(): + mixers = alsaaudio.mixers(cardindex=c) for m in mixers: - mixer = alsaaudio.Mixer(m, **kwargs) + mixer = alsaaudio.Mixer(m, cardindex=c) mixer.close() def testMixerAll(self): @@ -90,14 +85,10 @@ class PCMTest(unittest.TestCase): """Test PCM objects""" def testPCM(self): - "Open a PCM object on every device" + "Open a PCM object on every card" - for pd in alsaaudio.pcms(): - pcm = alsaaudio.PCM(device=pd) - pcm.close() - - for pd in alsaaudio.pcms(alsaaudio.PCM_CAPTURE): - pcm = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, device=pd) + for c in alsaaudio.card_indexes(): + pcm = alsaaudio.PCM(cardindex=c) pcm.close() def testPCMAll(self):