Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8307443

Browse files
committed
Initial revision
1 parent 2739c9c commit 8307443

2 files changed

Lines changed: 155 additions & 0 deletions

File tree

Demo/sgi/al/cmpaf.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
return self
33+
34+
def run(self):
35+
while 1:
36+
olddata = data = self.iport.readsamps(600)
37+
if self.do_ulaw:
38+
data = audioop.lin2ulaw(data, 2)
39+
data = audioop.ulaw2lin(data, 2)
40+
if self.do_adpcm:
41+
data, nacstate = audioop.lin2adpcm(data, 2, \
42+
self.acstate)
43+
data, dummy = audioop.adpcm2lin(data, 2, \
44+
self.acstate)
45+
self.acstate = nacstate
46+
if self.do_diff:
47+
olddata = audioop.mul(olddata, 2, -1)
48+
data = audioop.add(olddata, data, 2)
49+
self.oport.writesamps(data)
50+
fl.check_forms()
51+
52+
def cb_exit(self, *args):
53+
sys.exit(0)
54+
55+
def cb_adpcm(self, obj, val):
56+
self.do_adpcm = obj.get_button()
57+
58+
def cb_ulaw(self, obj, val):
59+
self.do_ulaw = obj.get_button()
60+
61+
def cb_diff(self, obj, val):
62+
self.do_diff = obj.get_button()
63+
64+
cmpaf = Cmpaf().init()
65+
cmpaf.run()

Demo/sgi/al/cmpaf_form.fd

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Magic: 12321
2+
3+
Internal Form Definition File
4+
(do not change)
5+
6+
Number of forms: 1
7+
8+
=============== FORM ===============
9+
Name: form
10+
Width: 230.000000
11+
Height: 80.000000
12+
Number of Objects: 5
13+
14+
--------------------
15+
class: 1
16+
type: 1
17+
box: 0.000000 0.000000 230.000000 80.000000
18+
boxtype: 1
19+
colors: 47 47
20+
alignment: 4
21+
style: 0
22+
size: 11.000000
23+
lcol: 0
24+
label:
25+
name:
26+
callback:
27+
argument:
28+
29+
--------------------
30+
class: 12
31+
type: 1
32+
box: 10.000000 40.000000 100.000000 30.000000
33+
boxtype: 1
34+
colors: 39 3
35+
alignment: 4
36+
style: 0
37+
size: 11.000000
38+
lcol: 0
39+
label: uLAW
40+
name: ulawbutton
41+
callback: cb_ulaw
42+
argument: 0
43+
44+
--------------------
45+
class: 12
46+
type: 1
47+
box: 10.000000 10.000000 100.000000 30.000000
48+
boxtype: 1
49+
colors: 39 3
50+
alignment: 4
51+
style: 0
52+
size: 11.000000
53+
lcol: 0
54+
label: ADPCM
55+
name: adpcm_button
56+
callback: cb_adpcm
57+
argument: 0
58+
59+
--------------------
60+
class: 11
61+
type: 0
62+
box: 170.000000 10.000000 50.000000 20.000000
63+
boxtype: 1
64+
colors: 47 47
65+
alignment: 4
66+
style: 0
67+
size: 11.000000
68+
lcol: 0
69+
label: EXIT
70+
name: exit_button
71+
callback: cb_exit
72+
argument: 0
73+
74+
--------------------
75+
class: 12
76+
type: 1
77+
box: 120.000000 40.000000 100.000000 30.000000
78+
boxtype: 1
79+
colors: 39 3
80+
alignment: 4
81+
style: 0
82+
size: 11.000000
83+
lcol: 0
84+
label: Difference
85+
name: diffbutton
86+
callback: cb_diff
87+
argument: 0
88+
89+
==============================
90+
create_the_forms

0 commit comments

Comments
 (0)