home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / al / cmpaf.py < prev    next >
Text File  |  1994-10-07  |  2KB  |  65 lines

  1. # Compare different audio compression schemes.
  2. #
  3. # This copies mono audio data from the input port to the output port,
  4. # and puts up a window with 4 toggle buttons:
  5. #
  6. # uLAW       : convert the data to uLAW and back
  7. # ADPCM      : convert the data to ADPCM and back
  8. # Difference : make only the difference between the converted and the
  9. #              original data audible
  10. # Exit       : quit from the program
  11.  
  12. import fl
  13. import FL
  14. import flp
  15. import al
  16. import AL
  17. import audioop
  18. import sys
  19.  
  20. class Cmpaf:
  21.     def __init__(self):
  22.         parsetree = flp.parse_form('cmpaf_form','form')
  23.         flp.create_full_form(self, parsetree)
  24.         c = al.newconfig()
  25.         c.setchannels(AL.MONO)
  26.         c.setqueuesize(1800)
  27.         self.iport = al.openport('cmpaf','r', c)
  28.         self.oport = al.openport('cmpaf','w', c)
  29.         self.do_adpcm = self.do_ulaw = self.do_diff = 0
  30.         self.acstate = None
  31.         self.form.show_form(FL.PLACE_SIZE, 1, 'compare audio formats')
  32.  
  33.     def run(self):
  34.         while 1:
  35.             olddata = data = self.iport.readsamps(600)
  36.             if self.do_ulaw:
  37.                 data = audioop.lin2ulaw(data, 2)
  38.                 data = audioop.ulaw2lin(data, 2)
  39.             if self.do_adpcm:
  40.                 data, nacstate = audioop.lin2adpcm(data, 2, \
  41.                       self.acstate)
  42.                 data, dummy = audioop.adpcm2lin(data, 2, \
  43.                       self.acstate)
  44.                 self.acstate = nacstate
  45.             if self.do_diff:
  46.                 olddata = audioop.mul(olddata, 2, -1)
  47.                 data = audioop.add(olddata, data, 2)
  48.             self.oport.writesamps(data)
  49.             fl.check_forms()
  50.  
  51.     def cb_exit(self, *args):
  52.         sys.exit(0)
  53.  
  54.     def cb_adpcm(self, obj, val):
  55.         self.do_adpcm = obj.get_button()
  56.  
  57.     def cb_ulaw(self, obj, val):
  58.         self.do_ulaw = obj.get_button()
  59.  
  60.     def cb_diff(self, obj, val):
  61.         self.do_diff = obj.get_button()
  62.  
  63. cmpaf = Cmpaf()
  64. cmpaf.run()
  65.