-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
185 lines (146 loc) · 4.13 KB
/
main.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package main
import (
"github.com/OpenSatelliteProject/libsathelper"
"github.com/go-gl/gl/v3.2-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/golang-ui/nuklear/nk"
"github.com/racerxdl/go.fifo"
"github.com/racerxdl/kissdvb/Frontend"
"github.com/racerxdl/kissdvb/Frontend/CFileFrontend"
"github.com/racerxdl/segdsp/dsp"
"log"
"os"
"os/signal"
"runtime"
"sync"
"syscall"
"time"
)
const PllAlpha float32 = 0.0001
const ClockAlpha float32 = 0.05
const ClockMu float32 = 0.5
const ClockOmegaLimit float32 = 0.005
const ClockGainOmega = (ClockAlpha * ClockAlpha) / 4.0
var filter *dsp.FirFilter
var costasNew dsp.CostasLoop
var buffer0 []complex64
var buffer1 []complex64
var mmOld SatHelper.ClockRecovery
var videoPlayer = MakeVideoPlayer()
func checkAndResizeBuffers(length int) {
if len(buffer0) < length {
buffer0 = make([]complex64, length)
}
if len(buffer1) < length {
buffer1 = make([]complex64, length)
}
}
func swapBuffers(a *[]complex64, b *[]complex64) {
c := *b
*b = *a
*a = c
}
var lock = sync.Mutex{}
var lastConstellationUpdate time.Time
var constellationSymbolFifo *fifo.Queue
func sampleLoop(data []complex64) {
lock.Lock()
defer lock.Unlock()
checkAndResizeBuffers(len(data))
copy(buffer0, data)
ba := buffer0
bb := buffer1
s := filter.WorkBuffer(ba, bb)
swapBuffers(&ba, &bb)
s = costasNew.WorkBuffer(ba, bb)
swapBuffers(&ba, &bb)
//s = mmNew.WorkBuffer(ba, bb)
s = mmOld.Work(&ba[0], &bb[0], s)
swapBuffers(&ba, &bb)
constellationSymbolFifo.UnsafeLock()
for i := 0; i < s; i++ {
if constellationSymbolFifo.UnsafeLen() > 2048 {
break
}
constellationSymbolFifo.UnsafeAdd(ba[i])
}
constellationSymbolFifo.UnsafeUnlock()
if time.Since(lastConstellationUpdate) > time.Millisecond*10 && constellationSymbolFifo.Len() >= 1024 {
go UpdateConstellation()
lastConstellationUpdate = time.Now()
}
DecodePut(ba[:s])
}
func main() {
rsErrors.Store(int(0))
packetCount.Store(int(0))
frontend := CFileFrontend.NewCFileFrontend("/media/ELTN/Baseband Records/DVB-S/dvbs-2e6.cfile")
frontend.SetSampleRate(2e6)
sampleRate := 2e6
symbolRate := 1e6
sps := sampleRate / symbolRate
rrcTaps := dsp.MakeRRC(1, sampleRate, symbolRate, 0.35, 15)
filter = dsp.MakeFirFilter(rrcTaps)
costasNew = dsp.MakeCostasLoop4(PllAlpha)
//mmOld = SatHelper.NewClockRecovery(float32(sps), 0.25*0.175*0.175, 0.5, 0.175, 0.005)
mmOld = SatHelper.NewClockRecovery(float32(sps), ClockGainOmega, ClockMu, ClockAlpha, ClockOmegaLimit)
//mmNew = digital.NewComplexClockRecovery(float32(sps), 0.25*0.175*0.175, 0.5, 0.175, 0.005)
lastConstellationUpdate = time.Now()
constellationSymbolFifo = fifo.NewQueue()
frontend.SetSamplesAvailableCallback(func(data Frontend.SampleCallbackData) {
sampleLoop(data.ComplexArray)
})
runtime.LockOSThread()
if err := glfw.Init(); err != nil {
log.Fatalln(err)
}
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 2)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
win, err := glfw.CreateWindow(winWidth, winHeight, "KissDVB", nil, nil)
if err != nil {
log.Fatalln(err)
}
win.MakeContextCurrent()
width, height := win.GetSize()
if err := gl.Init(); err != nil {
log.Fatalf("opengl initialization failed: %s", err)
}
gl.Viewport(0, 0, int32(width), int32(height))
ctx := nk.NkPlatformInit(win, nk.PlatformInstallCallbacks)
exitC := make(chan os.Signal, 1)
doneC := make(chan struct{}, 1)
signal.Notify(exitC, os.Interrupt, syscall.SIGTERM)
go func() {
<-exitC
log.Println("Got SIGTERM!")
frontend.Stop()
win.SetShouldClose(true)
<-doneC
}()
fpsTicker := time.NewTicker(time.Second / 60)
constellationFrame, constellationTex = rgbaTex(constellationTex, constellationImage)
InitializeFonts()
nk.NkStyleSetFont(ctx, fonts["sans16"].Handle())
frontend.Start()
videoPlayer.Start()
go DecodeLoop()
for {
select {
case <-exitC:
nk.NkPlatformShutdown()
glfw.Terminate()
fpsTicker.Stop()
close(doneC)
return
case <-fpsTicker.C:
if win.ShouldClose() {
close(exitC)
continue
}
glfw.PollEvents()
gfxMain(win, ctx)
}
}
}