-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickRec.go.go
119 lines (102 loc) · 2.03 KB
/
clickRec.go.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"fmt"
"github.com/williamsharkey/rec/go-wave"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
)
var sig = make(chan os.Signal, 1)
func init() {
signal.Notify(sig, os.Interrupt, os.Kill)
}
func clickRec(rs *RecSettings) {
s := rs.Rec
s.Active = !s.Active
if rs.Rec.Active {
go recNew(rs)
newpath := filepath.Join(".", "wavs")
err := os.MkdirAll(newpath, os.ModePerm)
if err != nil {
return
}
files, err := ioutil.ReadDir(newpath)
if err != nil {
return
}
var max int64 = 0
for _, file := range files {
n := file.Name()
ext := filepath.Ext(n)
name := strings.TrimSuffix(n, ext)
curr, errP := strconv.ParseInt(name, 10, 64)
if errP != nil {
continue
}
if curr > max {
max = curr
}
}
fn := fmt.Sprintf("%03d", max+1)
audioFileName := filepath.Join(newpath, fn+".wav")
waveFile, err := os.Create(audioFileName)
if err != nil {
return
}
defer waveFile.Close()
param := wave.WriterParam{
Out: waveFile,
Channel: 1,
SampleRate: 44100,
BitsPerSample: 32,
}
waveWriter, err := wave.NewWriter(param)
if err != nil {
return
}
defer waveWriter.Close()
Loop2:
for {
select {
case <-sig:
return
//panic("yo")
//waveWriter.Close()
//waveFile.Close()
//recAppend(rs.RecList, rs.UI, fn)
//break Loop2
case <-rs.Rec.Print:
//fmt.Println("s received", p)
case samps := <-rs.Rec.Buffer:
//x:=[4*1024]byte{}
//for i,s:=range samps{
// p:=int32ToByte(s)
// x[i+0]=p[0]
// x[i+1]=p[1]
// x[i+2]=p[2]
// x[i+3]=p[3]
//}
_, err = waveWriter.WriteSample32(samps[:])
if err != nil {
waveWriter.Close()
waveFile.Close()
return
}
case <-rs.Rec.Complete:
waveWriter.Close()
waveFile.Close()
//f,err:=waveFile.Stat()
//if err==nil{waveWriter
recAppend(rs, nameSize{fn, int64(waveWriter.RiffChunk.Size + 8)}) //f.Size()})
//}
break Loop2
default:
}
}
} else {
rs.Rec.Kill <- 1
}
}