Back to index

python3.2  3.2.2
Public Member Functions
test.test_ossaudiodev.OSSAudioDevTests Class Reference

List of all members.

Public Member Functions

def play_sound_file
def set_parameters
def set_bad_parameters
def test_playback
def test_set_parameters
def test_mixer_methods
def test_with

Detailed Description

Definition at line 42 of file test_ossaudiodev.py.


Member Function Documentation

def test.test_ossaudiodev.OSSAudioDevTests.play_sound_file (   self,
  data,
  rate,
  ssize,
  nchannels 
)

Definition at line 44 of file test_ossaudiodev.py.

00044 
00045     def play_sound_file(self, data, rate, ssize, nchannels):
00046         try:
00047             dsp = ossaudiodev.open('w')
00048         except IOError as msg:
00049             if msg.args[0] in (errno.EACCES, errno.ENOENT,
00050                                errno.ENODEV, errno.EBUSY):
00051                 raise unittest.SkipTest(msg)
00052             raise
00053 
00054         # at least check that these methods can be invoked
00055         dsp.bufsize()
00056         dsp.obufcount()
00057         dsp.obuffree()
00058         dsp.getptr()
00059         dsp.fileno()
00060 
00061         # Make sure the read-only attributes work.
00062         self.assertFalse(dsp.closed)
00063         self.assertEqual(dsp.name, "/dev/dsp")
00064         self.assertEqual(dsp.mode, "w", "bad dsp.mode: %r" % dsp.mode)
00065 
00066         # And make sure they're really read-only.
00067         for attr in ('closed', 'name', 'mode'):
00068             try:
00069                 setattr(dsp, attr, 42)
00070             except (TypeError, AttributeError):
00071                 pass
00072             else:
00073                 self.fail("dsp.%s not read-only" % attr)
00074 
00075         # Compute expected running time of sound sample (in seconds).
00076         expected_time = float(len(data)) / (ssize/8) / nchannels / rate
00077 
00078         # set parameters based on .au file headers
00079         dsp.setparameters(AFMT_S16_NE, nchannels, rate)
00080         self.assertTrue(abs(expected_time - 3.51) < 1e-2, expected_time)
00081         t1 = time.time()
00082         dsp.write(data)
00083         dsp.close()
00084         t2 = time.time()
00085         elapsed_time = t2 - t1
00086 
00087         percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100
00088         self.assertTrue(percent_diff <= 10.0,
00089                         "elapsed time (%s) > 10%% off of expected time (%s)" %
00090                         (elapsed_time, expected_time))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 121 of file test_ossaudiodev.py.

00121 
00122     def set_bad_parameters(self, dsp):
00123         # Now try some configurations that are presumably bogus: eg. 300
00124         # channels currently exceeds even Hollywood's ambitions, and
00125         # negative sampling rate is utter nonsense.  setparameters() should
00126         # accept these in non-strict mode, returning something other than
00127         # was requested, but should barf in strict mode.
00128         fmt = AFMT_S16_NE
00129         rate = 44100
00130         channels = 2
00131         for config in [(fmt, 300, rate),       # ridiculous nchannels
00132                        (fmt, -5, rate),        # impossible nchannels
00133                        (fmt, channels, -50),   # impossible rate
00134                       ]:
00135             (fmt, channels, rate) = config
00136             result = dsp.setparameters(fmt, channels, rate, False)
00137             self.assertNotEqual(result, config,
00138                              "unexpectedly got requested configuration")
00139 
00140             try:
00141                 result = dsp.setparameters(fmt, channels, rate, True)
00142             except ossaudiodev.OSSAudioError as err:
00143                 pass
00144             else:
00145                 self.fail("expected OSSAudioError")

Here is the call graph for this function:

Definition at line 91 of file test_ossaudiodev.py.

00091 
00092     def set_parameters(self, dsp):
00093         # Two configurations for testing:
00094         #   config1 (8-bit, mono, 8 kHz) should work on even the most
00095         #      ancient and crufty sound card, but maybe not on special-
00096         #      purpose high-end hardware
00097         #   config2 (16-bit, stereo, 44.1kHz) should work on all but the
00098         #      most ancient and crufty hardware
00099         config1 = (ossaudiodev.AFMT_U8, 1, 8000)
00100         config2 = (AFMT_S16_NE, 2, 44100)
00101 
00102         for config in [config1, config2]:
00103             (fmt, channels, rate) = config
00104             if (dsp.setfmt(fmt) == fmt and
00105                 dsp.channels(channels) == channels and
00106                 dsp.speed(rate) == rate):
00107                 break
00108         else:
00109             raise RuntimeError("unable to set audio sampling parameters: "
00110                                "you must have really weird audio hardware")
00111 
00112         # setparameters() should be able to set this configuration in
00113         # either strict or non-strict mode.
00114         result = dsp.setparameters(fmt, channels, rate, False)
00115         self.assertEqual(result, (fmt, channels, rate),
00116                          "setparameters%r: returned %r" % (config, result))
00117 
00118         result = dsp.setparameters(fmt, channels, rate, True)
00119         self.assertEqual(result, (fmt, channels, rate),
00120                          "setparameters%r: returned %r" % (config, result))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 162 of file test_ossaudiodev.py.

00162 
00163     def test_mixer_methods(self):
00164         # Issue #8139: ossaudiodev didn't initialize its types properly,
00165         # therefore some methods were unavailable.
00166         with ossaudiodev.openmixer() as mixer:
00167             self.assertGreaterEqual(mixer.fileno(), 0)

Here is the call graph for this function:

Definition at line 146 of file test_ossaudiodev.py.

00146 
00147     def test_playback(self):
00148         sound_info = read_sound_file(findfile('audiotest.au'))
00149         self.play_sound_file(*sound_info)

Here is the call graph for this function:

Definition at line 150 of file test_ossaudiodev.py.

00150 
00151     def test_set_parameters(self):
00152         dsp = ossaudiodev.open("w")
00153         try:
00154             self.set_parameters(dsp)
00155 
00156             # Disabled because it fails under Linux 2.6 with ALSA's OSS
00157             # emulation layer.
00158             #self.set_bad_parameters(dsp)
00159         finally:
00160             dsp.close()
00161             self.assertTrue(dsp.closed)

Here is the call graph for this function:

Definition at line 168 of file test_ossaudiodev.py.

00168 
00169     def test_with(self):
00170         with ossaudiodev.open('w') as dsp:
00171             pass
00172         self.assertTrue(dsp.closed)
00173 

Here is the call graph for this function:


The documentation for this class was generated from the following file: