]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/play
play: use audio/sundec instead of audio/µlawdec
[plan9front.git] / rc / bin / play
1 #!/bin/rc
2 rfork e
3
4 out=/dev/audio
5 typ=()
6 tmp=()
7 argv0=$0
8
9 fn cleanup {
10         if(! ~ $#tmp 0)
11                 rm -f $tmp
12         tmp=()
13 }
14
15 fn sigint {
16         cleanup
17         exit
18 }
19
20 fn sigexit {
21         cleanup
22 }
23
24 fn play1 {
25         if(~ $#* 0){
26                 tmp=(/tmp/play.$pid.$#tmp.tmp $tmp)
27                 dd -bs 8192 -count 1 >$tmp(1) >[2]/dev/null
28                 cat $tmp(1) /fd/0 | play1 `{file -m $tmp(1)} xxx
29                 cleanup
30         }
31         if not {
32                 switch($1){
33                 case *plain*
34                         sed 's/\r//g' | while(j=`{read}){
35                                 echo $"j >[1=2]
36                                 if(~ $"j http:* https:* HTTP:* HTTPS:*){
37                                         hget -r 'Icy-MetaData: 0' $j | play1
38                                 }
39                                 if not {
40                                         if(test -r $"j)
41                                                 play1 <$"j
42                                         if not {
43                                                 echo $argv0: 'can''t open file:' $"j >[1=2]
44                                         }
45                                 }
46                         }
47                 case *ogg* *vorbis*
48                         audio/oggdec
49                 case *mp3* *mpeg*
50                         audio/mp3dec
51                 case *wave*
52                         audio/wavdec
53                 case *flac*
54                         audio/flacdec
55                 case *audio/basic*
56                         audio/sundec
57                 case *pls*
58                         awk 'BEGIN {FS="="} /^File/{print $2}' | play1 plain
59                 case *
60                         echo $argv0: unknown format: $1 >[1=2]
61                 }
62         }
63 }
64
65 fn usage {
66         echo usage: $argv0 [ -o file ] [ file ... ] >[1=2]
67         exit usage
68 }
69
70 while(~ $1 -*){
71         switch($1){
72         case -o
73                 out=$2
74                 shift
75         case *
76                 usage
77         }
78         shift
79 }
80
81 # boost priority
82 @{echo pri 13 >/proc/$pid/ctl} >/dev/null >[2=1] 
83
84 >$out {
85         if(~ $#* 0){play1; exit}
86         for(i){echo $i} | play1 plain 
87