Browse Source

package name updated

pull/1/head
Eray Arslan 2 years ago
parent
commit
65eeba9110
  1. 14
      bladerf.go
  2. 10
      bladerf_test.go
  3. 4
      go.mod
  4. 2
      macros.go
  5. 109
      main/main.go
  6. 4
      structs.go

14
bladerf.go

@ -10,14 +10,14 @@ import "C" @@ -10,14 +10,14 @@ import "C"
// extern void* StreamCallback(struct bladerf *dev, struct bladerf_stream *stream, struct bladerf_metadata *md, void* samples, size_t num_samples, void* user_data);
import "C"
import (
"bladerf/channel"
"bladerf/channel_layout"
"bladerf/direction"
exception "bladerf/error"
"bladerf/format"
"bladerf/gain_mode"
"bladerf/loopback"
"fmt"
"github.com/erayarslan/go-bladerf/channel"
"github.com/erayarslan/go-bladerf/channel_layout"
"github.com/erayarslan/go-bladerf/direction"
exception "github.com/erayarslan/go-bladerf/error"
"github.com/erayarslan/go-bladerf/format"
"github.com/erayarslan/go-bladerf/gain_mode"
"github.com/erayarslan/go-bladerf/loopback"
"github.com/mattn/go-pointer"
"unsafe"
)

10
bladerf_test.go

@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
package bladerf
import (
"bladerf/channel_layout"
"bladerf/direction"
"bladerf/format"
"bladerf/gain_mode"
"bladerf/log"
"fmt"
"github.com/erayarslan/go-bladerf/channel_layout"
"github.com/erayarslan/go-bladerf/direction"
"github.com/erayarslan/go-bladerf/format"
"github.com/erayarslan/go-bladerf/gain_mode"
"github.com/erayarslan/go-bladerf/log"
"github.com/gordonklaus/portaudio"
fifo "github.com/racerxdl/go.fifo"
"github.com/racerxdl/segdsp/demodcore"

4
go.mod

@ -1,12 +1,10 @@ @@ -1,12 +1,10 @@
module bladerf
module github.com/erayarslan/go-bladerf
go 1.13
require (
github.com/gordonklaus/portaudio v0.0.0-20180817120803-00e7307ccd93
github.com/mattetti/audio v0.0.0-20190404201502-c6aebeb78429
github.com/mattn/go-pointer v0.0.1
github.com/oov/audio v0.0.0-20171004131523-88a2be6dbe38
github.com/racerxdl/go.fifo v0.0.0-20180604061744-c6aa83afe374
github.com/racerxdl/segdsp v0.0.0-20190413213320-dfaea7c39d3a
)

2
macros.go

@ -2,7 +2,7 @@ package bladerf @@ -2,7 +2,7 @@ package bladerf
// #include "macro_wrapper.h"
import "C"
import "bladerf/channel"
import "github.com/erayarslan/go-bladerf/channel"
func CHANNEL_RX(ch int) channel.Channel {
return channel.Channel(C.ChannelRX(C.int(ch)))

109
main/main.go

@ -1,109 +0,0 @@ @@ -1,109 +0,0 @@
package main
import (
bf "bladerf"
"bladerf/channel_layout"
"bladerf/direction"
"bladerf/format"
"bladerf/log"
"fmt"
"github.com/gordonklaus/portaudio"
fifo "github.com/racerxdl/go.fifo"
"github.com/racerxdl/segdsp/demodcore"
"os"
"os/signal"
"syscall"
)
const audioBufferSize = 8192 / 4
var demodulator demodcore.DemodCore
var audioStream *portaudio.Stream
var audioFifo = fifo.NewQueue()
func ProcessAudio(out []float32) {
if audioFifo.Len() > 0 {
var z = audioFifo.Next().([]float32)
copy(out, z)
} else {
for i := range out {
out[i] = 0
}
}
}
func GetFinalData(input []int16) []complex64 {
var complexFloat = make([]complex64, len(input)/2)
for i := 0; i < len(complexFloat); i++ {
complexFloat[i] = complex(float32(input[2*i])/2048, float32(input[2*i+1])/2048)
}
return complexFloat
}
func cb(data []int16) {
out := demodulator.Work(GetFinalData(data))
if out != nil {
var o = out.(demodcore.DemodData)
var nBf = make([]float32, len(o.Data))
copy(nBf, o.Data)
var buffs = len(nBf) / audioBufferSize
for i := 0; i < buffs; i++ {
audioFifo.Add(nBf[audioBufferSize*i : audioBufferSize*(i+1)])
}
}
}
func main() {
log.SetVerbosity(log.Debug)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
channel := bf.CHANNEL_RX(1)
devices := bf.GetDeviceList()
if len(devices) == 0 {
fmt.Println("NO DEVICE")
return
}
rf := bf.OpenWithDevInfo(devices[0])
defer bf.Close(rf)
_ = bf.SetFrequency(&rf, channel, 96600000)
_ = bf.SetSampleRate(&rf, channel, 4e6)
_, _ = bf.SetBandwidth(&rf, channel, 240000)
//_ = SetGainMode(&rf, channel, Hybrid_AGC)
_ = bf.EnableModule(&rf, channel)
rxStream := bf.InitStream(&rf, format.SC16_Q11, 16, audioBufferSize, 8, cb)
defer bf.DeInitStream(rxStream)
_ = bf.SetStreamTimeout(&rf, direction.RX, 32)
timeout, _ := bf.GetStreamTimeout(&rf, direction.RX)
println(timeout)
demodulator = demodcore.MakeWBFMDemodulator(uint32(2e6), 80e3, 48000)
portaudio.Initialize()
h, _ := portaudio.DefaultHostApi()
p := portaudio.LowLatencyParameters(nil, h.DefaultOutputDevice)
p.Input.Channels = 0
p.Output.Channels = 1
p.SampleRate = 48000
p.FramesPerBuffer = audioBufferSize
audioStream, _ = portaudio.OpenStream(p, ProcessAudio)
_ = audioStream.Start()
go func() {
_ = bf.StartStream(rxStream, channel_layout.RX_X2)
}()
<-sig
}

4
structs.go

@ -4,8 +4,8 @@ package bladerf @@ -4,8 +4,8 @@ package bladerf
import "C"
import (
"bladerf/backend"
"bladerf/gain_mode"
"github.com/erayarslan/go-bladerf/backend"
"github.com/erayarslan/go-bladerf/gain_mode"
)
type DevInfo struct {

Loading…
Cancel
Save