123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package main
-
- import (
- "fmt"
- "math"
- "math/rand"
-
- "github.com/naleek/gortty"
- )
-
- // 96000 = 14
- // 48000 = 7
- // 44100 = 7
- // 22050 = 3
- // 11025 = 1
- // 8000 = 1
- func main() {
- // lpf := 100
- // l := newLpf(lpf)
- // for i := 5000; i <= 44100; i += 1000 {
- // l.update(dostuff(11025))
- // dostuff(11025)
- dostuff(8000)
- // dostuff(11025)
- // dostuff(22050)
- // dostuff(44100)
- // dostuff(48000)
- // dostuff(96000)
-
- // fmt.Printf("%d\t%f\n", i-lpf/2, v)
- //}
- }
- func dostuff(freq int) float64 {
-
- done := make(chan bool)
-
- s := &gortty.ModemSettings{
- Baud: 45,
- StopBits: 2,
- DataBits: 5,
- SampleRate: freq,
- OneFreq: 2125,
- ZeroFreq: 2295,
- }
-
- demodulatorIn := make(chan int16)
- demodulatorOut := make(chan [3]float64)
-
- go func() {
-
- // pulse
- // for i := 0; i <= 200; i++ {
- // if i == 50 {
- // demodulatorIn <- int16(16384)
- // } else {
- // demodulatorIn <- int16(0)
- // }
- // }
- //
- // for samp := 0; samp <= s.SampleRate/45; samp++ {
- // phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * 2125 * 2
- // demodulatorIn <- int16(math.Sin(phase) * 16384)
- // }
- // // noise
- for i := 0; i <= s.SampleRate/4; i++ {
- n := rand.Float64()
- demodulatorIn <- int16(n * 16384)
- }
- for x := 0; x <= 5; x++ {
- for samp := 0; samp <= s.SampleRate/45; samp++ {
- phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.OneFreq)
- n := rand.Float64()
- demodulatorIn <- int16((math.Sin(phase) + n) * 16384)
- }
-
- for samp := 0; samp <= s.SampleRate/45; samp++ {
- phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.ZeroFreq)
- n := rand.Float64()
- demodulatorIn <- int16((math.Sin(phase) + n) * 16384)
- }
- }
-
- //
- // for samp := 0; samp <= s.SampleRate/1; samp++ {
- // phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.ZeroFreq)
- // demodulatorIn <- int16(math.Sin(phase) * 16384)
- // }
- // for samp := 0; samp <= s.SampleRate/40; samp++ {
- // phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.OneFreq)
- // demodulatorIn <- int16(math.Sin(phase) * 16384)
- // }
- //
- // for samp := 0; samp <= s.SampleRate/40; samp++ {
- // phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.ZeroFreq)
- // demodulatorIn <- int16(math.Sin(phase) * 16384)
- // }
- // for samp := 0; samp <= s.SampleRate/10; samp++ {
- // phase := 2 * math.Pi * float64(samp) / float64(s.SampleRate) * float64(s.ZeroFreq)
- // demodulatorIn <- int16(math.Sin(phase) * 16384)
- // }
-
- done <- true
- }()
-
- gortty.NewDumbDemodulator(s, demodulatorIn, demodulatorOut)
- c := 0
- running := true
- var r float64
- for running {
- select {
- case v := <-demodulatorOut:
- fmt.Printf("%f\t%f\t%f\n", v[0], v[1], v[2])
- r = v[0]
-
- c++
- case <-done:
-
- running = false
- }
- }
- return r
- }
-
- type lpf struct {
- x []float64
- t float64
- }
-
- func newLpf(size int) *lpf {
- l := new(lpf)
- l.x = make([]float64, size)
- return l
- }
-
- func (l *lpf) update(v float64) float64 {
-
- o := l.x[0]
- l.x = append(l.x, v)
- l.x = l.x[1:]
-
- l.t -= o
- l.t += v
-
- return l.t
- }
|