123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package main
-
- import (
- "fmt"
- "time"
-
- "github.com/naleek/gortty"
- )
-
- type TTYFrame struct {
- Seq uint32
- Len uint32
- Samples []byte
- }
-
- func main() {
-
- s := &gortty.ModemSettings{
- Baud: 45,
- StopBits: 2,
- DataBits: 5,
- SampleRate: 8000,
- OneFreq: 2125,
- ZeroFreq: 2295,
- }
-
- charset := gortty.LoadCharset(&gortty.USTTY)
-
- encoderIn := make(chan rune)
- modulatorIn := make(chan byte)
-
- //demodulatorIn := make(chan int16)
- // decoderIn := make(chan byte)
- // decoderOut := make(chan rune)
-
- chopperIn := make(chan int16)
- chopperOut := make(chan gortty.TimeSlice)
-
- done := make(chan struct{})
-
- //sig := make(chan [2]float64)
- encoder := gortty.NewEncoder(encoderIn, modulatorIn, charset)
- gortty.NewModulator(s, modulatorIn, chopperIn)
- // gortty.NewModulator(s, modulatorIn, demodulatorIn)
- //gortty.NewDemodulator(s, demodulatorIn, decoderIn)
- // gortty.NewDecoder(decoderIn, decoderOut, charset)
-
- gortty.NewChopper(s, chopperIn, chopperOut)
-
- go func() {
- encoder.EncodeString("hello world")
- time.Sleep(2000 * time.Millisecond)
- done <- struct{}{}
- }()
-
- running := true
- x := 0
-
- var buff byte
- var bits int
-
- for running {
- select {
- case r := <-chopperOut:
- x++
-
- if r.Carrier && x%10==0 {
- buff = buff << 1
- bits++
- if r.Marking {
- buff = buff | 0x01
- }
- if bits == 8 {
- fmt.Printf("%x",buff)
- bits = 0
- buff = 0
- }
- }
- case <-done:
- running = false
- }
- }
- }
-
- // // NewOBL is fun
- // func NewOBL(baud float64, callback Callback) *OBL {
- //
- // obl := new(OBL)
- //
- // obl.charset = USTTY.initialize()
- //
- // obl.callback = callback
- //
- // obl.mod.sinLutQ15 = make([]int16, 16384)
- // for i := 0; i < 16384; i++ {
- // obl.mod.sinLutQ15[i] = int16(32767 * math.Sin(2.0*math.Pi*float64(i)/float64(16384)))
- // }
- //
- // /* regular reset */
- // obl.autobaud.enabled = true
- // obl.Reset(baud)
- //
- // go func() {
- // portaudio.Initialize()
- // defer portaudio.Terminate()
- //
- // x := make(chan int16, 300)
- //
- // stream, _ := portaudio.OpenDefaultStream(0, 1, float64(sampleRate), 0, func(out []int16) {
- // for i := range out {
- // out[i] = <-x
- // }
- // })
- //
- // stream.Start()
- //
- // for {
- // s := <-obl.mod.output
- // //go func() {
- // obl.demod.input <- s
- // x <- s
- // //}()
- // // binary.Write(f, binary.LittleEndian, s)
- // }
- // }()
- //
- // go obl.Modulate()
- // go obl.Demodulate()
- //
- // return obl
- // }
|