Added README; cleaned up the repo
This commit is contained in:
33 files changed
+270
-9330
No files matched your search
@@ -1,3 +1,127 @@
|
|||||||
# beatglow
|
# BeatGlow
|
||||||
|
|
||||||
BeatGlow is a music visualiser for embedded audio players
|
Visualizer for audiophile streamers (or enthousiasts alike).
|
||||||
|
|
||||||
|
## State of the project
|
||||||
|
|
||||||
|
Work in progress!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### Main display
|
||||||
|
|
||||||
|
Showing what track is currently playing.
|
||||||
|
|
||||||
|
Features:
|
||||||
|
- Audio format, bitrate and output sample rate display
|
||||||
|
- Track elapsed and duration
|
||||||
|
- Track album art
|
||||||
|
- Spectrum analyzer / Waterfall display of the track playing
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Settings
|
||||||
|
|
||||||
|
Live adjust settings from the rotary dail.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Minimal requirements:
|
||||||
|
- Linux Computer (Raspberry Pi 3B+)
|
||||||
|
- Supported display
|
||||||
|
|
||||||
|
### Setup Raspberry Pi & SSD1322 256x64 OLED display
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
- Raspberry Pi 3B+/4B+
|
||||||
|
- SSD1322 OLED Display 3.12" 256x64
|
||||||
|
- Display purchase options:
|
||||||
|
- [AliExpress](https://s.click.aliexpress.com/e/_onJsYxJ) [^1]
|
||||||
|
- [AudioPhonics.fr](https://www.audiophonics.fr/en/screens-vu-meters/white-spi-iic-256x64-oled-312-screen-p-14604.html)
|
||||||
|
|
||||||
|
|
||||||
|
#### Wiring
|
||||||
|
|
||||||
|
Wiring the display is as follows, looking at the OLED display connector from the back (pin 1 on the top left, pin 16 on the bottom right):
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
| Wire | Function | Raspberry Pi | Display |
|
||||||
|
| -------------------------------- | --------- | --------------- | ------- |
|
||||||
|
|  | Ground | Pin 20 (GND) | Pin 1 |
|
||||||
|
|  | 3.3V | Pin 17 (3.3V) | Pin 2 |
|
||||||
|
|  | SPI Clock | Pin 23 (GPIO11) | Pin 4 |
|
||||||
|
|  | SPI Data | Pin 19 (GPIO10) | Pin 5 |
|
||||||
|
|  | SPI D/C | Pin 18 (GPIO24) | Pin 14 |
|
||||||
|
|  | SPI Reset | Pin 22 (GPIO25) | Pin 15 |
|
||||||
|
|  | SPI C/E | Pin 24 (GPIO8) | Pin 16 |
|
||||||
|
|
||||||
|
#### Configuration
|
||||||
|
|
||||||
|
The display configuration in `beatglow.conf` is as follows:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# Display hardware configuration.
|
||||||
|
display {
|
||||||
|
# Target frame rate, actual frame rate depends on hardware options.
|
||||||
|
fps = 25
|
||||||
|
|
||||||
|
# Main display is where all the magic happens.
|
||||||
|
main {
|
||||||
|
# Type of display
|
||||||
|
type = "ssd1322"
|
||||||
|
size = "256x64"
|
||||||
|
|
||||||
|
# Mode (spi or i2c)
|
||||||
|
mode = "spi"
|
||||||
|
|
||||||
|
# SPI settings
|
||||||
|
port = "spi0.0"
|
||||||
|
reset = "GPIO25"
|
||||||
|
dc = "GPIO24"
|
||||||
|
bl = "GPIO23"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup Raspberry Pi & ST7789 170x320 IPS display
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
- Raspberry Pi 3B+/4B+
|
||||||
|
- ST7735/ST8889 IPS display
|
||||||
|
- Display purchase options:
|
||||||
|
- [AliExpress](https://s.click.aliexpress.com/e/_onuTZPb) [^1]
|
||||||
|
- [Waveshare](https://www.waveshare.com/1.9inch-lcd-module.htm)
|
||||||
|
|
||||||
|
#### Configuration
|
||||||
|
|
||||||
|
The display configuration in `beatglow.conf` is as follows:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
|
||||||
|
display {
|
||||||
|
# Target frame rate, actual frame rate depends on hardware options.
|
||||||
|
fps = 25
|
||||||
|
|
||||||
|
# Main display is where all the magic happens.
|
||||||
|
main {
|
||||||
|
# Type of display
|
||||||
|
type = "st7789" # or st7735
|
||||||
|
size = "320x130"
|
||||||
|
rotate = "left"
|
||||||
|
|
||||||
|
# Mode (spi or i2c)
|
||||||
|
mode = "spi"
|
||||||
|
|
||||||
|
# SPI settings
|
||||||
|
port = "spi0.0"
|
||||||
|
reset = "GPIO25"
|
||||||
|
dc = "GPIO24"
|
||||||
|
bl = "GPIO23"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
[^1]: Affiliate links, by clicking them and making an order there is a small kick back for me, which allows me to order parts for testing. There is usually no additional costs for the purchaser.
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"math/cmplx"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/internal/calc"
|
|
||||||
"gonum.org/v1/gonum/dsp/fourier"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FrequencySpectrumAnalyzer structure to hold analysis parameters
|
|
||||||
type FrequencySpectrumAnalyzer struct {
|
|
||||||
SampleRate float64
|
|
||||||
BitDepth int
|
|
||||||
NumBins int
|
|
||||||
MinFrequency float64
|
|
||||||
MaxFrequency float64
|
|
||||||
avgSamples []float64
|
|
||||||
coefficients []complex128
|
|
||||||
bins []float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// dBFS calculates dBFS for the given amplitude value
|
|
||||||
func dBFS(amplitude float64) float64 {
|
|
||||||
if amplitude == 0 {
|
|
||||||
return -math.Inf(1) // -Infinity for silence
|
|
||||||
}
|
|
||||||
return 20 * math.Log10(amplitude)
|
|
||||||
}
|
|
||||||
|
|
||||||
func normalize(values []float64) {
|
|
||||||
var max float64
|
|
||||||
for _, v := range values {
|
|
||||||
if v = math.Abs(v); v > max {
|
|
||||||
max = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if max == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for i := range values {
|
|
||||||
values[i] /= max
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AnalyzeFrequencySpectrum performs the FFT and returns the energy levels in dBFS for each frequency bin
|
|
||||||
func (a *FrequencySpectrumAnalyzer) AnalyzeFrequencySpectrum(buffer *Buffer) []float64 {
|
|
||||||
samples := len(buffer.Samples[0])
|
|
||||||
//if len(a.avgSamples) != samples {
|
|
||||||
a.avgSamples = make([]float64, samples)
|
|
||||||
a.coefficients = make([]complex128, samples/2+1)
|
|
||||||
//}
|
|
||||||
|
|
||||||
channels := len(buffer.Samples)
|
|
||||||
if channels == 1 {
|
|
||||||
for i, sample := range buffer.Samples[0] {
|
|
||||||
a.avgSamples[i] = float64(sample)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for i := range buffer.Samples[0] {
|
|
||||||
a.avgSamples[i] = float64(buffer.Samples[0][i]+buffer.Samples[1][i]) / 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply windowing function
|
|
||||||
//normalize(a.avgSamples)
|
|
||||||
//calc.Hamming(a.avgSamples, a.avgSamples)
|
|
||||||
calc.Hann(a.avgSamples, a.avgSamples)
|
|
||||||
|
|
||||||
// Perform FFT on the signal
|
|
||||||
fft := fourier.NewFFT(samples)
|
|
||||||
fft.Coefficients(a.coefficients, a.avgSamples)
|
|
||||||
|
|
||||||
// Calculate the energy levels in dBFS for each frequency bin
|
|
||||||
var (
|
|
||||||
frequencyBinSize = a.SampleRate / float64(samples)
|
|
||||||
minBin = int(math.Round(a.MinFrequency / frequencyBinSize))
|
|
||||||
maxBin = int(math.Round(a.MaxFrequency / frequencyBinSize))
|
|
||||||
)
|
|
||||||
|
|
||||||
// Make sure the minimum bin is not lower than 0, and the maximum bin doesn't exceed half of the buffer size
|
|
||||||
if minBin < 0 {
|
|
||||||
minBin = 0
|
|
||||||
}
|
|
||||||
if maxBin > samples/2 {
|
|
||||||
maxBin = samples / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
//if len(a.bins) != a.NumBins {
|
|
||||||
a.bins = make([]float64, a.NumBins)
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Compute dBFS levels for the selected frequency range
|
|
||||||
for i := 0; i < a.NumBins; i++ {
|
|
||||||
var (
|
|
||||||
// Calculate the frequency range for this bin
|
|
||||||
frequencyScale = (a.MaxFrequency - a.MinFrequency) / float64(a.NumBins)
|
|
||||||
frequencyStart = a.MinFrequency + float64(i)*frequencyScale
|
|
||||||
frequencyEnd = a.MinFrequency + float64(i+1)*frequencyScale
|
|
||||||
|
|
||||||
// Determine the FFT bin range corresponding to the frequency range of this bin
|
|
||||||
startBin = int((frequencyStart / frequencyBinSize) + .5)
|
|
||||||
endBin = int((frequencyEnd / frequencyBinSize) + .5)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure the bins are within the valid range
|
|
||||||
if startBin < 0 {
|
|
||||||
startBin = 0
|
|
||||||
}
|
|
||||||
if endBin > samples/2 {
|
|
||||||
endBin = samples / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Average the magnitudes of the FFT bins in this range and accumulate the result
|
|
||||||
var totalAmplitude float64
|
|
||||||
var count int
|
|
||||||
for bin := startBin; bin < endBin; bin++ {
|
|
||||||
x := a.coefficients[bin]
|
|
||||||
//amplitude := real(x)*real(x) + imag(x)*imag(x) // math.Hypot(real(x), imag(x))
|
|
||||||
amplitude := math.Min(cmplx.Abs(x), 1.0)
|
|
||||||
totalAmplitude += amplitude
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the average dBFS for this frequency bin
|
|
||||||
if count > 0 {
|
|
||||||
a.bins[i] = math.Min((totalAmplitude/float64(count))*10, 1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.bins
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import "math"
|
|
||||||
|
|
||||||
// Float is all floating point number types (and Samples).
|
|
||||||
type Float interface {
|
|
||||||
~float32 | ~float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clamp a sample in [-1..+1].
|
|
||||||
func Clamp[T Float](sample T) T {
|
|
||||||
if sample < -1 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if sample > +1 {
|
|
||||||
return +1
|
|
||||||
}
|
|
||||||
return sample
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abs a slice of values.
|
|
||||||
func Abs[T Float](values []T) {
|
|
||||||
for i, v := range values {
|
|
||||||
values[i] = T(math.Abs(float64(v)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mean of values.
|
|
||||||
func Mean[T Float](values []T) T {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// an algorithm that attempts to retain accuracy
|
|
||||||
// with widely different values.
|
|
||||||
var parts []float64
|
|
||||||
for _, v := range values {
|
|
||||||
var (
|
|
||||||
x = float64(v)
|
|
||||||
i int
|
|
||||||
)
|
|
||||||
for _, p := range parts {
|
|
||||||
sum := p + x
|
|
||||||
var err float64
|
|
||||||
switch ax, ap := math.Abs(x), math.Abs(p); {
|
|
||||||
case ax < ap:
|
|
||||||
err = x - (sum - p)
|
|
||||||
case ap < ax:
|
|
||||||
err = p - (sum - x)
|
|
||||||
}
|
|
||||||
if err != 0 {
|
|
||||||
parts[i] = err
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
x = sum
|
|
||||||
}
|
|
||||||
parts = append(parts[:i], x)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum float64
|
|
||||||
for _, x := range parts {
|
|
||||||
sum += x
|
|
||||||
}
|
|
||||||
return T(sum / float64(len(values)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// RMS calculates the root mean square of values.
|
|
||||||
func RMS[T Float](values []T) T {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var squares float64
|
|
||||||
for _, v := range values {
|
|
||||||
squares += float64(v) * float64(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
return T(math.Sqrt(squares / float64(len(values))))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sum of values.
|
|
||||||
func Sum[T Float](values []T) T {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum T
|
|
||||||
for _, v := range values {
|
|
||||||
sum += v
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
// SQNR is the signal-to-quantization-noise ratio.
|
|
||||||
func SQNR(bits int) float64 {
|
|
||||||
return 20 * math.Log10(math.Pow(2, float64(bits)))
|
|
||||||
}
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/binary"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Sample is a type alias for float64.
|
|
||||||
type Sample float64
|
|
||||||
|
|
||||||
// Format is the format of a Buffer or another audio source.
|
|
||||||
type Format interface {
|
|
||||||
// BitsPerSample is the number of bits per sample.
|
|
||||||
BitsPerSample() int
|
|
||||||
|
|
||||||
// Order is the byte order.
|
|
||||||
Order() binary.ByteOrder
|
|
||||||
|
|
||||||
// DecodeFromBytes reads one sample from b. No bounds checking is performed on b!
|
|
||||||
DecodeFromBytes(b []byte) Sample
|
|
||||||
|
|
||||||
// EncodeToBytes writes on sample to b.
|
|
||||||
EncodeToBytes(b []byte, s Sample)
|
|
||||||
}
|
|
||||||
|
|
||||||
type pcmFormat uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
Int8 pcmFormat = iota
|
|
||||||
Int16
|
|
||||||
Int16BE
|
|
||||||
Int32
|
|
||||||
Int32BE
|
|
||||||
Float32
|
|
||||||
Float32BE
|
|
||||||
Float64
|
|
||||||
Float64BE
|
|
||||||
)
|
|
||||||
|
|
||||||
func makeFormat(bits int) pcmFormat {
|
|
||||||
switch bits {
|
|
||||||
case 8:
|
|
||||||
return Int8
|
|
||||||
case 16:
|
|
||||||
return Int16
|
|
||||||
case 32:
|
|
||||||
return Int32
|
|
||||||
default:
|
|
||||||
return Int16
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var pcmfFormatBitsPerSample = map[pcmFormat]int{
|
|
||||||
Int8: 8,
|
|
||||||
Int16: 16,
|
|
||||||
Int16BE: 16,
|
|
||||||
Int32: 32,
|
|
||||||
Int32BE: 32,
|
|
||||||
Float32: 32,
|
|
||||||
Float32BE: 32,
|
|
||||||
Float64: 64,
|
|
||||||
Float64BE: 64,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f pcmFormat) BitsPerSample() int {
|
|
||||||
if v, ok := pcmfFormatBitsPerSample[f]; ok {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f pcmFormat) Order() binary.ByteOrder {
|
|
||||||
if f%2 == 0 {
|
|
||||||
return binary.BigEndian
|
|
||||||
}
|
|
||||||
return binary.LittleEndian
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f pcmFormat) DecodeFromBytes(b []byte) Sample {
|
|
||||||
order := f.Order()
|
|
||||||
switch f {
|
|
||||||
case Int8:
|
|
||||||
return Sample(int8(b[0])) / math.MaxInt8
|
|
||||||
case Int16, Int16BE:
|
|
||||||
return Sample(int16(order.Uint16(b))) / math.MaxInt16
|
|
||||||
case Int32, Int32BE:
|
|
||||||
return Sample(int32(order.Uint32(b))) / math.MaxInt32
|
|
||||||
case Float32, Float32BE:
|
|
||||||
return Sample(math.Float32frombits(order.Uint32(b)))
|
|
||||||
case Float64, Float64BE:
|
|
||||||
return Sample(math.Float64frombits(order.Uint64(b)))
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f pcmFormat) EncodeToBytes(b []byte, s Sample) {
|
|
||||||
order := f.Order()
|
|
||||||
switch f {
|
|
||||||
case Int8:
|
|
||||||
b[0] = byte(int8(s * math.MaxInt8))
|
|
||||||
case Int16, Int16BE:
|
|
||||||
order.PutUint16(b, uint16(int16(s*math.MaxInt16)))
|
|
||||||
case Int32, Int32BE:
|
|
||||||
order.PutUint32(b, uint32(int32(s*math.MaxInt32)))
|
|
||||||
case Float32, Float32BE:
|
|
||||||
order.PutUint32(b, math.Float32bits(float32(s)))
|
|
||||||
case Float64, Float64BE:
|
|
||||||
order.PutUint64(b, math.Float64bits(float64(s)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var pcmFormatNames = map[pcmFormat]string{
|
|
||||||
Int8: "8-bit signed PCM",
|
|
||||||
Int16: "16-bit signed PCM",
|
|
||||||
Int16BE: "16-bit signed PCM (BE)",
|
|
||||||
Int32: "32-bit signed PCM",
|
|
||||||
Int32BE: "32-bit signed PCM (BE)",
|
|
||||||
Float32: "32-bit floating piont PCM",
|
|
||||||
Float32BE: "32-bit floating point PCM (BE)",
|
|
||||||
Float64: "64-bit floating point PCM",
|
|
||||||
Float64BE: "64-bit floating point PCM (BE)",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f pcmFormat) String() string {
|
|
||||||
if s, ok := pcmFormatNames[f]; ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffer of audio samples, only supports mono and stereo samples.
|
|
||||||
type Buffer struct {
|
|
||||||
Format Format
|
|
||||||
Rate Rate
|
|
||||||
Samples [][]Sample
|
|
||||||
buf []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBuffer(format Format, rate Rate, n, channels int) *Buffer {
|
|
||||||
if channels < 1 {
|
|
||||||
channels = 1
|
|
||||||
}
|
|
||||||
if channels > 2 {
|
|
||||||
channels = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"channels": channels,
|
|
||||||
"rate": rate,
|
|
||||||
"format": format,
|
|
||||||
"samples": n,
|
|
||||||
}).Debug("new audio buffer")
|
|
||||||
|
|
||||||
samples := make([][]Sample, channels)
|
|
||||||
for channel := 0; channel < channels; channel++ {
|
|
||||||
samples[channel] = make([]Sample, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Buffer{
|
|
||||||
Format: format,
|
|
||||||
Rate: rate,
|
|
||||||
Samples: samples,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeFrom decodes samples read from r.
|
|
||||||
func (b *Buffer) DecodeFrom(r io.Reader) (n int, err error) {
|
|
||||||
if s, ok := r.(SamplesReader); ok {
|
|
||||||
// Use the SamplesReader interface, if available.
|
|
||||||
return s.ReadSamples(b.Samples)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
channels = len(b.Samples)
|
|
||||||
samples = len(b.Samples[0])
|
|
||||||
bitsPerSample = b.Format.BitsPerSample()
|
|
||||||
bytesPerSample = bitsPerSample / 8
|
|
||||||
bytesRequired = channels * samples * bytesPerSample
|
|
||||||
)
|
|
||||||
|
|
||||||
// Resize buffer, if required.
|
|
||||||
if len(b.buf) < bytesRequired {
|
|
||||||
b.buf = make([]byte, bytesRequired)
|
|
||||||
} else {
|
|
||||||
b.buf = b.buf[:bytesRequired]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read raw bytes.
|
|
||||||
if _, err = io.ReadFull(r, b.buf); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert bytes to samples, deinterleave multi channel audio.
|
|
||||||
var o, c int
|
|
||||||
for i, l := 0, bytesRequired/bytesPerSample; i < l; i++ {
|
|
||||||
b.Samples[0][c] = b.Format.DecodeFromBytes(b.buf[o : o+bytesPerSample])
|
|
||||||
c = (c + 1) % channels
|
|
||||||
o = o + bytesPerSample
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytesRequired / bytesPerSample, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToMono converts the buffer to mono. If the buffer is already mono, it returns the buffer.
|
|
||||||
func (b *Buffer) ToMono() *Buffer {
|
|
||||||
if len(b.Samples) == 1 {
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert stereo buffer to mono.
|
|
||||||
o := NewBuffer(b.Format, b.Rate, len(b.Samples[0]), 2)
|
|
||||||
for i := range o.Samples[0] {
|
|
||||||
o.Samples[0][i] = (b.Samples[0][i] + b.Samples[1][i]) / 2
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToStereo converts the buffer to stereo. If the buffer is already stereo, it returns the buffer.
|
|
||||||
func (b *Buffer) ToStereo() *Buffer {
|
|
||||||
if len(b.Samples) == 2 {
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert mono buffer to stereo.
|
|
||||||
o := NewBuffer(b.Format, b.Rate, len(b.Samples[0]), 1)
|
|
||||||
copy(o.Samples[0], b.Samples[0])
|
|
||||||
copy(o.Samples[1], b.Samples[0])
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
type BufferProcessor interface {
|
|
||||||
ProcessBuffer(buffer *Buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Processor interface {
|
|
||||||
ProcessSamples(samples [][]Sample)
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestFormatBitsPerSample(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
Test Format
|
|
||||||
Want int
|
|
||||||
}{
|
|
||||||
{Int8, 8},
|
|
||||||
{Int16, 16},
|
|
||||||
{Int16BE, 16},
|
|
||||||
{Int32, 32},
|
|
||||||
{Int32BE, 32},
|
|
||||||
}
|
|
||||||
for _, test := range testCases {
|
|
||||||
t.Run(test.Test.(pcmFormat).String(), func(it *testing.T) {
|
|
||||||
if v := test.Test.BitsPerSample(); v != test.Want {
|
|
||||||
it.Errorf("expected %d bits per sample, got %d", test.Want, v)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Register("file", openReader)
|
|
||||||
Register("fifo", openReader)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Source of audio samples.
|
|
||||||
type Source interface {
|
|
||||||
io.Reader
|
|
||||||
|
|
||||||
String() string
|
|
||||||
|
|
||||||
// Channels is the number of channels.
|
|
||||||
Channels() int
|
|
||||||
|
|
||||||
// Format of the source.
|
|
||||||
Format() Format
|
|
||||||
|
|
||||||
// SampleRate of the source.
|
|
||||||
SampleRate() Rate
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotFound signals the reader type can not be found.
|
|
||||||
type NotFound struct {
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err NotFound) Error() string {
|
|
||||||
return fmt.Sprintf("audio source %q not available", err.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SourceOpener can open an audio stream source.
|
|
||||||
type SourceOpener func(config.Audio) (Source, error)
|
|
||||||
|
|
||||||
var drivers = make(map[string]SourceOpener)
|
|
||||||
|
|
||||||
func Register(name string, opener SourceOpener) {
|
|
||||||
if _, dupe := drivers[name]; dupe {
|
|
||||||
panic(fmt.Sprintf("audio source %q already registered", name))
|
|
||||||
}
|
|
||||||
drivers[name] = opener
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSource(config config.Audio) (Source, error) {
|
|
||||||
opener, ok := drivers[config.Type]
|
|
||||||
if ok {
|
|
||||||
return opener(config)
|
|
||||||
}
|
|
||||||
return nil, NotFound{Type: config.Type}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReaderSource struct {
|
|
||||||
io.ReadCloser
|
|
||||||
|
|
||||||
// Name of the reader (path).
|
|
||||||
Name string
|
|
||||||
|
|
||||||
// Ch is the number of channels.
|
|
||||||
Ch int
|
|
||||||
|
|
||||||
// Format is the audio format.
|
|
||||||
Fmt Format
|
|
||||||
|
|
||||||
// Rate is the sample rate.
|
|
||||||
Rate Rate
|
|
||||||
|
|
||||||
// Opener is a function that can be called if the reader is closed.
|
|
||||||
Opener func() (io.ReadCloser, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func openReader(config config.Audio) (Source, error) {
|
|
||||||
var (
|
|
||||||
ch = config.Channels
|
|
||||||
bits = config.Bits
|
|
||||||
rate = Rate(config.Rate)
|
|
||||||
)
|
|
||||||
if ch == 0 {
|
|
||||||
ch = 2
|
|
||||||
}
|
|
||||||
if bits == 0 {
|
|
||||||
bits = 16
|
|
||||||
}
|
|
||||||
if rate == 0 {
|
|
||||||
rate = 44100
|
|
||||||
}
|
|
||||||
return &ReaderSource{
|
|
||||||
Name: config.Path,
|
|
||||||
Ch: ch,
|
|
||||||
Fmt: makeFormat(bits),
|
|
||||||
Rate: rate,
|
|
||||||
Opener: func() (io.ReadCloser, error) {
|
|
||||||
return os.Open(config.Path)
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ReaderSource) String() string {
|
|
||||||
return "reader:" + s.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ReaderSource) Channels() int {
|
|
||||||
return s.Ch
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ReaderSource) Format() Format {
|
|
||||||
return s.Fmt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ReaderSource) SampleRate() Rate {
|
|
||||||
return s.Rate
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ReaderSource) Read(b []byte) (int, error) {
|
|
||||||
var err error
|
|
||||||
if r.ReadCloser == nil {
|
|
||||||
if r.ReadCloser, err = r.Opener(); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var n int
|
|
||||||
if n, err = r.ReadCloser.Read(b); err != nil {
|
|
||||||
logrus.WithError(err).Warn("source failed to read; closing")
|
|
||||||
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
|
||||||
_ = r.ReadCloser.Close()
|
|
||||||
r.ReadCloser = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type SamplesReader interface {
|
|
||||||
// ReadSamples reads samples, it returns the number of samples read.
|
|
||||||
ReadSamples(samples [][]Sample) (int, error)
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
const streamDoubleBufferSize = 16
|
|
||||||
|
|
||||||
type StreamCancelFunc func()
|
|
||||||
|
|
||||||
// Stream reads from a source using a buffer size of n samples.
|
|
||||||
func Stream(source Source, n int) (<-chan *Buffer, StreamCancelFunc) {
|
|
||||||
channel := make(chan *Buffer, streamDoubleBufferSize)
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
go stream(ctx, channel, source, n)
|
|
||||||
return channel, StreamCancelFunc(cancel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func stream(ctx context.Context, stream chan<- *Buffer, source Source, n int) {
|
|
||||||
defer close(stream)
|
|
||||||
|
|
||||||
buffers := make([]*Buffer, streamDoubleBufferSize)
|
|
||||||
for i := 0; i < streamDoubleBufferSize; i++ {
|
|
||||||
buffers[i] = NewBuffer(source.Format(), source.SampleRate(), n, source.Channels())
|
|
||||||
}
|
|
||||||
|
|
||||||
var bufferPos int
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer := buffers[bufferPos]
|
|
||||||
bufferPos = (bufferPos + 1) % streamDoubleBufferSize
|
|
||||||
if _, err := buffer.DecodeFrom(source); err != nil {
|
|
||||||
logrus.WithError(err).WithField("source", source).Warn("decode audio failed")
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case stream <- buffer:
|
|
||||||
default:
|
|
||||||
logrus.WithField("source", source).Trace("buffer overrun, host too slow?")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rate is the sampling rate.
|
|
||||||
type Rate int
|
|
||||||
|
|
||||||
// Frequency is the sampling frequency.
|
|
||||||
func (r Rate) Frequency() Frequency {
|
|
||||||
return 1 / Frequency(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Duration of n samples at this rate.
|
|
||||||
func (r Rate) Duration(n int) time.Duration {
|
|
||||||
return time.Second * time.Duration(n) / time.Duration(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Number of sample during duration d.
|
|
||||||
func (r Rate) Samples(d time.Duration) int {
|
|
||||||
return int(d * time.Duration(r) / time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Rate) String() string {
|
|
||||||
return strconv.FormatInt(int64(r), 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Frequency is a type alias for float64.
|
|
||||||
type Frequency float64
|
|
||||||
|
|
||||||
const (
|
|
||||||
Hz Frequency = 1
|
|
||||||
KHz Frequency = 1e3
|
|
||||||
MHz Frequency = 1e6
|
|
||||||
GHz Frequency = 1e9
|
|
||||||
THz Frequency = 1e12
|
|
||||||
)
|
|
||||||
|
|
||||||
func (f Frequency) String() string {
|
|
||||||
switch {
|
|
||||||
case f > THz:
|
|
||||||
return fmt.Sprintf("%gTHz", f/THz)
|
|
||||||
case f > GHz:
|
|
||||||
return fmt.Sprintf("%gGHz", f/GHz)
|
|
||||||
case f > MHz:
|
|
||||||
return fmt.Sprintf("%gMHz", f/MHz)
|
|
||||||
case f > KHz:
|
|
||||||
return fmt.Sprintf("%gkHz", f/KHz)
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("%gHz", f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rate is the sampling rate for this frequency.
|
|
||||||
func (r Frequency) Rate() Rate {
|
|
||||||
return Rate(1 / r)
|
|
||||||
}
|
|
||||||
-147
@@ -1,147 +0,0 @@
|
|||||||
package ui
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"image"
|
|
||||||
"image/color"
|
|
||||||
"image/png"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/nfnt/resize"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/ui/widget"
|
|
||||||
"github.com/BeatGlow/display"
|
|
||||||
"github.com/BeatGlow/display/draw"
|
|
||||||
|
|
||||||
_ "embed" // Embed binary files
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
logoBG = color.RGBA{R: 0x11, G: 0xff, B: 0xe3, A: 0xff}
|
|
||||||
logoFG = color.RGBA{R: 0x8a, G: 0x00, B: 0xc4, A: 0xff}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Boot renders the boot splash.
|
|
||||||
func Boot(dst display.Display) error {
|
|
||||||
logrus.WithField("display", dst).Info("Welcome to BeatGlow!")
|
|
||||||
|
|
||||||
var (
|
|
||||||
styles = StylesFor(dst.ColorModel())
|
|
||||||
bounds = dst.Bounds()
|
|
||||||
width = bounds.Dx()
|
|
||||||
height = bounds.Dy()
|
|
||||||
canvas = image.NewRGBA(bounds)
|
|
||||||
)
|
|
||||||
logrus.Infof("styles: %#+v", styles)
|
|
||||||
|
|
||||||
draw.Draw(canvas, bounds, styles.Boot.Background, image.Point{}, draw.Src)
|
|
||||||
if err := dst.Refresh(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fontSize := 24.0
|
|
||||||
switch {
|
|
||||||
case height >= 64:
|
|
||||||
fontSize = 36.0
|
|
||||||
case height >= 128:
|
|
||||||
fontSize = 48.0
|
|
||||||
}
|
|
||||||
|
|
||||||
font := styles.Boot.Font.WithPointSize(fontSize)
|
|
||||||
logoTextWidth, logoTextHeight := font.MeasureText("beatglow")
|
|
||||||
logoText := widget.NewText(image.Point{}, font, image.NewUniform(styles.Boot.Foreground), "beatglow")
|
|
||||||
logoText.Position = bounds.Size()
|
|
||||||
logoText.Position.X /= 2
|
|
||||||
logoText.Position.Y /= 2
|
|
||||||
logoText.Position.X -= logoTextWidth / 2
|
|
||||||
logoText.Position.Y -= logoTextHeight / 2
|
|
||||||
logoText.Render(dst)
|
|
||||||
|
|
||||||
border := bounds
|
|
||||||
border.Max.X--
|
|
||||||
border.Max.Y--
|
|
||||||
draw.Rectangle(dst, border, color.White)
|
|
||||||
|
|
||||||
if err := dst.Refresh(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
time.Sleep(250 * time.Millisecond)
|
|
||||||
|
|
||||||
var (
|
|
||||||
logoTextStep image.Point
|
|
||||||
logoTextStop image.Point
|
|
||||||
logoLoveMaxX uint
|
|
||||||
logoLoveMaxY uint
|
|
||||||
logoLovePosition image.Point
|
|
||||||
logoLoveCenterX bool
|
|
||||||
logoLoveCenterY bool
|
|
||||||
)
|
|
||||||
switch {
|
|
||||||
case width == 256 && height == 64:
|
|
||||||
// Side by side
|
|
||||||
logoTextStep = image.Pt(-1, 0)
|
|
||||||
logoTextStop = image.Pt(2, logoText.Position.Y)
|
|
||||||
logoLoveMaxX = uint(width) / 2
|
|
||||||
logoLoveMaxY = uint(height)
|
|
||||||
logoLovePosition = image.Pt((width/4)*3, height/2) // center right
|
|
||||||
logoLoveCenterX = true
|
|
||||||
default:
|
|
||||||
// Scroll up
|
|
||||||
logoTextStep = image.Pt(0, -1)
|
|
||||||
logoTextStop = image.Pt(logoText.Position.X, 0)
|
|
||||||
logoLoveMaxX = uint(width)
|
|
||||||
logoLoveMaxY = uint(height / 2)
|
|
||||||
logoLovePosition = image.Pt(width/2, (height/4)*3) // bottom
|
|
||||||
logoLoveCenterY = true
|
|
||||||
}
|
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Millisecond)
|
|
||||||
for ; !logoText.Position.Eq(logoTextStop); logoText.Position = logoText.Position.Add(logoTextStep) {
|
|
||||||
draw.Draw(canvas, bounds, styles.Boot.Background, image.Point{}, draw.Src) // clear canvas
|
|
||||||
logoText.Render(canvas) // render logo
|
|
||||||
draw.Draw(dst, bounds, canvas, image.Point{}, draw.Src) // canvas to display
|
|
||||||
dst.Refresh() // display refresh
|
|
||||||
<-ticker.C
|
|
||||||
}
|
|
||||||
ticker.Stop()
|
|
||||||
|
|
||||||
logrus.Info("BeatGlow 💖 Volumio")
|
|
||||||
logoLove := resize.Thumbnail(logoLoveMaxX, logoLoveMaxY, logoVolumio, resize.Lanczos3)
|
|
||||||
|
|
||||||
//draw.Draw(canvas, bounds, image.NewUniform(color.Black), image.Point{}, draw.Src)
|
|
||||||
if logoLoveCenterX {
|
|
||||||
logoLovePosition.X -= logoLove.Bounds().Dx() / 2
|
|
||||||
}
|
|
||||||
if logoLoveCenterY {
|
|
||||||
logoLovePosition.Y -= logoLove.Bounds().Dy() / 2
|
|
||||||
}
|
|
||||||
draw.Draw(canvas, bounds.Add(logoLovePosition), logoLove, image.Point{}, draw.Src)
|
|
||||||
draw.Draw(dst, bounds, canvas, image.Point{}, draw.Src)
|
|
||||||
|
|
||||||
if err := dst.Refresh(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustDecodePNG(b []byte) image.Image {
|
|
||||||
i, err := png.Decode(bytes.NewBuffer(b))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
logoVolumio = mustDecodePNG(logoVolumioPNG)
|
|
||||||
logoMoode = mustDecodePNG(logoMoodePNG)
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed asset/logo-volumio.png
|
|
||||||
var logoVolumioPNG []byte
|
|
||||||
|
|
||||||
//go:embed asset/logo-moode.png
|
|
||||||
var logoMoodePNG []byte
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/cmplx"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/audio"
|
|
||||||
"github.com/BeatGlow/beatglow/draw"
|
|
||||||
"github.com/BeatGlow/beatglow/draw/pixel"
|
|
||||||
"github.com/BeatGlow/beatglow/internal/calc"
|
|
||||||
"github.com/BeatGlow/display"
|
|
||||||
"gonum.org/v1/gonum/dsp/fourier"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Analyzer struct {
|
|
||||||
display display.Display
|
|
||||||
canvas *draw.Canvas
|
|
||||||
rate audio.Rate
|
|
||||||
step int
|
|
||||||
fft *fourier.FFT
|
|
||||||
complex []complex128
|
|
||||||
samples []float64
|
|
||||||
levels []float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAnalyzer(display display.Display, rate audio.Rate, step int) *Analyzer {
|
|
||||||
return &Analyzer{
|
|
||||||
display: display,
|
|
||||||
canvas: draw.NewCanvas(display),
|
|
||||||
rate: rate,
|
|
||||||
step: step,
|
|
||||||
levels: make([]float64, display.Bounds().Dx()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) ProcessBuffer(buffer *audio.Buffer) {
|
|
||||||
a.frequencySpectrum(buffer.ToMono().Samples[0], a.rate, a.step)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) Halt() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Analyzer) Type() string {
|
|
||||||
return "visual:analyzer"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) Render() error {
|
|
||||||
//a.display.Clear()
|
|
||||||
|
|
||||||
for x, level := range a.levels {
|
|
||||||
h := int(56*level + .5)
|
|
||||||
draw.Line(a.display, pixel.On, x, 56-h, x+1, 56)
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.display.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) resize(n int) {
|
|
||||||
if s := n/2 + 1; len(a.complex) != s {
|
|
||||||
a.fft = fourier.NewFFT(n)
|
|
||||||
a.samples = make([]float64, n)
|
|
||||||
a.complex = make([]complex128, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) convert(samples []audio.Sample) {
|
|
||||||
for i, v := range samples {
|
|
||||||
a.samples[i] = float64(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) frequencySpectrum(samples []audio.Sample, rate audio.Rate, step int) error {
|
|
||||||
n := len(samples)
|
|
||||||
a.resize(n)
|
|
||||||
a.convert(samples)
|
|
||||||
a.fft.Coefficients(a.complex, a.samples)
|
|
||||||
|
|
||||||
/*
|
|
||||||
if err := transform(csamples); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
fmt.Printf("%d: %#+v", len(a.complex), a.complex)
|
|
||||||
freqSamplingStep := float64(rate) / float64(n)
|
|
||||||
scaleStep := float64(step) / freqSamplingStep
|
|
||||||
freqLimit := float64(rate) / 2.0
|
|
||||||
|
|
||||||
for i := 0.0; i*freqSamplingStep <= freqLimit; i += scaleStep {
|
|
||||||
//result[int(i*freqSamplingStep)] = math.Abs(real(a.complex[int(i)])) // cmplx.Abs(a.complex[int(i)])
|
|
||||||
a.levels[int(i*freqSamplingStep)] = cmplx.Abs(a.complex[int(i)])
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
for i := 0; i < a.display.Bounds().Size().X; i++ {
|
|
||||||
o := i << 1
|
|
||||||
a.levels[i] = (cmplx.Abs(a.complex[o]) + cmplx.Abs(a.complex[o+1])) / 2
|
|
||||||
}
|
|
||||||
calc.Hamming(a.levels, a.levels)
|
|
||||||
|
|
||||||
a.normalizeSpectrum()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Analyzer) normalizeSpectrum() {
|
|
||||||
max := calc.Max(a.levels)
|
|
||||||
if max > 0 {
|
|
||||||
for i := range a.levels {
|
|
||||||
a.levels[i] /= max
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image"
|
|
||||||
|
|
||||||
"github.com/nfnt/resize"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/player"
|
|
||||||
"github.com/BeatGlow/beatglow/ui"
|
|
||||||
"github.com/BeatGlow/display"
|
|
||||||
"github.com/BeatGlow/display/draw"
|
|
||||||
|
|
||||||
_ "embed"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Art struct {
|
|
||||||
display display.Display
|
|
||||||
styles ui.Styles
|
|
||||||
player player.Player
|
|
||||||
size uint
|
|
||||||
track *player.Track
|
|
||||||
icon image.Image
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewArt(display display.Display, player player.Player) *Art {
|
|
||||||
size := uint(display.Bounds().Dx())
|
|
||||||
icon := resize.Thumbnail(size, size, ui.MustDecodePNG(recordPNG), resize.Lanczos3)
|
|
||||||
return &Art{
|
|
||||||
display: display,
|
|
||||||
styles: ui.StylesFor(display.ColorModel()),
|
|
||||||
player: player,
|
|
||||||
size: size,
|
|
||||||
icon: icon,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Art) Halt() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Art) Type() string {
|
|
||||||
return "art"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Art) Render() error {
|
|
||||||
logrus.WithField("visual", "art").Debugf("render %s", v.display.Bounds())
|
|
||||||
return v.display.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Art) TrackChanged(track *player.Track) {
|
|
||||||
logrus.WithField("visual", "art").Debug("track changed")
|
|
||||||
v.track = track
|
|
||||||
v.display.Clear()
|
|
||||||
draw.Draw(v.display, v.display.Bounds(), v.icon, image.Point{}, draw.Src)
|
|
||||||
if track != nil {
|
|
||||||
go v.request(track)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Art) request(track *player.Track) {
|
|
||||||
log := logrus.WithFields(logrus.Fields{
|
|
||||||
"visual": "art",
|
|
||||||
"player": v.player.Type(),
|
|
||||||
})
|
|
||||||
|
|
||||||
p, ok := v.player.(player.AlbumArt)
|
|
||||||
if ok {
|
|
||||||
log.Debug("requesting album art")
|
|
||||||
|
|
||||||
var i image.Image
|
|
||||||
if i, ok = p.AlbumArt(track); ok {
|
|
||||||
thumbnail := resize.Thumbnail(v.size, v.size, i, resize.Lanczos2)
|
|
||||||
logrus.WithField("visual", "playing").Debugf("track album art %s", thumbnail.Bounds().Size())
|
|
||||||
centered := v.display.Bounds().Size().Sub(thumbnail.Bounds().Size())
|
|
||||||
centered.X /= 2
|
|
||||||
centered.Y /= 2
|
|
||||||
draw.Draw(v.display, thumbnail.Bounds().Add(centered), thumbnail, image.Point{}, draw.Src)
|
|
||||||
} else {
|
|
||||||
log.Debug("track album art unavailable")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Debug("player doesn't support album art")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:embed asset/record.png
|
|
||||||
var recordPNG []byte
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/ui"
|
|
||||||
"github.com/BeatGlow/beatglow/ui/font"
|
|
||||||
"github.com/BeatGlow/display"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Offline struct {
|
|
||||||
since time.Time
|
|
||||||
display display.Display
|
|
||||||
styles ui.Styles
|
|
||||||
x, y int
|
|
||||||
w, h int
|
|
||||||
dx, dy bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOffline(display display.Display) *Offline {
|
|
||||||
size := display.Bounds().Size()
|
|
||||||
return &Offline{
|
|
||||||
since: time.Now(),
|
|
||||||
display: display,
|
|
||||||
styles: ui.StylesFor(display.ColorModel()),
|
|
||||||
w: size.X - 3,
|
|
||||||
h: size.Y - 3,
|
|
||||||
x: rand.Int() % (size.X - 3),
|
|
||||||
y: rand.Int() % (size.Y - 3),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Offline) Halt() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Offline) Type() string {
|
|
||||||
return "offline"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Offline) Render() error {
|
|
||||||
v.display.Clear()
|
|
||||||
since := (time.Since(v.since) / time.Second) * time.Second
|
|
||||||
font.MicroGrotesk.Draw(v.display, image.Point{1, 24}, image.NewUniform(v.styles.Boot.Foreground), "Player offline!")
|
|
||||||
font.Monaco.Draw(v.display, image.Point{1, 40}, image.NewUniform(v.styles.Boot.Foreground), fmt.Sprintf("for %s", since))
|
|
||||||
return v.display.Refresh()
|
|
||||||
}
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/draw"
|
|
||||||
"github.com/BeatGlow/beatglow/draw/pixel"
|
|
||||||
"github.com/BeatGlow/beatglow/player"
|
|
||||||
"github.com/BeatGlow/beatglow/ui"
|
|
||||||
"github.com/BeatGlow/display"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
playingTitleY = 12
|
|
||||||
playingArtistY = 30
|
|
||||||
)
|
|
||||||
|
|
||||||
type Playing struct {
|
|
||||||
display display.Display
|
|
||||||
canvas *draw.Canvas
|
|
||||||
bounds image.Rectangle
|
|
||||||
styles ui.Styles
|
|
||||||
|
|
||||||
status struct {
|
|
||||||
player *player.Status
|
|
||||||
track *player.Track
|
|
||||||
}
|
|
||||||
|
|
||||||
scroll *draw.Scroller
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPlaying(display display.Display) *Playing {
|
|
||||||
size := display.Bounds().Size()
|
|
||||||
styles := ui.StylesFor(display.ColorModel())
|
|
||||||
|
|
||||||
v := &Playing{
|
|
||||||
display: display,
|
|
||||||
canvas: draw.NewCanvas(display).SetStyle(styles.Track),
|
|
||||||
bounds: display.Bounds(),
|
|
||||||
styles: styles,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup font sizes
|
|
||||||
v.styles.Track.Font.SetPointSize(24)
|
|
||||||
v.styles.Progress.Font.SetPointSize(9)
|
|
||||||
|
|
||||||
// Setup scroller
|
|
||||||
v.scroll = draw.NewScroller(display, size.X, true)
|
|
||||||
v.scroll.Canvas.SetStyle(v.styles.Track)
|
|
||||||
|
|
||||||
// Player offline text
|
|
||||||
v.Update(nil)
|
|
||||||
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Playing) Halt() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Playing) Type() string {
|
|
||||||
return "playing"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Playing) Render() error {
|
|
||||||
v.display.Clear()
|
|
||||||
|
|
||||||
var (
|
|
||||||
rows = [...]int{
|
|
||||||
0, // warnings (?)
|
|
||||||
12, // title
|
|
||||||
30, // artist
|
|
||||||
55, // status
|
|
||||||
43, // progress
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
fonts = [...]*font.Font{
|
|
||||||
font.Monaco.WithPointSize(8),
|
|
||||||
font.MicroGrotesk.WithPointSize(16),
|
|
||||||
font.MicroGrotesk.WithPointSize(12),
|
|
||||||
font.Monaco.WithPointSize(8),
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
fonts = [...]*font.Font{
|
|
||||||
font.Fixed5x7,
|
|
||||||
font.Unifont,
|
|
||||||
font.Fixed5x7,
|
|
||||||
font.Fixed5x7,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
|
|
||||||
v.scroll.Advance()
|
|
||||||
|
|
||||||
var (
|
|
||||||
bounds = v.display.Bounds()
|
|
||||||
width = bounds.Dx()
|
|
||||||
status = v.status.player
|
|
||||||
track = v.status.track
|
|
||||||
)
|
|
||||||
|
|
||||||
if status != nil {
|
|
||||||
var (
|
|
||||||
format = "Dunno"
|
|
||||||
elapsedText = "--:-- / --:--"
|
|
||||||
progress float64
|
|
||||||
)
|
|
||||||
|
|
||||||
if track != nil {
|
|
||||||
elapsedText = fmt.Sprintf("%s / %s", hms(status.Elapsed), hms(track.Duration))
|
|
||||||
progress = float64(status.Elapsed) / float64(track.Duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
if status.Format.Encoding != "" {
|
|
||||||
format = strings.ToUpper(status.Format.Encoding)
|
|
||||||
} else if track != nil && track.Path != "" {
|
|
||||||
format = strings.ToUpper(filepath.Ext(track.Path)[1:])
|
|
||||||
}
|
|
||||||
//format += fmt.Sprintf("-%d", status.Format.BitRate)
|
|
||||||
|
|
||||||
v.canvas.WithStyle(v.styles.Progress, func() {
|
|
||||||
v.canvas.Text(1, 0, format)
|
|
||||||
v.canvas.Text(40, 0, elapsedText)
|
|
||||||
v.canvas.WithGradient(width-120-2, 8, func() {
|
|
||||||
v.canvas.Progess(120, 0, width-120-2, progress)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if status.Paused {
|
|
||||||
draw.Sprite(v.display, pixel.On, 1, rows[3], pauseSprite)
|
|
||||||
} else {
|
|
||||||
draw.Sprite(v.display, pixel.On, 1, rows[3], playSprite)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.display.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Playing) TrackChanged(track *player.Track) {
|
|
||||||
logrus.WithField("visual", "playing").Debug("track changed")
|
|
||||||
if track == nil {
|
|
||||||
v.scroll.SetDirection(0)
|
|
||||||
} else {
|
|
||||||
v.scroll.SetDirection(+1)
|
|
||||||
switch {
|
|
||||||
case track.Artist != "" && track.Title != "":
|
|
||||||
v.scroll.Text(0, playingTitleY, fmt.Sprintf("%s - %s", track.Artist, track.Title))
|
|
||||||
case track.Title != "":
|
|
||||||
v.scroll.Text(0, playingTitleY, fmt.Sprintf("Unknown Artist - %s", track.Title))
|
|
||||||
case track.Artist != "":
|
|
||||||
v.scroll.Text(0, playingTitleY, fmt.Sprintf("%s - Unknown", track.Title))
|
|
||||||
default:
|
|
||||||
v.scroll.Text(0, playingTitleY, "Unknown")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v.scroll.Reset()
|
|
||||||
v.status.track = track
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Playing) StatusChanged(status *player.Status) {
|
|
||||||
logrus.WithField("visual", "playing").Debug("status changed")
|
|
||||||
v.status.player = status
|
|
||||||
}
|
|
||||||
|
|
||||||
func hms(d time.Duration) string {
|
|
||||||
var (
|
|
||||||
v = int(d / time.Second)
|
|
||||||
h = v / 3600
|
|
||||||
m = (v - h*3600) / 60
|
|
||||||
s = (v - m*60)
|
|
||||||
)
|
|
||||||
if h == 0 {
|
|
||||||
return fmt.Sprintf("%02d:%02d", m, s)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%02d:%02d:%02d", h, m, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Playing) Update(status *player.Status) {
|
|
||||||
v.status.player = status
|
|
||||||
|
|
||||||
if status == nil {
|
|
||||||
v.scroll.Text(0, playingTitleY, "Player is offline")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
playSprite = []byte{8, 8, 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00}
|
|
||||||
pauseSprite = []byte{8, 8, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x7F, 0x7F, 0x00}
|
|
||||||
repeatSprite = []byte{8, 8, 0x00, 0x79, 0x7B, 0x63, 0x63, 0x63, 0x6F, 0x2F}
|
|
||||||
volumeSprite = []byte{8, 8, 0x00, 0x18, 0x18, 0x3C, 0x7E, 0xFF, 0x00, 0x00}
|
|
||||||
)
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/BeatGlow/beatglow/hardware"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Visual interface {
|
|
||||||
hardware.Driver
|
|
||||||
|
|
||||||
Render() error
|
|
||||||
}
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
package visual
|
|
||||||
|
|
||||||
var vumeterBackground = [2][]uint8{{
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8,
|
|
||||||
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8, 0xf8,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00,
|
|
||||||
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0,
|
|
||||||
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
|
|
||||||
0xc0, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x0f, 0x00,
|
|
||||||
0x0f, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0x04, 0x04,
|
|
||||||
0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04, 0x04, 0xfc, 0x04, 0x04, 0x00,
|
|
||||||
0x00, 0xfc, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04,
|
|
||||||
0x04, 0xfc, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x24,
|
|
||||||
0x24, 0x24, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0xc0, 0x3c, 0x00, 0x00, 0xfc, 0x24, 0x24, 0x24, 0x00,
|
|
||||||
0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
|
|
||||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
|
|
||||||
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x1c,
|
|
||||||
0x00, 0x7e, 0x4a, 0x4a, 0x42, 0x00, 0x7c, 0x12, 0x12, 0x7c, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
|
||||||
}, {
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8,
|
|
||||||
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8, 0xf8,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00,
|
|
||||||
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0,
|
|
||||||
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
|
|
||||||
0xc0, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x0f, 0x00,
|
|
||||||
0x0f, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0x04, 0x04,
|
|
||||||
0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04, 0x04, 0xfc, 0x04, 0x04, 0x00,
|
|
||||||
0x00, 0xfc, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04,
|
|
||||||
0x04, 0xfc, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x24,
|
|
||||||
0x24, 0x24, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0xc0, 0x3c, 0x00, 0x00, 0xfc, 0x24, 0x24, 0x24, 0x00,
|
|
||||||
0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
|
|
||||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
|
|
||||||
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x1c,
|
|
||||||
0x00, 0x7e, 0x4a, 0x4a, 0x42, 0x00, 0x7c, 0x12, 0x12, 0x7c, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
|
||||||
}}
|
|
||||||
|
|
||||||
var vumeterBackgroundVU = [2][]uint8{{
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf0, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50,
|
|
||||||
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x78, 0x41, 0x41, 0x41, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x41, 0x40, 0x79, 0x41, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79,
|
|
||||||
0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79, 0x01, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x79,
|
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60,
|
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x01,
|
|
||||||
0xc0, 0x4e, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0xc2, 0x02, 0xc2, 0x42, 0xce, 0x00, 0xc0, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
|
||||||
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
|
||||||
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x3e,
|
|
||||||
0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
|
||||||
}, {
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x1f, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04,
|
|
||||||
0x50, 0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
|
|
||||||
0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x10, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x01, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
|
||||||
0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
|
||||||
0x79, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x01, 0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41,
|
|
||||||
0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x40, 0x79, 0x41, 0x41,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x78, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x40, 0xce, 0x02, 0xc2, 0x42, 0xc2, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x4e, 0xc0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x07,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
|
||||||
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
|
||||||
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x7e, 0x22, 0x22, 0x3e, 0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00,
|
|
||||||
0x7e, 0x08, 0x08, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
}}
|
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"image/color/palette"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -162,3 +163,56 @@ func (i imageView) Set(x, y int, c color.Color) {
|
|||||||
}
|
}
|
||||||
i.Image.Set(x, y, c)
|
i.Image.Set(x, y, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PaletteFor(model color.Model) color.Palette {
|
||||||
|
var p color.Palette
|
||||||
|
|
||||||
|
switch model {
|
||||||
|
case pixel.MonoModel:
|
||||||
|
p = color.Palette{
|
||||||
|
pixel.Off,
|
||||||
|
pixel.On,
|
||||||
|
}
|
||||||
|
|
||||||
|
case pixel.Gray2Model:
|
||||||
|
p = color.Palette{
|
||||||
|
pixel.Gray2{Y: 0},
|
||||||
|
pixel.Gray2{Y: 1},
|
||||||
|
pixel.Gray2{Y: 2},
|
||||||
|
pixel.Gray2{Y: 3},
|
||||||
|
}
|
||||||
|
|
||||||
|
case pixel.Gray4Model:
|
||||||
|
p = color.Palette{
|
||||||
|
pixel.Gray4{Y: 0x0}, pixel.Gray4{Y: 0x1}, pixel.Gray4{Y: 0x2}, pixel.Gray4{Y: 0x3},
|
||||||
|
pixel.Gray4{Y: 0x4}, pixel.Gray4{Y: 0x5}, pixel.Gray4{Y: 0x6}, pixel.Gray4{Y: 0x7},
|
||||||
|
pixel.Gray4{Y: 0x8}, pixel.Gray4{Y: 0x9}, pixel.Gray4{Y: 0xa}, pixel.Gray4{Y: 0xb},
|
||||||
|
pixel.Gray4{Y: 0xc}, pixel.Gray4{Y: 0xd}, pixel.Gray4{Y: 0xe}, pixel.Gray4{Y: 0xf},
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
// TODO(maze): implement color quantization
|
||||||
|
return palette.Plan9
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to RGBA.
|
||||||
|
for i, c := range p {
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
p[i] = color.RGBA{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8), A: 0xFF}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImageToPaletted(dst *image.Paletted, src image.Image, palette color.Palette) *image.Paletted {
|
||||||
|
if palette == nil {
|
||||||
|
palette = PaletteFor(src.ColorModel())
|
||||||
|
}
|
||||||
|
|
||||||
|
if dst == nil {
|
||||||
|
dst = image.NewPaletted(src.Bounds(), palette)
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageCopy(dst, src)
|
||||||
|
|
||||||
|
return dst
|
||||||
|
}
|
||||||
+13
-36
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/BeatGlow/beatglow/app"
|
"github.com/BeatGlow/beatglow/app"
|
||||||
"github.com/BeatGlow/beatglow/app/font"
|
"github.com/BeatGlow/beatglow/app/font"
|
||||||
"github.com/BeatGlow/beatglow/app/widget"
|
"github.com/BeatGlow/beatglow/app/widget"
|
||||||
|
"github.com/BeatGlow/beatglow/config"
|
||||||
"github.com/BeatGlow/beatglow/player"
|
"github.com/BeatGlow/beatglow/player"
|
||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
@@ -31,6 +32,7 @@ const (
|
|||||||
|
|
||||||
type playing struct {
|
type playing struct {
|
||||||
base
|
base
|
||||||
|
settings *config.Settings
|
||||||
phonesWidget *widget.Text
|
phonesWidget *widget.Text
|
||||||
formatRate bool
|
formatRate bool
|
||||||
formatText string
|
formatText string
|
||||||
@@ -53,6 +55,7 @@ func Playing(ctx app.Context) app.Layout {
|
|||||||
styles := app.StylesFor(ctx.Display().ColorModel())
|
styles := app.StylesFor(ctx.Display().ColorModel())
|
||||||
layout := &playing{
|
layout := &playing{
|
||||||
base: base{name: "playing"},
|
base: base{name: "playing"},
|
||||||
|
settings: ctx.Settings(),
|
||||||
phonesWidget: widget.NewText(image.Pt(10, 12)),
|
phonesWidget: widget.NewText(image.Pt(10, 12)),
|
||||||
formatText: formatTextPlaceholder,
|
formatText: formatTextPlaceholder,
|
||||||
formatWidget: widget.NewText(image.Pt(2+len(formatTextPlaceholder)*9, 12)),
|
formatWidget: widget.NewText(image.Pt(2+len(formatTextPlaceholder)*9, 12)),
|
||||||
@@ -129,46 +132,20 @@ func Playing(ctx app.Context) app.Layout {
|
|||||||
return layout
|
return layout
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (l *playing) log() *logrus.Entry {
|
|
||||||
return logrus.WithField("layout", "playing")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (playing) String() string {
|
|
||||||
return "playing"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *playing) Hide(ctx app.Context) {
|
|
||||||
log := l.log()
|
|
||||||
log.Debug("hide")
|
|
||||||
for _, widget := range l.Widgets() {
|
|
||||||
log.WithField("widget", widget.String()).Debug("hide widget")
|
|
||||||
_ = widget.Hide(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *playing) Show(ctx app.Context) {
|
func (l *playing) Show(ctx app.Context) {
|
||||||
log := l.log()
|
channels := 2
|
||||||
log.Debug("show")
|
if l.settings.Spectrum.Mono {
|
||||||
for _, widget := range l.Widgets() {
|
channels = 1
|
||||||
log.WithField("widget", widget.String()).Debug("show widget")
|
|
||||||
_ = widget.Show(ctx)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (l *playing) Widgets() []app.Widget {
|
l.spectrumWidget.
|
||||||
return []app.Widget{
|
SetWaterfall(l.settings.Spectrum.Waterfall).
|
||||||
l.phonesWidget,
|
SetChannels(channels).
|
||||||
l.formatWidget,
|
SetHold(int(l.settings.Spectrum.Hold)).
|
||||||
l.iconWidget,
|
SetRange(l.settings.Spectrum.MinFrequency, l.settings.Spectrum.MaxFrequency)
|
||||||
l.durationWidget,
|
|
||||||
l.trackWidget,
|
l.base.Show(ctx)
|
||||||
l.artWidget,
|
|
||||||
l.spectrumWidget,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
||||||
if track == nil {
|
if track == nil {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"periph.io/x/host/v3"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/BeatGlow/config"
|
|
||||||
"github.com/BeatGlow/BeatGlow/hardware"
|
|
||||||
"github.com/BeatGlow/BeatGlow/ui"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if _, err := host.Init(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
output, err := hardware.Display(&config.DisplayConfig{
|
|
||||||
Mode: "SPI",
|
|
||||||
Type: "SSD1322",
|
|
||||||
Reset: "GPIO25",
|
|
||||||
DC: "GPIO24",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if err = ui.Boot(output); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
defaultPath := filepath.Join(os.ExpandEnv("$HOME"), "/.beatglow-settings.conf")
|
|
||||||
settingsFileFlag := flag.String("settings", defaultPath, "User settings file")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
settings := config.LoadUserSettings(*settingsFileFlag)
|
|
||||||
if err := config.SaveUserSettings(*settingsFileFlag, settings); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/hardware"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
|
||||||
|
|
||||||
wifi, err := hardware.WirelessNetworkInfo()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("no wireless:", err)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("wireless: %s %s @ %s %ddBm\n", wifi.Name, wifi.IP, wifi.WirelessSSID, wifi.WirelessLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
wired, err := hardware.WiredNetworkInfo()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("no wired:", err)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("wired: %s %s\n", wired.Name, wired.IP)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/player"
|
|
||||||
"github.com/BeatGlow/beatglow/player/mpd"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
|
||||||
|
|
||||||
p, err := mpd.New("localhost:6600", "")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer p.Halt()
|
|
||||||
|
|
||||||
events, err := p.Events()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for event := range events {
|
|
||||||
fmt.Println("event: ", event)
|
|
||||||
switch event.(type) {
|
|
||||||
case player.ConnectedEvent:
|
|
||||||
fmt.Println("connected, requesting playlist...")
|
|
||||||
|
|
||||||
tracks, err := p.Playlist()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("%d tracks:\n", len(tracks))
|
|
||||||
for _, track := range tracks {
|
|
||||||
fmt.Println(" ", track.ID, track)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+56
-5
@@ -2,12 +2,16 @@ package beatglow
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"image/color"
|
||||||
|
"image/gif"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/BeatGlow/audio"
|
"github.com/BeatGlow/audio"
|
||||||
|
|
||||||
|
"github.com/BeatGlow/beatglow/app"
|
||||||
"github.com/BeatGlow/beatglow/app/layout"
|
"github.com/BeatGlow/beatglow/app/layout"
|
||||||
"github.com/BeatGlow/beatglow/config"
|
"github.com/BeatGlow/beatglow/config"
|
||||||
"github.com/BeatGlow/beatglow/hardware"
|
"github.com/BeatGlow/beatglow/hardware"
|
||||||
@@ -17,9 +21,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
ctx controllerContext
|
ctx controllerContext
|
||||||
encoder input.Encoder
|
encoder input.Encoder
|
||||||
frameRate time.Duration
|
frameRate time.Duration
|
||||||
|
recorder *gif.GIF
|
||||||
|
recorderStart time.Time
|
||||||
|
recorderFrames int
|
||||||
|
recorderPalette color.Palette
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *config.Config) (*Controller, error) {
|
func New(config *config.Config) (*Controller, error) {
|
||||||
@@ -29,12 +37,18 @@ func New(config *config.Config) (*Controller, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &Controller{}
|
c := &Controller{
|
||||||
|
recorderStart: time.Now().Add(10 * time.Second),
|
||||||
|
recorderFrames: 100,
|
||||||
|
}
|
||||||
|
|
||||||
if err := c.configureDisplay(log, &config.Display); err != nil {
|
if err := c.configureDisplay(log, &config.Display); err != nil {
|
||||||
log.WithError(err).Error("fatal error setting up display")
|
log.WithError(err).Error("fatal error setting up display")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
c.recorderPalette = app.PaletteFor(c.ctx.display.ColorModel())
|
||||||
|
log.Debugf("palette (%d colors): %+v", len(c.recorderPalette), c.recorderPalette)
|
||||||
|
|
||||||
if err := c.configureAudio(&config.Audio); err != nil {
|
if err := c.configureAudio(&config.Audio); err != nil {
|
||||||
log.WithError(err).Error("fatal error setting up audio source")
|
log.WithError(err).Error("fatal error setting up audio source")
|
||||||
c.teardown(log)
|
c.teardown(log)
|
||||||
@@ -166,7 +180,7 @@ func (c *Controller) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) onFrame(_ time.Time) {
|
func (c *Controller) onFrame(now time.Time) {
|
||||||
var refresh bool
|
var refresh bool
|
||||||
for _, layout := range c.ctx.layouts {
|
for _, layout := range c.ctx.layouts {
|
||||||
for _, widget := range layout.Widgets() {
|
for _, widget := range layout.Widgets() {
|
||||||
@@ -183,11 +197,48 @@ func (c *Controller) onFrame(_ time.Time) {
|
|||||||
if err := c.ctx.display.Refresh(); err != nil {
|
if err := c.ctx.display.Refresh(); err != nil {
|
||||||
logrus.WithError(err).Warn("display refresh failed")
|
logrus.WithError(err).Warn("display refresh failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.recorder != nil {
|
||||||
|
c.recorder.Image = append(c.recorder.Image, app.ImageToPaletted(nil, c.ctx.display, c.recorderPalette))
|
||||||
|
c.recorder.Delay = append(c.recorder.Delay, int(now.Sub(c.recorderStart).Seconds()/1000))
|
||||||
|
if len(c.recorder.Image) > c.recorderFrames {
|
||||||
|
go c.recorderSave()
|
||||||
|
}
|
||||||
|
} else if now.After(c.recorderStart) {
|
||||||
|
logrus.Info("recorder starting")
|
||||||
|
c.recorder = new(gif.GIF)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logrus.Trace("display refresh skipped, widgets not changed")
|
logrus.Trace("display refresh skipped, widgets not changed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) recorderSave() {
|
||||||
|
r := c.recorder
|
||||||
|
c.recorder = nil
|
||||||
|
c.recorderStart = time.Now().Add(24000 * time.Hour) // never? :P
|
||||||
|
|
||||||
|
name := "beatglow-recording.gif"
|
||||||
|
log := logrus.WithField("path", name)
|
||||||
|
log.Debugf("saving %d frames", len(r.Image))
|
||||||
|
|
||||||
|
f, err := os.Create(name)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Warn("can't save recording")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = gif.EncodeAll(f, r); err != nil {
|
||||||
|
logrus.WithError(err).Warn("can't save recording")
|
||||||
|
_ = f.Close()
|
||||||
|
_ = os.Remove(name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Controller) onInput(log *logrus.Entry, event hardware.InputEvent) {
|
func (c *Controller) onInput(log *logrus.Entry, event hardware.InputEvent) {
|
||||||
log = log.WithField("event", event.String())
|
log = log.WithField("event", event.String())
|
||||||
log.Debug("input event")
|
log.Debug("input event")
|
||||||
|
|||||||
@@ -7,44 +7,32 @@ replace github.com/BeatGlow/audio => ../audio
|
|||||||
replace github.com/BeatGlow/display => ../display
|
replace github.com/BeatGlow/display => ../display
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.4.0
|
github.com/BeatGlow/audio v0.1.2
|
||||||
github.com/goki/freetype v1.0.5
|
github.com/BeatGlow/display v1.1.6
|
||||||
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
github.com/hashicorp/hcl/v2 v2.23.0
|
github.com/hashicorp/hcl/v2 v2.23.0
|
||||||
github.com/kyoh86/xdg v1.2.0
|
github.com/kyoh86/xdg v1.2.0
|
||||||
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12
|
github.com/makeworld-the-better-one/dither/v2 v2.4.0
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/zclconf/go-cty v1.16.0
|
github.com/urfave/cli/v3 v3.0.0-beta1
|
||||||
|
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be
|
||||||
golang.org/x/image v0.23.0
|
golang.org/x/image v0.23.0
|
||||||
golang.org/x/text v0.21.0
|
|
||||||
gonum.org/v1/gonum v0.15.1
|
|
||||||
periph.io/x/conn/v3 v3.7.1
|
periph.io/x/conn/v3 v3.7.1
|
||||||
periph.io/x/host/v3 v3.8.3
|
periph.io/x/host/v3 v3.8.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BeatGlow/audio v0.1.2 // indirect
|
|
||||||
github.com/BeatGlow/display v1.1.5 // indirect
|
|
||||||
github.com/abema/go-mp4 v1.4.0 // indirect
|
|
||||||
github.com/agext/levenshtein v1.2.1 // indirect
|
github.com/agext/levenshtein v1.2.1 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||||
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5 // indirect
|
|
||||||
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a // indirect
|
|
||||||
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606 // indirect
|
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.1.2 // indirect
|
|
||||||
github.com/icza/bitio v1.1.0 // indirect
|
|
||||||
github.com/makeworld-the-better-one/dither/v2 v2.4.0 // indirect
|
|
||||||
github.com/mazznoer/colorgrad v0.10.0 // indirect
|
|
||||||
github.com/mazznoer/csscolorparser v0.1.5 // indirect
|
|
||||||
github.com/mewkiz/flac v1.0.12 // indirect
|
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
github.com/zclconf/go-cty v1.16.0 // indirect
|
||||||
github.com/urfave/cli/v3 v3.0.0-beta1 // indirect
|
|
||||||
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be // indirect
|
|
||||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
|
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
|
||||||
golang.org/x/mod v0.22.0 // indirect
|
golang.org/x/mod v0.22.0 // indirect
|
||||||
golang.org/x/sync v0.10.0 // indirect
|
golang.org/x/sync v0.10.0 // indirect
|
||||||
golang.org/x/sys v0.29.0 // indirect
|
golang.org/x/sys v0.29.0 // indirect
|
||||||
|
golang.org/x/text v0.21.0 // indirect
|
||||||
golang.org/x/tools v0.29.0 // indirect
|
golang.org/x/tools v0.29.0 // indirect
|
||||||
)
|
)
|
||||||
@@ -1,148 +1,69 @@
|
|||||||
github.com/BeatGlow/display v0.0.0-20250120134219-4650b2392069 h1:gfN5oQQzEJngdeVrHlIk4Cy9AtQs1Vyqgdq9unaRkQI=
|
|
||||||
github.com/BeatGlow/display v0.0.0-20250120134219-4650b2392069/go.mod h1:9tdbycx202ruXPN1jheVULNlHFEV7bOy4hUj5pyGA30=
|
|
||||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
|
||||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
|
||||||
github.com/abema/go-mp4 v1.4.0 h1:n4plz1gLVon+fSPdfZHfCQnJDYXq33l5zF/Tb9O7U7o=
|
|
||||||
github.com/abema/go-mp4 v1.4.0/go.mod h1:vPl9t5ZK7K0x68jh12/+ECWBCXoWuIDtNgPtU2f04ws=
|
|
||||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||||
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
|
||||||
github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5 h1:caoskihCyJpXaV3oRLl+jYuE+aLRnfcIprUQ6oBxTh8=
|
|
||||||
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5/go.mod h1:ZcIrkf+E8KutUpAcNHOHaf2NYukHYOlYTCDxV5zzn04=
|
|
||||||
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a h1:wKFSDxAFrELZwZHfH8qL60cBUPx4k/As9rknIyS9HVI=
|
|
||||||
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a/go.mod h1:aEx53qKDtY1Ryywz6SVx/K+n3eVGB2tsijuntsITXzA=
|
|
||||||
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606 h1:1lyGjYJXpYkF6fGQbhAIOdIaeymKQuS6RJVLVlTzc5w=
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606 h1:1lyGjYJXpYkF6fGQbhAIOdIaeymKQuS6RJVLVlTzc5w=
|
||||||
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606/go.mod h1:KDYiP7UvrtHRqnVLE6ziKupbojinMHjFUdo+1VA7r/Q=
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606/go.mod h1:KDYiP7UvrtHRqnVLE6ziKupbojinMHjFUdo+1VA7r/Q=
|
||||||
github.com/goki/freetype v1.0.5 h1:yi2lQeUhXnBgSMqYd0vVmPw6RnnfIeTP3N4uvaJXd7A=
|
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||||
github.com/goki/freetype v1.0.5/go.mod h1:wKmKxddbzKmeci9K96Wknn5kjTWLyfC8tKOqAFbEX8E=
|
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
|
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
|
||||||
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
|
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
|
||||||
github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
|
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
|
||||||
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
|
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
|
||||||
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
|
|
||||||
github.com/jszwec/csvutil v1.5.1/go.mod h1:Rpu7Uu9giO9subDyMCIQfHVDuLrcaC36UA4YcJjGBkg=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI=
|
github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI=
|
||||||
github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs=
|
github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs=
|
||||||
github.com/luismesas/go-rpi v1.0.2 h1:qbtmG/pFgPtr7BiB1tR4O+5ODwBldBPoHuHDctQjnU8=
|
|
||||||
github.com/luismesas/go-rpi v1.0.2/go.mod h1:X5HClL0mGP2US8C2ISmJStxOW6WPSvmVDrnP9zNGthg=
|
|
||||||
github.com/luismesas/goPi v1.0.2 h1:JOtDgbru2ORpYQT2Ot0UwIBQMyxw84/bBlO7rkP2XhI=
|
|
||||||
github.com/luismesas/goPi v1.0.2/go.mod h1:uKBSNIiXHmmA1vNzKnlDt79VzpGygJ3XMWwhPuWH/F8=
|
|
||||||
github.com/makeworld-the-better-one/dither/v2 v2.4.0 h1:Az/dYXiTcwcRSe59Hzw4RI1rSnAZns+1msaCXetrMFE=
|
github.com/makeworld-the-better-one/dither/v2 v2.4.0 h1:Az/dYXiTcwcRSe59Hzw4RI1rSnAZns+1msaCXetrMFE=
|
||||||
github.com/makeworld-the-better-one/dither/v2 v2.4.0/go.mod h1:VBtN8DXO7SNtyGmLiGA7IsFeKrBkQPze1/iAeM95arc=
|
github.com/makeworld-the-better-one/dither/v2 v2.4.0/go.mod h1:VBtN8DXO7SNtyGmLiGA7IsFeKrBkQPze1/iAeM95arc=
|
||||||
github.com/mazznoer/colorgrad v0.10.0 h1:p2ImJimPGEUFhMrNx4EGSzkr2XARomIo1yyUgso3NDQ=
|
|
||||||
github.com/mazznoer/colorgrad v0.10.0/go.mod h1:1dkoC2jE1oMVr11umiBHfyHV/W+E+By2WJaPKJJ6Nkk=
|
|
||||||
github.com/mazznoer/csscolorparser v0.1.5 h1:Wr4uNIE+pHWN3TqZn2SGpA2nLRG064gB7WdSfSS5cz4=
|
|
||||||
github.com/mazznoer/csscolorparser v0.1.5/go.mod h1:OQRVvgCyHDCAquR1YWfSwwaDcM0LhnSffGnlbOew/3I=
|
|
||||||
github.com/mewkiz/flac v1.0.12 h1:5Y1BRlUebfiVXPmz7hDD7h3ceV2XNrGNMejNVjDpgPY=
|
|
||||||
github.com/mewkiz/flac v1.0.12/go.mod h1:1UeXlFRJp4ft2mfZnPLRpQTd7cSjb/s17o7JQzzyrCA=
|
|
||||||
github.com/mewkiz/pkg v0.0.0-20230226050401-4010bf0fec14/go.mod h1:QYCFBiH5q6XTHEbWhR0uhR3M9qNPoD2CSQzr0g75kE4=
|
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||||
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 h1:dd7vnTDfjtwCETZDrRe+GPYNLA1jBtbZeyfyE8eZCyk=
|
|
||||||
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12/go.mod h1:i/KKcxEWEO8Yyl11DYafRPKOPVYTrhxiTRigjtEEXZU=
|
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e/go.mod h1:nBdnFKj15wFbf94Rwfq4m30eAcyY9V/IyKAGQFtqkW0=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/sunfish-shogi/bufseekio v0.0.0-20210207115823-a4185644b365/go.mod h1:dEzdXgvImkQ3WLI+0KQpmEx8T/C/ma9KeS3AfmU899I=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
|
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
|
||||||
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
|
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be h1:qf05vm7CJA3tcnR42pv2a/+pvCPGylJcg10B9CRFPvg=
|
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be h1:qf05vm7CJA3tcnR42pv2a/+pvCPGylJcg10B9CRFPvg=
|
||||||
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be/go.mod h1:FWqHpmEj39kZYjkb4y+GkFRwJofD3lP2k8ataoNlo2Y=
|
github.com/zachomedia/go-bdf v0.0.0-20220611021443-a3af701111be/go.mod h1:FWqHpmEj39kZYjkb4y+GkFRwJofD3lP2k8ataoNlo2Y=
|
||||||
github.com/zclconf/go-cty v1.16.0 h1:xPKEhst+BW5D0wxebMZkxgapvOE/dw7bFTlgSc9nD6w=
|
github.com/zclconf/go-cty v1.16.0 h1:xPKEhst+BW5D0wxebMZkxgapvOE/dw7bFTlgSc9nD6w=
|
||||||
github.com/zclconf/go-cty v1.16.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
github.com/zclconf/go-cty v1.16.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
||||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
|
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
|
||||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
|
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
|
||||||
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
|
|
||||||
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
||||||
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
|
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
|
||||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
|
||||||
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
|
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
|
||||||
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
|
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0=
|
|
||||||
gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
periph.io/x/conn/v3 v3.7.1 h1:tMjNv3WO8jEz/ePuXl7y++2zYi8LsQ5otbmqGKy3Myg=
|
periph.io/x/conn/v3 v3.7.1 h1:tMjNv3WO8jEz/ePuXl7y++2zYi8LsQ5otbmqGKy3Myg=
|
||||||
periph.io/x/conn/v3 v3.7.1/go.mod h1:c+HCVjkzbf09XzcqZu/t+U8Ss/2QuJj0jgRF6Nye838=
|
periph.io/x/conn/v3 v3.7.1/go.mod h1:c+HCVjkzbf09XzcqZu/t+U8Ss/2QuJj0jgRF6Nye838=
|
||||||
periph.io/x/host/v3 v3.8.2 h1:ayKUDzgUCN0g8+/xM9GTkWaOBhSLVcVHGTfjAOi8OsQ=
|
|
||||||
periph.io/x/host/v3 v3.8.2/go.mod h1:yFL76AesNHR68PboofSWYaQTKmvPXsQH2Apvp/ls/K4=
|
|
||||||
periph.io/x/host/v3 v3.8.3 h1:v90ozCFDWgEyfNElZ+JnOvq0jAdW0vmgjCUy8dYXDds=
|
periph.io/x/host/v3 v3.8.3 h1:v90ozCFDWgEyfNElZ+JnOvq0jAdW0vmgjCUy8dYXDds=
|
||||||
periph.io/x/host/v3 v3.8.3/go.mod h1:uKrIpfXjELwHkwGBNe6aos//XiQ/3uxDa1P2BmLV6Ok=
|
periph.io/x/host/v3 v3.8.3/go.mod h1:uKrIpfXjELwHkwGBNe6aos//XiQ/3uxDa1P2BmLV6Ok=
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package fourier
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// ToComplex converts a slice of float64 into a slice of complex128, where the input
|
|
||||||
// slice's values are set as the real part of the complex numbers
|
|
||||||
//
|
|
||||||
// In Go, a complex number is a pair of two float numbers. This means that converting a
|
|
||||||
// float number to a complex number only makes it necessary to assign the (float's) value as
|
|
||||||
// the real part of the complex number, leaving the imaginary as zero.
|
|
||||||
//
|
|
||||||
// This particular function leverages that by creating a float slice of twice the size as the inputs, and
|
|
||||||
// placing each element of the input on every second slot. Finally, it casts this float slice as a complex slice,
|
|
||||||
// using an unsafe approach to prioritize performance.
|
|
||||||
func ToComplex(x []float64) []complex128 {
|
|
||||||
var (
|
|
||||||
length = len(x)
|
|
||||||
out = make([]float64, length*2)
|
|
||||||
)
|
|
||||||
|
|
||||||
for i, j := 0, 0; i < len(x); i, j = i+1, (i+1)*2 {
|
|
||||||
out[j] = x[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return (*(*[]complex128)(unsafe.Pointer(&out)))[:length]
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
package fourier
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/BeatGlow/BeatGlow/internal/dsp/fourier/window"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
tau = 2 * math.Pi
|
|
||||||
|
|
||||||
// DefaultMagnitudeThreshold describes the default value where a certain
|
|
||||||
// frequency is strong enough to be considered relevant to the spectrum filter.
|
|
||||||
DefaultMagnitudeThreshold = 10
|
|
||||||
)
|
|
||||||
|
|
||||||
// FrequencyPower denotes a single frequency and its magnitude in a Fast
|
|
||||||
// Fourier Transform of a signal.
|
|
||||||
type FrequencyPower struct {
|
|
||||||
Freq int
|
|
||||||
Mag float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply applies a Fast Fourier Transform (FFT) on a slice of float64 `data`,
|
|
||||||
// with sample rate `sampleRate`. It returns a slice of FrequencyPower.
|
|
||||||
func Apply(sampleRate int, data []float64, w window.Window) []FrequencyPower {
|
|
||||||
var (
|
|
||||||
ln = len(data)
|
|
||||||
magnitudes = make([]FrequencyPower, 0, (ln/2)-1)
|
|
||||||
)
|
|
||||||
|
|
||||||
// apply a window function to the values
|
|
||||||
if w != nil && len(w) == ln {
|
|
||||||
w.Apply(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply a fast Fourier transform on the data; exclude index 0, no 0Hz-freq results
|
|
||||||
spectrum := FFT(ToComplex(data))
|
|
||||||
|
|
||||||
for i := 1; i < ln/2; i++ {
|
|
||||||
freqReal := real(spectrum[i])
|
|
||||||
freqImag := imag(spectrum[i])
|
|
||||||
// map the magnitude for each frequency bin to the corresponding value in the map
|
|
||||||
// using math.Sqrt(re*re + im*im) is faster than using math.Hypot(re, im)
|
|
||||||
// see fft_test.go for details
|
|
||||||
magnitudes = append(
|
|
||||||
magnitudes,
|
|
||||||
FrequencyPower{
|
|
||||||
Freq: i * sampleRate / ln,
|
|
||||||
Mag: math.Sqrt(freqReal*freqReal + freqImag*freqImag),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return magnitudes
|
|
||||||
}
|
|
||||||
|
|
||||||
// FFT applies a Fast Fourier Transform to the input slice of complex128 values, to
|
|
||||||
// retrieve the frequency spectrum of a digital signal.
|
|
||||||
func FFT(value []complex128) []complex128 {
|
|
||||||
var (
|
|
||||||
valueLen = len(value)
|
|
||||||
factors = GetRadix2Factors(valueLen)
|
|
||||||
temp = make([]complex128, valueLen) // temp
|
|
||||||
)
|
|
||||||
|
|
||||||
value = ReorderData(value)
|
|
||||||
|
|
||||||
// stage increases by a power of two
|
|
||||||
for stage := 2; stage <= valueLen; stage <<= 1 {
|
|
||||||
var (
|
|
||||||
blocks = valueLen / stage
|
|
||||||
stage2Value = stage / 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// iterate through each item in the batch, increasing by the stage value
|
|
||||||
for batchIdx := 0; batchIdx < valueLen; batchIdx += stage {
|
|
||||||
if stage == 2 { // "first stage" scenario
|
|
||||||
var (
|
|
||||||
reorderIdx = value[batchIdx]
|
|
||||||
reorderNext = value[batchIdx+1]
|
|
||||||
)
|
|
||||||
|
|
||||||
temp[batchIdx] = reorderIdx + reorderNext
|
|
||||||
temp[batchIdx+1] = reorderIdx - reorderNext
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for iter := 0; iter < stage2Value; iter++ {
|
|
||||||
var (
|
|
||||||
idx = iter + batchIdx
|
|
||||||
idx2 = idx + stage2Value
|
|
||||||
reorderIdx = value[idx]
|
|
||||||
factorized = value[idx2] * factors[blocks*iter]
|
|
||||||
)
|
|
||||||
|
|
||||||
temp[idx] = reorderIdx + factorized
|
|
||||||
temp[idx2] = reorderIdx - factorized
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
value, temp = temp, value
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
// IFFT returns the Inverse Fast Fourier Transform of a given complex128 slice.
|
|
||||||
func IFFT(value []complex128) []complex128 {
|
|
||||||
var (
|
|
||||||
ln = len(value)
|
|
||||||
output = make([]complex128, ln)
|
|
||||||
factor = complex(float64(ln), 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reverse inputs, which is calculated with modulo factor, hence value[0] as an outlier
|
|
||||||
output[0] = value[0]
|
|
||||||
|
|
||||||
for i, j := 1, ln-1; i < ln; i, j = i+1, j-1 {
|
|
||||||
output[i] = value[j]
|
|
||||||
}
|
|
||||||
|
|
||||||
output = FFT(output)
|
|
||||||
|
|
||||||
for i := range output {
|
|
||||||
output[i] /= factor
|
|
||||||
}
|
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convolve returns the convolution of x ∗ y, applied to the complex128 slice x.
|
|
||||||
func Convolve(x, y []complex128) []complex128 {
|
|
||||||
if len(x) != len(y) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
x = FFT(x)
|
|
||||||
y = FFT(y)
|
|
||||||
|
|
||||||
for i := 0; i < len(x); i++ {
|
|
||||||
x[i] *= y[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return IFFT(x)
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package fourier
|
|
||||||
|
|
||||||
// Log2Types is a type constraint interface to scope the allowed types to
|
|
||||||
// call the Log2 function.
|
|
||||||
type Log2Types interface {
|
|
||||||
uint | uint16 | uint32 | uint64 | int | int16 | int32 | int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log2 returns the log base 2 of v, matching the input to precomputed
|
|
||||||
// values to achieve the fastest performance possible.
|
|
||||||
//
|
|
||||||
// If the input is not present, then its log2 value is computed with a fast
|
|
||||||
// bit-shifting technique.
|
|
||||||
//
|
|
||||||
// from: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
|
|
||||||
func Log2[T Log2Types](v T) T {
|
|
||||||
switch v {
|
|
||||||
case 0, 1:
|
|
||||||
return 0
|
|
||||||
case 2:
|
|
||||||
return 1
|
|
||||||
case 4:
|
|
||||||
return 2
|
|
||||||
case 8:
|
|
||||||
return 3
|
|
||||||
case 16:
|
|
||||||
return 4
|
|
||||||
case 32:
|
|
||||||
return 5
|
|
||||||
case 64:
|
|
||||||
return 6
|
|
||||||
case 128:
|
|
||||||
return 7
|
|
||||||
case 256:
|
|
||||||
return 8
|
|
||||||
case 512:
|
|
||||||
return 9
|
|
||||||
case 1024:
|
|
||||||
return 10
|
|
||||||
case 2048:
|
|
||||||
return 11
|
|
||||||
case 4096:
|
|
||||||
return 12
|
|
||||||
case 8192:
|
|
||||||
return 13
|
|
||||||
default:
|
|
||||||
return log2(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func log2[T Log2Types](v T) T {
|
|
||||||
var r T
|
|
||||||
for v >>= 1; v != 0; v >>= 1 {
|
|
||||||
r++
|
|
||||||
}
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package fourier
|
|
||||||
|
|
||||||
import "math"
|
|
||||||
|
|
||||||
const (
|
|
||||||
firstCur = 2048
|
|
||||||
firstPrev = 1024
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetRadix2Factors is temporarily public, could become private at a later point.
|
|
||||||
func GetRadix2Factors(inputLen int) []complex128 {
|
|
||||||
if factors, ok := radix2Factors[inputLen]; ok {
|
|
||||||
return factors
|
|
||||||
}
|
|
||||||
|
|
||||||
for factor, prev := firstCur, firstPrev; factor <= inputLen; factor, prev = factor<<1, factor {
|
|
||||||
if _, ok := radix2Factors[factor]; !ok {
|
|
||||||
radix2Factors[factor] = make([]complex128, factor)
|
|
||||||
for n, j := 0, 0; n < factor; n, j = n+2, j+1 {
|
|
||||||
radix2Factors[factor][n] = radix2Factors[prev][j]
|
|
||||||
}
|
|
||||||
|
|
||||||
for n := 1; n < factor; n += 2 {
|
|
||||||
v := -tau / float64(factor) * float64(n)
|
|
||||||
radix2Factors[factor][n] = complex(
|
|
||||||
math.Cos(v), math.Sin(v),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return radix2Factors[inputLen]
|
|
||||||
}
|
|
||||||
|
|
||||||
var radix2Factors = map[int][]complex128{
|
|
||||||
4: {1 + 0i, 0 - 1i, -1 + 0i, 0 + 1i},
|
|
||||||
8: {1 + 0i, 0.7071067811865476 - 0.7071067811865475i, 0 - 1i, -0.7071067811865475 - 0.7071067811865476i, -1 + 0i, -0.7071067811865477 + 0.7071067811865475i, 0 + 1i, 0.7071067811865475 + 0.7071067811865477i},
|
|
||||||
16: {1 + 0i, 0.9238795325112867 - 0.3826834323650898i, 0.7071067811865476 - 0.7071067811865475i, 0.38268343236508984 - 0.9238795325112867i, 0 - 1i, -0.3826834323650897 - 0.9238795325112867i, -0.7071067811865475 - 0.7071067811865476i, -0.9238795325112867 - 0.38268343236508984i, -1 + 0i, -0.9238795325112868 + 0.38268343236508967i, -0.7071067811865477 + 0.7071067811865475i, -0.38268343236509034 + 0.9238795325112865i, 0 + 1i, 0.38268343236509 + 0.9238795325112866i, 0.7071067811865475 + 0.7071067811865477i, 0.9238795325112865 + 0.3826834323650904i},
|
|
||||||
32: {1 + 0i, 0.9807852804032304 - 0.19509032201612825i, 0.9238795325112867 - 0.3826834323650898i, 0.8314696123025453 - 0.5555702330196022i, 0.7071067811865476 - 0.7071067811865475i, 0.5555702330196023 - 0.8314696123025452i, 0.38268343236508984 - 0.9238795325112867i, 0.1950903220161283 - 0.9807852804032304i, 0 - 1i, -0.1950903220161282 - 0.9807852804032304i, -0.3826834323650897 - 0.9238795325112867i, -0.555570233019602 - 0.8314696123025453i, -0.7071067811865475 - 0.7071067811865476i, -0.8314696123025453 - 0.5555702330196021i, -0.9238795325112867 - 0.38268343236508984i, -0.9807852804032303 - 0.19509032201612858i, -1 + 0i, -0.9807852804032304 + 0.19509032201612836i, -0.9238795325112868 + 0.38268343236508967i, -0.8314696123025453 + 0.555570233019602i, -0.7071067811865477 + 0.7071067811865475i, -0.5555702330196022 + 0.8314696123025453i, -0.38268343236509034 + 0.9238795325112865i, -0.19509032201612866 + 0.9807852804032303i, 0 + 1i, 0.19509032201612828 + 0.9807852804032304i, 0.38268343236509 + 0.9238795325112866i, 0.5555702330196018 + 0.8314696123025455i, 0.7071067811865475 + 0.7071067811865477i, 0.8314696123025453 + 0.5555702330196022i, 0.9238795325112865 + 0.3826834323650904i, 0.9807852804032303 + 0.19509032201612872i},
|
|
||||||
64: {1 + 0i, 0.9951847266721968 - 0.0980171403295606i, 0.9807852804032304 - 0.19509032201612825i, 0.9569403357322088 - 0.29028467725446233i, 0.9238795325112867 - 0.3826834323650898i, 0.881921264348355 - 0.47139673682599764i, 0.8314696123025453 - 0.5555702330196022i, 0.773010453362737 - 0.6343932841636455i, 0.7071067811865476 - 0.7071067811865475i, 0.6343932841636456 - 0.7730104533627369i, 0.5555702330196023 - 0.8314696123025452i, 0.4713967368259978 - 0.8819212643483549i, 0.38268343236508984 - 0.9238795325112867i, 0.29028467725446233 - 0.9569403357322089i, 0.1950903220161283 - 0.9807852804032304i, 0.09801714032956077 - 0.9951847266721968i, 0 - 1i, -0.09801714032956066 - 0.9951847266721968i, -0.1950903220161282 - 0.9807852804032304i, -0.2902846772544622 - 0.9569403357322089i, -0.3826834323650897 - 0.9238795325112867i, -0.4713967368259977 - 0.8819212643483549i, -0.555570233019602 - 0.8314696123025453i, -0.6343932841636453 - 0.7730104533627371i, -0.7071067811865475 - 0.7071067811865476i, -0.773010453362737 - 0.6343932841636455i, -0.8314696123025453 - 0.5555702330196021i, -0.8819212643483549 - 0.4713967368259978i, -0.9238795325112867 - 0.38268343236508984i, -0.9569403357322088 - 0.29028467725446233i, -0.9807852804032303 - 0.19509032201612858i, -0.9951847266721968 - 0.09801714032956084i, -1 + 0i, -0.9951847266721968 + 0.09801714032956059i, -0.9807852804032304 + 0.19509032201612836i, -0.9569403357322089 + 0.29028467725446216i, -0.9238795325112868 + 0.38268343236508967i, -0.881921264348355 + 0.47139673682599764i, -0.8314696123025453 + 0.555570233019602i, -0.7730104533627371 + 0.6343932841636453i, -0.7071067811865477 + 0.7071067811865475i, -0.6343932841636459 + 0.7730104533627367i, -0.5555702330196022 + 0.8314696123025453i, -0.47139673682599786 + 0.8819212643483548i, -0.38268343236509034 + 0.9238795325112865i, -0.2902846772544624 + 0.9569403357322088i, -0.19509032201612866 + 0.9807852804032303i, -0.09801714032956045 + 0.9951847266721968i, 0 + 1i, 0.09801714032956009 + 0.9951847266721969i, 0.19509032201612828 + 0.9807852804032304i, 0.2902846772544621 + 0.9569403357322089i, 0.38268343236509 + 0.9238795325112866i, 0.4713967368259976 + 0.881921264348355i, 0.5555702330196018 + 0.8314696123025455i, 0.6343932841636456 + 0.7730104533627369i, 0.7071067811865475 + 0.7071067811865477i, 0.7730104533627367 + 0.6343932841636459i, 0.8314696123025453 + 0.5555702330196022i, 0.8819212643483548 + 0.4713967368259979i, 0.9238795325112865 + 0.3826834323650904i, 0.9569403357322088 + 0.29028467725446244i, 0.9807852804032303 + 0.19509032201612872i, 0.9951847266721968 + 0.09801714032956052i},
|
|
||||||
128: {1 + 0i, 0.9987954562051724 - 0.049067674327418015i, 0.9951847266721968 - 0.0980171403295606i, 0.989176509964781 - 0.14673047445536175i, 0.9807852804032304 - 0.19509032201612825i, 0.9700312531945441 - 0.24298017990326387i, 0.9569403357322088 - 0.29028467725446233i, 0.9415440651830208 - 0.33688985339222005i, 0.9238795325112867 - 0.3826834323650898i, 0.9039892931234433 - 0.4275550934302821i, 0.881921264348355 - 0.47139673682599764i, 0.8577286100002721 - 0.5141027441932217i, 0.8314696123025453 - 0.5555702330196022i, 0.8032075314806449 - 0.5956993044924334i, 0.773010453362737 - 0.6343932841636455i, 0.7409511253549591 - 0.6715589548470183i, 0.7071067811865476 - 0.7071067811865475i, 0.6715589548470184 - 0.7409511253549591i, 0.6343932841636456 - 0.7730104533627369i, 0.5956993044924335 - 0.8032075314806448i, 0.5555702330196023 - 0.8314696123025452i, 0.5141027441932218 - 0.8577286100002721i, 0.4713967368259978 - 0.8819212643483549i, 0.4275550934302822 - 0.9039892931234433i, 0.38268343236508984 - 0.9238795325112867i, 0.33688985339222005 - 0.9415440651830208i, 0.29028467725446233 - 0.9569403357322089i, 0.24298017990326398 - 0.970031253194544i, 0.1950903220161283 - 0.9807852804032304i, 0.14673047445536175 - 0.989176509964781i, 0.09801714032956077 - 0.9951847266721968i, 0.04906767432741813 - 0.9987954562051724i, 0 - 1i, -0.04906767432741801 - 0.9987954562051724i, -0.09801714032956066 - 0.9951847266721968i, -0.14673047445536164 - 0.989176509964781i, -0.1950903220161282 - 0.9807852804032304i, -0.24298017990326387 - 0.9700312531945441i, -0.2902846772544622 - 0.9569403357322089i, -0.33688985339221994 - 0.9415440651830209i, -0.3826834323650897 - 0.9238795325112867i, -0.42755509343028186 - 0.9039892931234434i, -0.4713967368259977 - 0.8819212643483549i, -0.5141027441932216 - 0.8577286100002722i, -0.555570233019602 - 0.8314696123025453i, -0.5956993044924332 - 0.8032075314806449i, -0.6343932841636453 - 0.7730104533627371i, -0.6715589548470184 - 0.7409511253549591i, -0.7071067811865475 - 0.7071067811865476i, -0.7409511253549589 - 0.6715589548470186i, -0.773010453362737 - 0.6343932841636455i, -0.8032075314806448 - 0.5956993044924335i, -0.8314696123025453 - 0.5555702330196021i, -0.8577286100002721 - 0.5141027441932218i, -0.8819212643483549 - 0.4713967368259978i, -0.9039892931234434 - 0.42755509343028203i, -0.9238795325112867 - 0.38268343236508984i, -0.9415440651830207 - 0.3368898533922203i, -0.9569403357322088 - 0.29028467725446233i, -0.970031253194544 - 0.24298017990326404i, -0.9807852804032303 - 0.19509032201612858i, -0.989176509964781 - 0.1467304744553618i, -0.9951847266721968 - 0.09801714032956084i, -0.9987954562051724 - 0.04906767432741797i, -1 + 0i, -0.9987954562051724 + 0.049067674327417724i, -0.9951847266721968 + 0.09801714032956059i, -0.989176509964781 + 0.14673047445536158i, -0.9807852804032304 + 0.19509032201612836i, -0.9700312531945441 + 0.24298017990326382i, -0.9569403357322089 + 0.29028467725446216i, -0.9415440651830208 + 0.3368898533922201i, -0.9238795325112868 + 0.38268343236508967i, -0.9039892931234436 + 0.4275550934302818i, -0.881921264348355 + 0.47139673682599764i, -0.8577286100002722 + 0.5141027441932216i, -0.8314696123025453 + 0.555570233019602i, -0.8032075314806449 + 0.5956993044924332i, -0.7730104533627371 + 0.6343932841636453i, -0.7409511253549591 + 0.6715589548470184i, -0.7071067811865477 + 0.7071067811865475i, -0.6715589548470187 + 0.7409511253549589i, -0.6343932841636459 + 0.7730104533627367i, -0.5956993044924332 + 0.803207531480645i, -0.5555702330196022 + 0.8314696123025453i, -0.5141027441932219 + 0.857728610000272i, -0.47139673682599786 + 0.8819212643483548i, -0.4275550934302825 + 0.9039892931234432i, -0.38268343236509034 + 0.9238795325112865i, -0.33688985339221994 + 0.9415440651830209i, -0.2902846772544624 + 0.9569403357322088i, -0.24298017990326412 + 0.970031253194544i, -0.19509032201612866 + 0.9807852804032303i, -0.14673047445536233 + 0.9891765099647809i, -0.09801714032956045 + 0.9951847266721968i, -0.04906767432741803 + 0.9987954562051724i, 0 + 1i, 0.04906767432741767 + 0.9987954562051724i, 0.09801714032956009 + 0.9951847266721969i, 0.14673047445536194 + 0.9891765099647809i, 0.19509032201612828 + 0.9807852804032304i, 0.24298017990326376 + 0.9700312531945441i, 0.2902846772544621 + 0.9569403357322089i, 0.3368898533922196 + 0.941544065183021i, 0.38268343236509 + 0.9238795325112866i, 0.4275550934302822 + 0.9039892931234433i, 0.4713967368259976 + 0.881921264348355i, 0.5141027441932214 + 0.8577286100002722i, 0.5555702330196018 + 0.8314696123025455i, 0.5956993044924328 + 0.8032075314806453i, 0.6343932841636456 + 0.7730104533627369i, 0.6715589548470183 + 0.7409511253549591i, 0.7071067811865475 + 0.7071067811865477i, 0.7409511253549589 + 0.6715589548470187i, 0.7730104533627367 + 0.6343932841636459i, 0.803207531480645 + 0.5956993044924332i, 0.8314696123025453 + 0.5555702330196022i, 0.857728610000272 + 0.5141027441932219i, 0.8819212643483548 + 0.4713967368259979i, 0.9039892931234431 + 0.427555093430282Line truncated
|
|
||||||
256: {1 + 0i, 0.9996988186962041 - 0.024541228522912288i, 0.9987954562051724 - 0.049067674327418015i, 0.9972904566786902 - 0.07356456359966743i, 0.9951847266721968 - 0.0980171403295606i, 0.9924795345987101 - 0.1224106751992162i, 0.989176509964781 - 0.14673047445536175i, 0.9852776423889412 - 0.17096188876030122i, 0.9807852804032304 - 0.19509032201612825i, 0.9757021300385286 - 0.2191012401568698i, 0.9700312531945441 - 0.24298017990326387i, 0.9637760657954398 - 0.26671275747489837i, 0.9569403357322088 - 0.29028467725446233i, 0.9495281805930367 - 0.3136817403988915i, 0.9415440651830208 - 0.33688985339222005i, 0.9329927988347388 - 0.3598950365349881i, 0.9238795325112867 - 0.3826834323650898i, 0.9142097557035307 - 0.40524131400498986i, 0.9039892931234433 - 0.4275550934302821i, 0.8932243011955153 - 0.44961132965460654i, 0.881921264348355 - 0.47139673682599764i, 0.8700869911087113 - 0.49289819222978404i, 0.8577286100002721 - 0.5141027441932217i, 0.8448535652497071 - 0.5349976198870972i, 0.8314696123025453 - 0.5555702330196022i, 0.8175848131515837 - 0.5758081914178453i, 0.8032075314806449 - 0.5956993044924334i, 0.7883464276266063 - 0.6152315905806268i, 0.773010453362737 - 0.6343932841636455i, 0.7572088465064846 - 0.6531728429537768i, 0.7409511253549591 - 0.6715589548470183i, 0.724247082951467 - 0.6895405447370669i, 0.7071067811865476 - 0.7071067811865475i, 0.6895405447370669 - 0.7242470829514668i, 0.6715589548470184 - 0.7409511253549591i, 0.6531728429537769 - 0.7572088465064845i, 0.6343932841636456 - 0.7730104533627369i, 0.6152315905806269 - 0.7883464276266062i, 0.5956993044924335 - 0.8032075314806448i, 0.5758081914178454 - 0.8175848131515836i, 0.5555702330196023 - 0.8314696123025452i, 0.5349976198870974 - 0.844853565249707i, 0.5141027441932218 - 0.8577286100002721i, 0.49289819222978415 - 0.8700869911087113i, 0.4713967368259978 - 0.8819212643483549i, 0.4496113296546066 - 0.8932243011955153i, 0.4275550934302822 - 0.9039892931234433i, 0.4052413140049898 - 0.9142097557035307i, 0.38268343236508984 - 0.9238795325112867i, 0.3598950365349883 - 0.9329927988347387i, 0.33688985339222005 - 0.9415440651830208i, 0.3136817403988915 - 0.9495281805930367i, 0.29028467725446233 - 0.9569403357322089i, 0.2667127574748984 - 0.9637760657954398i, 0.24298017990326398 - 0.970031253194544i, 0.21910124015686977 - 0.9757021300385286i, 0.1950903220161283 - 0.9807852804032304i, 0.17096188876030136 - 0.9852776423889412i, 0.14673047445536175 - 0.989176509964781i, 0.12241067519921628 - 0.9924795345987101i, 0.09801714032956077 - 0.9951847266721968i, 0.07356456359966745 - 0.9972904566786902i, 0.04906767432741813 - 0.9987954562051724i, 0.024541228522912267 - 0.9996988186962041i, 0 - 1i, -0.024541228522912142 - 0.9996988186962041i, -0.04906767432741801 - 0.9987954562051724i, -0.07356456359966734 - 0.9972904566786902i, -0.09801714032956066 - 0.9951847266721968i, -0.12241067519921617 - 0.9924795345987101i, -0.14673047445536164 - 0.989176509964781i, -0.17096188876030124 - 0.9852776423889412i, -0.1950903220161282 - 0.9807852804032304i, -0.21910124015686966 - 0.9757021300385286i, -0.24298017990326387 - 0.9700312531945441i, -0.2667127574748983 - 0.9637760657954398i, -0.2902846772544622 - 0.9569403357322089i, -0.31368174039889146 - 0.9495281805930367i, -0.33688985339221994 - 0.9415440651830209i, -0.35989503653498817 - 0.9329927988347388i, -0.3826834323650897 - 0.9238795325112867i, -0.40524131400498975 - 0.9142097557035308i, -0.42755509343028186 - 0.9039892931234434i, -0.4496113296546067 - 0.8932243011955153i, -0.4713967368259977 - 0.8819212643483549i, -0.4928981922297839 - 0.8700869911087115i, -0.5141027441932216 - 0.8577286100002722i, -0.5349976198870969 - 0.8448535652497072i, -0.555570233019602 - 0.8314696123025453i, -0.5758081914178453 - 0.8175848131515837i, -0.5956993044924332 - 0.8032075314806449i, -0.6152315905806267 - 0.7883464276266063i, -0.6343932841636453 - 0.7730104533627371i, -0.6531728429537765 - 0.7572088465064848i, -0.6715589548470184 - 0.7409511253549591i, -0.6895405447370669 - 0.724247082951467i, -0.7071067811865475 - 0.7071067811865476i, -0.7242470829514668 - 0.689540544737067i, -0.7409511253549589 - 0.6715589548470186i, -0.7572088465064847 - 0.6531728429537766i, -0.773010453362737 - 0.6343932841636455i, -0.7883464276266062 - 0.6152315905806269i, -0.8032075314806448 - 0.5956993044924335i, -0.8175848131515835 - 0.5758081914178454i, -0.8314696123025453 - 0.5555702330196021i, -0.8448535652497071 - 0.5349976198870972i, -0.8577286100002721 - 0.5141027441932218i, -0.8700869911087113 - 0.49289819222978415i, -0.8819212643483549 - 0.4713967368259978i, -0.8932243011955152 - 0.4496113296546069i, -0.9039892931234434 - 0.42755509343028203i, -0.9142097557035307 - 0.40524131400498986i, -0.9238795325112867 - 0.38268343236508984i, -0.9329927988347387 - 0.35989503653498833i, -0.9415440651830207 - 0.3368898533922203i, -0.9495281805930367 - 0.3136817403988914i, -0.9569403357322088 - 0.29028467725446233i, -0.9637760657954398 - 0.2667127574748985i, -0.97003125Line truncated
|
|
||||||
512: {1 + 0i, 0.9999247018391446 - 0.012271538285719925i, 0.9996988186962041 - 0.024541228522912288i, 0.9993223845883494 - 0.03680722294135883i, 0.9987954562051724 - 0.049067674327418015i, 0.9981181129001492 - 0.06132073630220858i, 0.9972904566786902 - 0.07356456359966743i, 0.996312612182778 - 0.0857973123444399i, 0.9951847266721968 - 0.0980171403295606i, 0.9939069700023561 - 0.11022220729388306i, 0.9924795345987101 - 0.1224106751992162i, 0.99090263542778 - 0.13458070850712617i, 0.989176509964781 - 0.14673047445536175i, 0.9873014181578584 - 0.15885814333386145i, 0.9852776423889412 - 0.17096188876030122i, 0.9831054874312164 - 0.18303988795514095i, 0.9807852804032304 - 0.19509032201612825i, 0.9783173707196277 - 0.20711137619221856i, 0.9757021300385286 - 0.2191012401568698i, 0.9729399522055602 - 0.2310581082806711i, 0.9700312531945441 - 0.24298017990326387i, 0.9669764710448521 - 0.25486565960451457i, 0.9637760657954398 - 0.26671275747489837i, 0.9604305194155658 - 0.27851968938505306i, 0.9569403357322088 - 0.29028467725446233i, 0.9533060403541938 - 0.3020059493192281i, 0.9495281805930367 - 0.3136817403988915i, 0.9456073253805213 - 0.3253102921622629i, 0.9415440651830208 - 0.33688985339222005i, 0.937339011912575 - 0.34841868024943456i, 0.9329927988347388 - 0.3598950365349881i, 0.9285060804732156 - 0.37131719395183754i, 0.9238795325112867 - 0.3826834323650898i, 0.9191138516900577 - 0.3939920400610481i, 0.9142097557035307 - 0.40524131400498986i, 0.9091679830905225 - 0.41642956009763715i, 0.9039892931234433 - 0.4275550934302821i, 0.8986744656939538 - 0.43861623853852766i, 0.8932243011955153 - 0.44961132965460654i, 0.8876396204028539 - 0.46053871095824i, 0.881921264348355 - 0.47139673682599764i, 0.8760700941954066 - 0.4821837720791227i, 0.8700869911087113 - 0.49289819222978404i, 0.8639728561215867 - 0.5035383837257176i, 0.8577286100002721 - 0.5141027441932217i, 0.8513551931052652 - 0.524589682678469i, 0.8448535652497071 - 0.5349976198870972i, 0.8382247055548381 - 0.5453249884220465i, 0.8314696123025453 - 0.5555702330196022i, 0.8245893027850253 - 0.5657318107836131i, 0.8175848131515837 - 0.5758081914178453i, 0.8104571982525948 - 0.5857978574564389i, 0.8032075314806449 - 0.5956993044924334i, 0.7958369046088836 - 0.6055110414043255i, 0.7883464276266063 - 0.6152315905806268i, 0.7807372285720945 - 0.6248594881423863i, 0.773010453362737 - 0.6343932841636455i, 0.765167265622459 - 0.6438315428897914i, 0.7572088465064846 - 0.6531728429537768i, 0.7491363945234594 - 0.6624157775901718i, 0.7409511253549591 - 0.6715589548470183i, 0.7326542716724129 - 0.680600997795453i, 0.724247082951467 - 0.6895405447370669i, 0.7157308252838186 - 0.6983762494089729i, 0.7071067811865476 - 0.7071067811865475i, 0.6983762494089729 - 0.7157308252838186i, 0.6895405447370669 - 0.7242470829514668i, 0.6806009977954531 - 0.7326542716724128i, 0.6715589548470184 - 0.7409511253549591i, 0.6624157775901718 - 0.7491363945234593i, 0.6531728429537769 - 0.7572088465064845i, 0.6438315428897915 - 0.765167265622459i, 0.6343932841636456 - 0.7730104533627369i, 0.6248594881423865 - 0.7807372285720944i, 0.6152315905806269 - 0.7883464276266062i, 0.6055110414043255 - 0.7958369046088835i, 0.5956993044924335 - 0.8032075314806448i, 0.585797857456439 - 0.8104571982525947i, 0.5758081914178454 - 0.8175848131515836i, 0.5657318107836132 - 0.8245893027850253i, 0.5555702330196023 - 0.8314696123025452i, 0.5453249884220466 - 0.838224705554838i, 0.5349976198870974 - 0.844853565249707i, 0.524589682678469 - 0.8513551931052652i, 0.5141027441932218 - 0.8577286100002721i, 0.5035383837257176 - 0.8639728561215866i, 0.49289819222978415 - 0.8700869911087113i, 0.4821837720791229 - 0.8760700941954065i, 0.4713967368259978 - 0.8819212643483549i, 0.46053871095824 - 0.8876396204028539i, 0.4496113296546066 - 0.8932243011955153i, 0.43861623853852766 - 0.8986744656939538i, 0.4275550934302822 - 0.9039892931234433i, 0.4164295600976373 - 0.9091679830905224i, 0.4052413140049898 - 0.9142097557035307i, 0.3939920400610481 - 0.9191138516900577i, 0.38268343236508984 - 0.9238795325112867i, 0.3713171939518376 - 0.9285060804732156i, 0.3598950365349883 - 0.9329927988347387i, 0.3484186802494345 - 0.937339011912575i, 0.33688985339222005 - 0.9415440651830208i, 0.325310292162263 - 0.9456073253805213i, 0.3136817403988915 - 0.9495281805930367i, 0.3020059493192282 - 0.9533060403541938i, 0.29028467725446233 - 0.9569403357322089i, 0.27851968938505306 - 0.9604305194155658i, 0.2667127574748984 - 0.9637760657954398i, 0.2548656596045146 - 0.9669764710448521i, 0.24298017990326398 - 0.970031253194544i, 0.23105810828067125 - 0.9729399522055602i, 0.21910124015686977 - 0.9757021300385286i, 0.20711137619221856 - 0.9783173707196277i, 0.1950903220161283 - 0.9807852804032304i, 0.18303988795514103 - 0.9831054874312164i, 0.17096188876030136 - 0.9852776423889412i, 0.1588581433338614 - 0.9873014181578584i, 0.14673047445536175 - 0.989176509964781i, 0.13458070850712622 - 0.99090263542778i, 0.12241067519921628 - 0.9924795345987101i, 0.11022Line truncated
|
|
||||||
1024: {1 + 0i, 0.9999811752826011 - 0.006135884649154475i, 0.9999247018391446 - 0.012271538285719925i, 0.9998305817958234 - 0.01840672990580482i, 0.9996988186962041 - 0.024541228522912288i, 0.9995294175010931 - 0.030674803176636626i, 0.9993223845883494 - 0.03680722294135883i, 0.9990777277526454 - 0.04293825693494082i, 0.9987954562051724 - 0.049067674327418015i, 0.9984755805732948 - 0.05519524434968994i, 0.9981181129001492 - 0.06132073630220858i, 0.9977230666441916 - 0.06744391956366405i, 0.9972904566786902 - 0.07356456359966743i, 0.9968202992911658 - 0.07968243797143013i, 0.996312612182778 - 0.0857973123444399i, 0.9957674144676598 - 0.09190895649713272i, 0.9951847266721968 - 0.0980171403295606i, 0.9945645707342554 - 0.10412163387205459i, 0.9939069700023561 - 0.11022220729388306i, 0.9932119492347945 - 0.11631863091190475i, 0.9924795345987101 - 0.1224106751992162i, 0.9917097536690995 - 0.12849811079379317i, 0.99090263542778 - 0.13458070850712617i, 0.9900582102622971 - 0.1406582393328492i, 0.989176509964781 - 0.14673047445536175i, 0.9882575677307495 - 0.15279718525844344i, 0.9873014181578584 - 0.15885814333386145i, 0.9863080972445987 - 0.16491312048996992i, 0.9852776423889412 - 0.17096188876030122i, 0.984210092386929 - 0.17700422041214875i, 0.9831054874312164 - 0.18303988795514095i, 0.9819638691095552 - 0.1890686641498062i, 0.9807852804032304 - 0.19509032201612825i, 0.9795697656854406 - 0.2011046348420919i, 0.9783173707196277 - 0.20711137619221856i, 0.9770281426577543 - 0.21311031991609136i, 0.9757021300385286 - 0.2191012401568698i, 0.9743393827855759 - 0.22508391135979283i, 0.9729399522055602 - 0.2310581082806711i, 0.9715038909862518 - 0.2370236059943672i, 0.9700312531945441 - 0.24298017990326387i, 0.9685220942744173 - 0.24892760574572015i, 0.9669764710448521 - 0.25486565960451457i, 0.9653944416976894 - 0.2607941179152755i, 0.9637760657954398 - 0.26671275747489837i, 0.9621214042690416 - 0.272621355449949i, 0.9604305194155658 - 0.27851968938505306i, 0.9587034748958715 - 0.2844075372112719i, 0.9569403357322088 - 0.29028467725446233i, 0.9551411683057708 - 0.2961508882436238i, 0.9533060403541938 - 0.3020059493192281i, 0.9514350209690083 - 0.30784964004153487i, 0.9495281805930367 - 0.3136817403988915i, 0.9475855910177412 - 0.3195020308160157i, 0.9456073253805213 - 0.3253102921622629i, 0.9435934581619604 - 0.33110630575987643i, 0.9415440651830208 - 0.33688985339222005i, 0.9394592236021899 - 0.3426607173119944i, 0.937339011912575 - 0.34841868024943456i, 0.9351835099389476 - 0.35416352542049034i, 0.9329927988347388 - 0.3598950365349881i, 0.9307669610789837 - 0.36561299780477385i, 0.9285060804732156 - 0.37131719395183754i, 0.9262102421383114 - 0.37700741021641826i, 0.9238795325112867 - 0.3826834323650898i, 0.921514039342042 - 0.38834504669882625i, 0.9191138516900577 - 0.3939920400610481i, 0.9166790599210427 - 0.3996241998456468i, 0.9142097557035307 - 0.40524131400498986i, 0.9117060320054299 - 0.4108431710579039i, 0.9091679830905225 - 0.41642956009763715i, 0.9065957045149153 - 0.4220002707997997i, 0.9039892931234433 - 0.4275550934302821i, 0.901348847046022 - 0.43309381885315196i, 0.8986744656939538 - 0.43861623853852766i, 0.8959662497561852 - 0.4441221445704292i, 0.8932243011955153 - 0.44961132965460654i, 0.8904487232447579 - 0.45508358712634384i, 0.8876396204028539 - 0.46053871095824i, 0.8847970984309378 - 0.4659764957679662i, 0.881921264348355 - 0.47139673682599764i, 0.8790122264286335 - 0.4767992300633221i, 0.8760700941954066 - 0.4821837720791227i, 0.8730949784182901 - 0.487550160148436i, 0.8700869911087113 - 0.49289819222978404i, 0.8670462455156926 - 0.49822766697278187i, 0.8639728561215867 - 0.5035383837257176i, 0.8608669386377673 - 0.508830142543107i, 0.8577286100002721 - 0.5141027441932217i, 0.8545579883654005 - 0.5193559901655896i, 0.8513551931052652 - 0.524589682678469i, 0.8481203448032972 - 0.5298036246862946i, 0.8448535652497071 - 0.5349976198870972i, 0.8415549774368984 - 0.5401714727298929i, 0.8382247055548381 - 0.5453249884220465i, 0.8348628749863801 - 0.5504579729366048i, 0.8314696123025453 - 0.5555702330196022i, 0.8280450452577557 - 0.560661576197336i, 0.8245893027850253 - 0.5657318107836131i, 0.8211025149911046 - 0.5707807458869673i, 0.8175848131515837 - 0.5758081914178453i, 0.8140363297059484 - 0.5808139580957645i, 0.8104571982525948 - 0.5857978574564389i, 0.8068475535437993 - 0.5907597018588742i, 0.8032075314806449 - 0.5956993044924334i, 0.799537269107905 - 0.600616479383869i, 0.7958369046088836 - 0.6055110414043255i, 0.7921065773002124 - 0.6103828062763095i, 0.7883464276266063 - 0.6152315905806268i, 0.7845565971555752 - 0.6200572117632891i, 0.7807372285720945 - 0.6248594881423863i, 0.7768884656732324 - 0.629638238914927i, 0.773010453362737 - 0.6343932841636455i, 0.7691033376455796 - 0.6391244448637757i, 0.765167265622459 - 0.6438315428897914i, 0.7612023854842618 - 0.6485144010221124i, 0.7572088465064846 - 0.6531728429537768i, 0.7531867990436125 - 0.6578066932970786i, 0.7491363945234594 - 0.66241577Line truncated
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package fourier
|
|
||||||
|
|
||||||
// RevBitsTypes is a type constraint interface to scope the allowed types to
|
|
||||||
// call the ReverseBits function.
|
|
||||||
type RevBitsTypes interface {
|
|
||||||
uint | uint16 | uint32 | uint64 | int | int16 | int32 | int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReverseFirstBits returns the first `size` bits of `value` in reverse order
|
|
||||||
// from: http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious
|
|
||||||
func ReverseFirstBits[T RevBitsTypes](value, size T) (reverse T) {
|
|
||||||
for ; value > 0; value, size = value>>1, size-1 {
|
|
||||||
reverse <<= 1 // left shift
|
|
||||||
reverse |= value & 1 // add next bit
|
|
||||||
}
|
|
||||||
|
|
||||||
return reverse << size
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReverseBits returns the bits of `value` in reverse order
|
|
||||||
// from: http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious
|
|
||||||
func ReverseBits[T RevBitsTypes](value T) (reverse T) {
|
|
||||||
for ; value > 0; value >>= 1 {
|
|
||||||
reverse <<= 1 // left shift
|
|
||||||
reverse |= value & 1 // add next bit
|
|
||||||
}
|
|
||||||
|
|
||||||
return reverse
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReorderData shuffles the input complex128 values to re-order it,
|
|
||||||
// setting the first half of the slice in even indexes and the last half
|
|
||||||
// of the slice in odd indexes.
|
|
||||||
func ReorderData(value []complex128) []complex128 {
|
|
||||||
var (
|
|
||||||
ln = len(value)
|
|
||||||
reorder = make([]complex128, ln)
|
|
||||||
sizeLog = Log2(ln)
|
|
||||||
)
|
|
||||||
|
|
||||||
for i := range value {
|
|
||||||
reorder[ReverseFirstBits(i, sizeLog)] = value[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return reorder
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,54 +0,0 @@
|
|||||||
package window
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
minBlockSize = 4
|
|
||||||
tau = math.Pi * 2
|
|
||||||
twoTau = math.Pi * 4
|
|
||||||
)
|
|
||||||
|
|
||||||
// GeneratorFunc is a type of function that generates a Window based on an input size.
|
|
||||||
type GeneratorFunc func(int) Window
|
|
||||||
|
|
||||||
// Generate calls the GeneratorFunc itself, with the input int `size`.
|
|
||||||
func (w GeneratorFunc) Generate(size int) Window {
|
|
||||||
return w(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Window is a custom type for a slice of float64, that repesents a Window that shapes
|
|
||||||
// input signal.
|
|
||||||
type Window []float64
|
|
||||||
|
|
||||||
// Apply will go through the input slice of float64 values, and apply the window to it by
|
|
||||||
// multiplying the value by the ratio in the respective element in the Window.
|
|
||||||
func (w Window) Apply(value []float64) {
|
|
||||||
for idx := range value {
|
|
||||||
value[idx] *= w[idx]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint:gochecknoglobals // immutable slice that contains supported block sizes
|
|
||||||
var blockSizes = []int{8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}
|
|
||||||
|
|
||||||
// New creates a new Window from the input GeneratorFunc and size
|
|
||||||
//
|
|
||||||
// The size should be a power of two supported in the fft package's BlockSize.
|
|
||||||
//
|
|
||||||
// In case the input size `int` is not a power of two, it will fallback to the next
|
|
||||||
// available block size, with a series of bit-shifting operations on the input size
|
|
||||||
// to derive the closest element in the (private) blockSizes slice of ints.
|
|
||||||
func New(w GeneratorFunc, size int) Window {
|
|
||||||
var (
|
|
||||||
count int
|
|
||||||
blockSize = size >> minBlockSize
|
|
||||||
)
|
|
||||||
|
|
||||||
for i := blockSize; i > 0; i >>= 1 {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
|
|
||||||
return w(blockSizes[count])
|
|
||||||
}
|
|
||||||
@@ -1,348 +0,0 @@
|
|||||||
// Copyright 2021 the u-root Authors. All rights reserved
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package spidev wraps the Linux spidev driver and performs low-level SPI
|
|
||||||
// operations.
|
|
||||||
package spidev
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
// See Linux "include/uapi/linux/spi/spidev.h" and
|
|
||||||
// "Documentation/spi/spidev.rst"
|
|
||||||
|
|
||||||
// Various ioctl numbers.
|
|
||||||
const (
|
|
||||||
iocRdMode = 0x80016b01
|
|
||||||
iocWrMode = 0x40016b01
|
|
||||||
iocRdLSBFirst = 0x80016b02
|
|
||||||
iocWrLSBFirst = 0x40016b02
|
|
||||||
iocRdBitsPerWord = 0x80016b03
|
|
||||||
iocWrBitsPerWord = 0x40016b03
|
|
||||||
iocRdMaxSpeedHz = 0x80046b04
|
|
||||||
iocWrMaxSpeedHz = 0x40046b04
|
|
||||||
iocRdMode32 = 0x80046b05
|
|
||||||
iocWrMode32 = 0x40046b05
|
|
||||||
)
|
|
||||||
|
|
||||||
// Constants used by iocMessage function.
|
|
||||||
const (
|
|
||||||
// iocMessage0 is the length of a message of 0 length. Use the
|
|
||||||
// iocMessage(n) function for an iocMessage of length n.
|
|
||||||
iocMessage0 = 0x40006b00
|
|
||||||
sizeBits = 14
|
|
||||||
sizeShift = 16
|
|
||||||
sizeMask = ((1 << sizeBits) - 1) << sizeShift
|
|
||||||
)
|
|
||||||
|
|
||||||
// maxTransferSize is the maximum size of a transfer. This is limited by the
|
|
||||||
// `length uint32` in the iocTransfer struct.
|
|
||||||
var maxTransferSize = math.MaxInt32
|
|
||||||
|
|
||||||
// iocMessage is an ioctl number for n Transfers. Since the ioctl number
|
|
||||||
// contains the size of the message, it is not a constant.
|
|
||||||
func iocMessage(n int) uint32 {
|
|
||||||
size := uint32(n * binary.Size(iocTransfer{}))
|
|
||||||
if n < 0 || size > (1<<sizeBits) {
|
|
||||||
return iocMessage(0)
|
|
||||||
}
|
|
||||||
return iocMessage0 | (size << sizeShift)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode is a bitset of the current SPI mode bits.
|
|
||||||
type Mode uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
// CPHA determines clock phase sampling (1=trailing edge).
|
|
||||||
CPHA Mode = 1 << iota
|
|
||||||
// CPOL determines clock polarity (1=idle high).
|
|
||||||
CPOL
|
|
||||||
// CS_HIGH determines chip select polarity (1=idle high).
|
|
||||||
CS_HIGH
|
|
||||||
// LSB_FIRST determines whether least significant bit comes first in a
|
|
||||||
// word (1=LSB first).
|
|
||||||
LSB_FIRST
|
|
||||||
// THREE_WIRE determines whether the bus operates in three wire mode
|
|
||||||
// (1=three wire).
|
|
||||||
THREE_WIRE
|
|
||||||
// LOOP determines whether the device should loop (1=loop enabled).
|
|
||||||
LOOP
|
|
||||||
// NO_CS determines whether to disable chip select (1=no chip select).
|
|
||||||
NO_CS
|
|
||||||
// READY determins ready mode bit.
|
|
||||||
READY
|
|
||||||
// TX_DUAL determines whether to transmit in dual mode.
|
|
||||||
TX_DUAL
|
|
||||||
// TX_QUAD determines whether to transmit in quad mode.
|
|
||||||
TX_QUAD
|
|
||||||
// RX_DUAL determines whether to receive in dual mode.
|
|
||||||
RX_DUAL
|
|
||||||
// RX_QUAD determines whether to receive in quad mode.
|
|
||||||
RX_QUAD
|
|
||||||
)
|
|
||||||
|
|
||||||
// iocTransfer is the data type used by the iocMessage ioctl. Multiple such
|
|
||||||
// transfers may be chained together in a single ioctl call.
|
|
||||||
type iocTransfer struct {
|
|
||||||
// txBuf contains the userspace address of data to send. If this is 0,
|
|
||||||
// then zeros are shifted onto the SPI bus.
|
|
||||||
txBuf uint64
|
|
||||||
// rxBuf contains the userspace address of data to receive. If this is
|
|
||||||
// 0, data received is ignored.
|
|
||||||
rxBuf uint64
|
|
||||||
// length is the length of max{transfer, txBuf, rxBuf} in bytes.
|
|
||||||
length uint32
|
|
||||||
|
|
||||||
speedHz uint32
|
|
||||||
delayUSecs uint16
|
|
||||||
bitsPerWord uint8
|
|
||||||
csChange uint8
|
|
||||||
txNBits uint8
|
|
||||||
rxNBits uint8
|
|
||||||
wordDelayUSecs uint8
|
|
||||||
pad uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer is the data and options for a single SPI transfer. Note that a SPI
|
|
||||||
// transfer is full-duplex meaning data is shifted out of Tx and shifted into
|
|
||||||
// Rx on the same clock cycle.
|
|
||||||
type Transfer struct {
|
|
||||||
// Tx contains a slice sent over the SPI bus.
|
|
||||||
Tx []byte
|
|
||||||
// Rx contains a slice received from the SPI bus.
|
|
||||||
Rx []byte
|
|
||||||
|
|
||||||
// The following temporarily override the SPI mode. They only apply to
|
|
||||||
// the current transfer.
|
|
||||||
|
|
||||||
// SpeedHz sets speed in Hz (optional).
|
|
||||||
SpeedHz uint32
|
|
||||||
// DelayUSecs is how long to delay before the next transfer (optional).
|
|
||||||
DelayUSecs uint16
|
|
||||||
// BitsPerWord is the device's wordsize (optional).
|
|
||||||
BitsPerWord uint8
|
|
||||||
// CSChange controls whether the CS (Chip Select) signal will be
|
|
||||||
// de-asserted at the end of the transfer.
|
|
||||||
CSChange bool
|
|
||||||
// TxNbits controls single, dual or quad mode (optional).
|
|
||||||
TxNBits uint8
|
|
||||||
// RxNbits controls single, dual or quad mode (optional).
|
|
||||||
RxNBits uint8
|
|
||||||
// WordDelayUSecs is the delay between words (optional).
|
|
||||||
WordDelayUSecs uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Transfer) String() string {
|
|
||||||
var x [8]byte
|
|
||||||
n, _ := io.ReadAtLeast(bytes.NewBuffer(t.Tx), x[:], len(x))
|
|
||||||
return fmt.Sprintf("%#02x...[:%d](%#02x)", x[:n], len(t.Tx), x[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrTxOverflow is returned if the Transfer buffer is too large.
|
|
||||||
type ErrTxOverflow struct {
|
|
||||||
TxLen, TxMax int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error implements the error interface.
|
|
||||||
func (e ErrTxOverflow) Error() string {
|
|
||||||
return fmt.Sprintf("SPI tx buffer overflow (%d > %d)", e.TxLen, e.TxMax)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrRxOverflow is returned if the Transfer buffer is too large.
|
|
||||||
type ErrRxOverflow struct {
|
|
||||||
RxLen, RxMax int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error implements the error interface.
|
|
||||||
func (e ErrRxOverflow) Error() string {
|
|
||||||
return fmt.Sprintf("SPI rx buffer overflow (%d > %d)", e.RxLen, e.RxMax)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrBufferMismatch is returned if the rx and tx buffers do not have equal
|
|
||||||
// length.
|
|
||||||
type ErrBufferMismatch struct {
|
|
||||||
TxLen, RxLen int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error implements the error interface.
|
|
||||||
func (e ErrBufferMismatch) Error() string {
|
|
||||||
return fmt.Sprintf("SPI tx and rx buffers of unequal length (%d != %d)", e.TxLen, e.RxLen)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SPI wraps the Linux device driver and provides low-level SPI operations.
|
|
||||||
type SPI struct {
|
|
||||||
f *os.File
|
|
||||||
// Used for mocking.
|
|
||||||
syscall func(trap, a1, a2 uintptr, a3 unsafe.Pointer) (r1, r2 uintptr, err unix.Errno)
|
|
||||||
// logger allows logging
|
|
||||||
logger func(string, ...any)
|
|
||||||
}
|
|
||||||
|
|
||||||
type opt func(s *SPI) error
|
|
||||||
|
|
||||||
// WithLogger returns an opt which can be used in Open to add
|
|
||||||
// a logger. A common usage would be:
|
|
||||||
// spidev.Open("/dev/spidev0.0", WithLogger(log.Printf))
|
|
||||||
func WithLogger(l func(string, ...any)) opt {
|
|
||||||
return func(s *SPI) error {
|
|
||||||
s.logger = l
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// safe tries to set "safe" settings for initial SPI operation.
|
|
||||||
// However, settings may not succeed, for $REASONS$.
|
|
||||||
// Hardware is highly variable.
|
|
||||||
// If there is an error, log it, and continue.
|
|
||||||
func (s *SPI) safe() {
|
|
||||||
if err := s.SetSpeedHz(500000); err != nil {
|
|
||||||
s.logger("warning only: set speed to %d HZ err %v", 500000, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open opens a new SPI device. dev is a filename such as "/dev/spidev0.0".
|
|
||||||
// Remember to call Close() once done.
|
|
||||||
func Open(dev string, opts ...opt) (*SPI, error) {
|
|
||||||
f, err := os.OpenFile(dev, os.O_RDWR, 0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s := &SPI{
|
|
||||||
f: f,
|
|
||||||
logger: func(string, ...any) {}, // log.Printf,
|
|
||||||
//logger: log.Printf,
|
|
||||||
// a3 must be an unsafe.Pointer instead of a uintptr, otherwise
|
|
||||||
// we cannot mock out in the test without creating a race
|
|
||||||
// condition. See `go doc unsafe.Pointer`.
|
|
||||||
syscall: func(trap, a1, a2 uintptr, a3 unsafe.Pointer) (r1, r2 uintptr, err unix.Errno) {
|
|
||||||
return unix.Syscall(trap, a1, a2, uintptr(a3))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, o := range opts {
|
|
||||||
if err := o(s); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.safe()
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the SPI device.
|
|
||||||
func (s *SPI) Close() error {
|
|
||||||
return s.f.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer performs multiple SPI reads and/or writes in a single function.
|
|
||||||
// See the Transfer struct for details.
|
|
||||||
func (s *SPI) Transfer(transfers []Transfer) error {
|
|
||||||
// Convert []Transfer to []iocTransfer.
|
|
||||||
it := make([]iocTransfer, len(transfers))
|
|
||||||
for i, t := range transfers {
|
|
||||||
s.logger("%d:%s", i, t.String())
|
|
||||||
it[i] = iocTransfer{
|
|
||||||
speedHz: t.SpeedHz,
|
|
||||||
delayUSecs: t.DelayUSecs,
|
|
||||||
bitsPerWord: t.BitsPerWord,
|
|
||||||
txNBits: t.TxNBits,
|
|
||||||
rxNBits: t.RxNBits,
|
|
||||||
wordDelayUSecs: t.WordDelayUSecs,
|
|
||||||
}
|
|
||||||
if len(t.Tx) > maxTransferSize {
|
|
||||||
return ErrTxOverflow{len(t.Tx), maxTransferSize}
|
|
||||||
}
|
|
||||||
if len(t.Rx) > maxTransferSize {
|
|
||||||
return ErrRxOverflow{len(t.Rx), maxTransferSize}
|
|
||||||
}
|
|
||||||
if len(t.Tx) != 0 && len(t.Rx) != 0 && len(t.Tx) != len(t.Rx) {
|
|
||||||
return ErrBufferMismatch{len(t.Tx), len(t.Rx)}
|
|
||||||
}
|
|
||||||
if len(t.Tx) != 0 {
|
|
||||||
txBuf := &transfers[i].Tx[0]
|
|
||||||
it[i].txBuf = uint64(uintptr(unsafe.Pointer(txBuf)))
|
|
||||||
it[i].length = uint32(len(t.Tx))
|
|
||||||
// Defer garbage collection until after the syscall.
|
|
||||||
defer runtime.KeepAlive(txBuf)
|
|
||||||
}
|
|
||||||
if len(t.Rx) != 0 {
|
|
||||||
rxBuf := &transfers[i].Rx[0]
|
|
||||||
it[i].rxBuf = uint64(uintptr(unsafe.Pointer(rxBuf)))
|
|
||||||
it[i].length = uint32(len(t.Rx))
|
|
||||||
// Defer garbage collection until after the syscall.
|
|
||||||
defer runtime.KeepAlive(rxBuf)
|
|
||||||
}
|
|
||||||
if transfers[i].CSChange {
|
|
||||||
it[i].csChange = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), uintptr(iocMessage(len(transfers))), unsafe.Pointer(&it[0])); err != 0 {
|
|
||||||
return os.NewSyscallError("ioctl(SPI_IOC_MESSAGE)", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode returns the Mode bitset.
|
|
||||||
func (s *SPI) Mode() (Mode, error) {
|
|
||||||
var m Mode
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdMode32, unsafe.Pointer(&m)); err != 0 {
|
|
||||||
return 0, os.NewSyscallError("ioctl(SPI_IOC_RD_MODE32)", err)
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMode sets the Mode bitset.
|
|
||||||
func (s *SPI) SetMode(m Mode) error {
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrMode32, unsafe.Pointer(&m)); err != 0 {
|
|
||||||
return os.NewSyscallError("ioctl(SPI_IOC_WR_MODE32)", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitsPerWord sets the number of bits per word. Myy understanding is this is
|
|
||||||
// only useful if there is a word delay.
|
|
||||||
func (s *SPI) BitsPerWord() (uint8, error) {
|
|
||||||
var bpw uint8
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdBitsPerWord, unsafe.Pointer(&bpw)); err != 0 {
|
|
||||||
return bpw, os.NewSyscallError("ioctl(SPI_IOC_RD_BITS_PER_WORD)", err)
|
|
||||||
}
|
|
||||||
return bpw, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBitsPerWord sets the number of bits per word.
|
|
||||||
func (s *SPI) SetBitsPerWord(bpw uint8) error {
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrBitsPerWord, unsafe.Pointer(&bpw)); err != 0 {
|
|
||||||
return os.NewSyscallError("ioctl(SPI_IOC_WR_BITS_PER_WORD)", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SpeedHz gets the transfer speed.
|
|
||||||
func (s *SPI) SpeedHz() (uint32, error) {
|
|
||||||
var hz uint32
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdMaxSpeedHz, unsafe.Pointer(&hz)); err != 0 {
|
|
||||||
return hz, os.NewSyscallError("ioctl(SPI_IOC_RD_MAX_SPEED_HZ)", err)
|
|
||||||
}
|
|
||||||
return hz, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSpeedHz sets the transfer speed.
|
|
||||||
func (s *SPI) SetSpeedHz(hz uint32) error {
|
|
||||||
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrMaxSpeedHz, unsafe.Pointer(&hz)); err != 0 {
|
|
||||||
return os.NewSyscallError("ioctl(SPI_IOC_WR_MAX_SPEED_HZ)", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user