-
Notifications
You must be signed in to change notification settings - Fork 8
/
dspcore.go
74 lines (59 loc) · 1010 Bytes
/
dspcore.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
package main
import (
"github.com/racerxdl/go.fifo"
"github.com/racerxdl/segdsp/demodcore"
"runtime"
"time"
)
var samplesFifo *fifo.Queue
var demodulator demodcore.DemodCore
var running = false
var buffer []complex64
var delta = 0.0
var count = 0
var dspCb func(interface{})
func addComplex(data []complex64) {
samplesFifo.Add(data)
}
func initDSP() {
samplesFifo = fifo.NewQueue()
}
func startDSP() {
if !running {
running = true
go dspLoop()
}
}
func stopDSP() {
if running {
running = false
}
}
func dspRun() {
length := samplesFifo.Len()
if length == 0 {
return
}
if demodulator == nil || dspCb == nil {
return
}
buffer = samplesFifo.Next().([]complex64)
var t0 = time.Now()
var out = demodulator.Work(buffer)
var d = time.Since(t0)
delta += d.Seconds()
count++
if out != nil {
delta /= float64(count)
//log.Println("Delta: ", delta, "seconds")
delta = 0
count = 0
dspCb(out)
}
}
func dspLoop() {
for running {
dspRun()
runtime.Gosched()
}
}