File: recrplay.tcl

package info (click to toggle)
snack 2.2.10.20090623-dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,764 kB
  • sloc: ansic: 32,662; sh: 8,558; tcl: 1,086; python: 761; makefile: 582
file content (80 lines) | stat: -rwxr-xr-x 1,693 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
# the next line restarts using wish \
exec wish8.4 "$0" "$@"

package require -exact snack 2.2

snack::sound s

set last 0
set server localhost:23654

proc Start {} {
    global sock server

    s record

    # Open binary socket connection to aserver.tcl

    foreach {host port} [split $server :] break
    set sock [socket $host $port]
    fconfigure $sock -translation binary
    if {$::tcl_version > 8.0} {
	fconfigure $sock -encoding binary
    }

    # Notify audio server that a play operation is due

    puts -nonewline $sock play

    # Send an AU file header to open the device correctly

    puts -nonewline $sock [s data -fileformat au]

    # Run SendData procedure in 200ms

    after 200 SendData
}

proc Stop {} {
    s stop
}

proc SendData {} {
    global last sock

    # There is new sound data to send

    if {[s length] > $last} {

	# Send audio data chunk in AU file format, "bigEndian"

	puts -nonewline $sock [s data -start $last -end -1 -fileformat raw\
		-byteorder bigEndian]
    }
    set last [s length]
    .l config -text Length:[s length]

    # User hit stop button, close down

    if ![snack::audio active] {
	set last 0
	close $sock
	return
    }
    after 300 SendData
}

pack [label .l -text "Length: 0"]

pack [frame .f1]
pack [label .f1.l -text "Server:"] -side left
pack [entry .f1.e -textvar server] -side left

pack [frame .f2]
pack [button .f2.a -bitmap snackRecord -command Start -wi 40 -he 20 -fg red] \
	-side left
pack [button .f2.b -bitmap snackStop -command Stop -wi 40 -he 20] -side left
pack [button .f2.c -bitmap snackPlay -command {s play} -wi 40 -he 20] \
	-side left
pack [button .f2.d -text Exit -command exit] -side left