Checkpoint
This commit is contained in:
125 files changed
+59376
No files matched your search
@@ -0,0 +1,115 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"git.maze.io/go/bragi/audio"
|
||||
"git.maze.io/go/bragi/hardware"
|
||||
"periph.io/x/conn/v3/physic"
|
||||
)
|
||||
|
||||
// Visualizer processes raw audio that can be rendered onto a display.
|
||||
type Visualizer interface {
|
||||
Process(audio.Slice)
|
||||
Render(dst draw.Image, origin image.Point, c color.Color)
|
||||
}
|
||||
|
||||
// Reader can read samples.
|
||||
type Reader interface {
|
||||
hardware.Resource
|
||||
|
||||
Channels() int
|
||||
SampleRate() physic.Frequency
|
||||
ReadSamples(audio.Slice) (int, error)
|
||||
}
|
||||
|
||||
type Filter interface {
|
||||
Filter(audio.Slice) audio.Slice
|
||||
}
|
||||
|
||||
type pcm16Reader struct {
|
||||
name string
|
||||
channels int
|
||||
sampleRate physic.Frequency
|
||||
rc io.ReadCloser
|
||||
byteOrder binary.ByteOrder
|
||||
b audio.Int16
|
||||
}
|
||||
|
||||
// OpenPCM16 reads from a raw linear 16-bit PCM file (or fifo).
|
||||
func OpenPCM16(name string, byteOrder binary.ByteOrder, channels int, sampleRate physic.Frequency) (Reader, error) {
|
||||
f, err := os.OpenFile(name, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pcm16Reader{
|
||||
name: name,
|
||||
channels: channels,
|
||||
sampleRate: sampleRate,
|
||||
rc: f,
|
||||
byteOrder: byteOrder,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// OpenPCM16TCP reads from a raw linear 16-bit PCM stream over TCP.
|
||||
func OpenPCM16TCP(addr string, byteOrder binary.ByteOrder, channels int, sampleRate physic.Frequency) (Reader, error) {
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pcm16Reader{
|
||||
name: "tcp://" + addr,
|
||||
channels: channels,
|
||||
sampleRate: sampleRate,
|
||||
rc: c,
|
||||
byteOrder: byteOrder,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *pcm16Reader) String() string {
|
||||
return fmt.Sprintf("pcm reader %s", r.name)
|
||||
}
|
||||
|
||||
func (r *pcm16Reader) Halt() error {
|
||||
return r.rc.Close()
|
||||
}
|
||||
|
||||
func (r *pcm16Reader) Channels() int {
|
||||
return r.channels
|
||||
}
|
||||
|
||||
func (r *pcm16Reader) SampleRate() physic.Frequency {
|
||||
return r.sampleRate
|
||||
}
|
||||
|
||||
func (r *pcm16Reader) ReadSamples(p audio.Slice) (n int, err error) {
|
||||
var (
|
||||
data audio.Int16
|
||||
ok bool
|
||||
)
|
||||
if data, ok = p.(audio.Int16); !ok {
|
||||
length := p.Len()
|
||||
if l := len(r.b); l < length {
|
||||
r.b = make(audio.Int16, p.Len())
|
||||
} else {
|
||||
r.b = r.b[:length]
|
||||
}
|
||||
data = r.b
|
||||
}
|
||||
if err = binary.Read(r.rc, r.byteOrder, &data); err != nil {
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
// Convert back
|
||||
r.b.CopyTo(p)
|
||||
}
|
||||
return p.Len(), nil
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"image/draw"
|
||||
)
|
||||
|
||||
func drawSprite(p draw.Image, x, y int, sprite []uint8, c color.Color) {
|
||||
/*
|
||||
for dy, row := range sprite {
|
||||
for dx := 0; dx < 8; dx++ {
|
||||
if row&(1<<(7-dx)) != 0 {
|
||||
p.Set(x+dx, y+dy, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
w, h, data := sprite[0], sprite[1], sprite[2:]
|
||||
for dy := 0; dy < int(h); dy++ {
|
||||
//pix := data[dy*int(w>>3):]
|
||||
for dx := 0; dx < int(w); dx++ {
|
||||
//b := pix[dx>>3]
|
||||
//if b&(1<<(7-(dx%8))) != 0 {
|
||||
// p.Set(x+dx, y+dy, c)
|
||||
//}
|
||||
byteOffset := int(dy/8)*int(w) + dx
|
||||
bitOffset := dy % 8
|
||||
if data[byteOffset]&(1<<bitOffset) != 0 {
|
||||
p.Set(x+dx, y+dy, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func drawLine(p draw.Image, x1, y1, x2, y2 int, c color.Color) {
|
||||
var dx, dy, e, slope int
|
||||
|
||||
// Because drawing p1 -> p2 is equivalent to draw p2 -> p1,
|
||||
// I sort points in x-axis order to handle only half of possible cases.
|
||||
if x1 > x2 {
|
||||
x1, y1, x2, y2 = x2, y2, x1, y1
|
||||
}
|
||||
|
||||
dx, dy = x2-x1, y2-y1
|
||||
// Because point is x-axis ordered, dx cannot be negative
|
||||
if dy < 0 {
|
||||
dy = -dy
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
// Is line a point ?
|
||||
case x1 == x2 && y1 == y2:
|
||||
p.Set(x1, y1, c)
|
||||
|
||||
// Is line an horizontal ?
|
||||
case y1 == y2:
|
||||
for ; dx != 0; dx-- {
|
||||
p.Set(x1, y1, c)
|
||||
x1++
|
||||
}
|
||||
p.Set(x1, y1, c)
|
||||
|
||||
// Is line a vertical ?
|
||||
case x1 == x2:
|
||||
if y1 > y2 {
|
||||
y1, y2 = y2, y1
|
||||
}
|
||||
for ; dy != 0; dy-- {
|
||||
p.Set(x1, y1, c)
|
||||
y1++
|
||||
}
|
||||
p.Set(x1, y1, c)
|
||||
|
||||
// Is line a diagonal ?
|
||||
case dx == dy:
|
||||
if y1 < y2 {
|
||||
for ; dx != 0; dx-- {
|
||||
p.Set(x1, y1, c)
|
||||
x1++
|
||||
y1++
|
||||
}
|
||||
} else {
|
||||
for ; dx != 0; dx-- {
|
||||
p.Set(x1, y1, c)
|
||||
x1++
|
||||
y1--
|
||||
}
|
||||
}
|
||||
p.Set(x1, y1, c)
|
||||
|
||||
// wider than high ?
|
||||
case dx > dy:
|
||||
if y1 < y2 {
|
||||
// BresenhamDxXRYD(img, x1, y1, x2, y2, col)
|
||||
dy, e, slope = 2*dy, dx, 2*dx
|
||||
for ; dx != 0; dx-- {
|
||||
p.Set(x1, y1, c)
|
||||
x1++
|
||||
e -= dy
|
||||
if e < 0 {
|
||||
y1++
|
||||
e += slope
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// BresenhamDxXRYU(img, x1, y1, x2, y2, col)
|
||||
dy, e, slope = 2*dy, dx, 2*dx
|
||||
for ; dx != 0; dx-- {
|
||||
p.Set(x1, y1, c)
|
||||
x1++
|
||||
e -= dy
|
||||
if e < 0 {
|
||||
y1--
|
||||
e += slope
|
||||
}
|
||||
}
|
||||
}
|
||||
p.Set(x2, y2, c)
|
||||
|
||||
// higher than wide.
|
||||
default:
|
||||
if y1 < y2 {
|
||||
// BresenhamDyXRYD(img, x1, y1, x2, y2, col)
|
||||
dx, e, slope = 2*dx, dy, 2*dy
|
||||
for ; dy != 0; dy-- {
|
||||
p.Set(x1, y1, c)
|
||||
y1++
|
||||
e -= dx
|
||||
if e < 0 {
|
||||
x1++
|
||||
e += slope
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// BresenhamDyXRYU(img, x1, y1, x2, y2, col)
|
||||
dx, e, slope = 2*dx, dy, 2*dy
|
||||
for ; dy != 0; dy-- {
|
||||
p.Set(x1, y1, c)
|
||||
y1--
|
||||
e -= dx
|
||||
if e < 0 {
|
||||
x1++
|
||||
e += slope
|
||||
}
|
||||
}
|
||||
}
|
||||
p.Set(x2, y2, c)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package audio
|
||||
|
||||
// Deinterleave multi channel samples to separate slices.
|
||||
func Deinterleave(samples []int16, slices [][]int16) {
|
||||
if len(samples) == 0 {
|
||||
return
|
||||
}
|
||||
if len(slices) == 1 {
|
||||
copy(slices[0], samples)
|
||||
return
|
||||
}
|
||||
|
||||
channels := len(slices)
|
||||
for i, sample := range samples {
|
||||
j, k := i%channels, i/channels
|
||||
slices[j][k] = sample
|
||||
}
|
||||
}
|
||||
|
||||
// Interleave multi channel samples to a single slice.
|
||||
func Interleave(slices [][]int16, samples []int16) {
|
||||
if len(slices) == 0 {
|
||||
return
|
||||
}
|
||||
if len(slices) == 1 {
|
||||
copy(samples, slices[0])
|
||||
return
|
||||
}
|
||||
|
||||
channels := len(slices)
|
||||
for i := range samples {
|
||||
j, k := i%channels, i/channels
|
||||
samples[i] = slices[j][k]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
"git.maze.io/go/bragi/audio"
|
||||
"periph.io/x/conn/v3/physic"
|
||||
)
|
||||
|
||||
var (
|
||||
spriteLeft = []uint8{
|
||||
0x08, /* width */
|
||||
0x05, /* height */
|
||||
0b10000,
|
||||
0b10000,
|
||||
0b10000,
|
||||
0b10000,
|
||||
0b11110,
|
||||
}
|
||||
spriteRight = []uint8{
|
||||
0x08, /* width */
|
||||
0x05, /* height */
|
||||
0b11110,
|
||||
0b10001,
|
||||
0b11110,
|
||||
0b10100,
|
||||
0b10010,
|
||||
}
|
||||
)
|
||||
|
||||
type Peak struct {
|
||||
rate physic.Frequency
|
||||
channels int
|
||||
level audio.Float64
|
||||
peaks []audio.Float64
|
||||
}
|
||||
|
||||
func NewPeak(sampleRate physic.Frequency, channels int, keep int) *Peak {
|
||||
if channels < 1 {
|
||||
channels = 1
|
||||
} else if channels > 2 {
|
||||
channels = 2
|
||||
}
|
||||
|
||||
v := &Peak{
|
||||
rate: sampleRate,
|
||||
channels: channels,
|
||||
level: make(audio.Float64, channels),
|
||||
}
|
||||
|
||||
if keep > 0 {
|
||||
for i := 0; i < channels; i++ {
|
||||
v.peaks = append(v.peaks, make(audio.Float64, keep))
|
||||
}
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Peak) Process(samples audio.Slice) {
|
||||
sum := make([]float64, v.channels)
|
||||
for i, l := 0, samples.Len(); i < l; i++ {
|
||||
k := samples.At(i)
|
||||
if k < 0 {
|
||||
k = -k
|
||||
}
|
||||
if k > 1 {
|
||||
k = 1
|
||||
}
|
||||
n := i % v.channels
|
||||
sum[n] += math.Pow(k, 2)
|
||||
}
|
||||
|
||||
//log.Printf("max: %+v", max)
|
||||
for n, k := range sum {
|
||||
l := math.Sqrt(k / float64(samples.Len()))
|
||||
v.level[n] = l
|
||||
|
||||
if v.peaks != nil {
|
||||
copy(v.peaks[n][1:], v.peaks[n])
|
||||
v.peaks[n][0] = l
|
||||
//sortSlice(v.peaks[n], true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Peak) Render(dst draw.Image, origin image.Point, c color.Color) {
|
||||
var (
|
||||
r = image.Rect(0, 0, 64, 11)
|
||||
scale = 1.0 / float64(r.Dx()-6)
|
||||
)
|
||||
|
||||
// Clear buffer
|
||||
draw.Draw(dst, r.Add(origin), image.Black, image.Point{}, draw.Src)
|
||||
|
||||
ox, oy := origin.X, origin.Y
|
||||
|
||||
// Draw sprites
|
||||
drawSprite(dst, ox-3, oy+0, spriteLeft[:], c)
|
||||
drawSprite(dst, ox-3, oy+6, spriteRight[:], c)
|
||||
|
||||
// Draw line
|
||||
ox += 6
|
||||
drawLine(dst, ox, oy+2, ox+r.Dx()-6, oy+2, c)
|
||||
drawLine(dst, ox, oy+8, ox+r.Dx()-6, oy+8, c)
|
||||
|
||||
// Draw bar
|
||||
lw := int(v.level[0] / scale)
|
||||
rw := lw
|
||||
if v.channels > 1 {
|
||||
rw = int(v.level[1] / scale)
|
||||
}
|
||||
drawLine(dst, ox, oy+1, ox+lw, oy+1, c)
|
||||
drawLine(dst, ox, oy+3, ox+lw, oy+3, c)
|
||||
drawLine(dst, ox, oy+7, ox+rw, oy+7, c)
|
||||
drawLine(dst, ox, oy+9, ox+rw, oy+9, c)
|
||||
|
||||
if v.peaks != nil {
|
||||
lw = int(audio.Max(v.peaks[0]) / scale) //int(v.peaks[0][0] / scale)
|
||||
rw = lw
|
||||
if v.channels > 1 {
|
||||
rw = int(audio.Max(v.peaks[1]) / scale) //int(v.peaks[1][0] / scale)
|
||||
}
|
||||
drawLine(dst, ox+lw, oy+1, ox+lw, oy+3, c)
|
||||
drawLine(dst, ox+rw, oy+7, ox+rw, oy+9, c)
|
||||
}
|
||||
}
|
||||
|
||||
func sortSlice(s audio.Float64, reverse bool) {
|
||||
sort.Slice(s, func(i, j int) bool {
|
||||
if reverse {
|
||||
return s[i] > s[j]
|
||||
}
|
||||
return s[i] < s[j]
|
||||
})
|
||||
}
|
||||
|
||||
var _ Visualizer = (*Peak)(nil)
|
||||
@@ -0,0 +1 @@
|
||||
package audio
|
||||
@@ -0,0 +1,205 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"math"
|
||||
|
||||
"git.maze.io/go/bragi/audio"
|
||||
"periph.io/x/conn/v3/physic"
|
||||
)
|
||||
|
||||
type VUMeter struct {
|
||||
rate physic.Frequency
|
||||
channel int
|
||||
channels int
|
||||
level float64
|
||||
//peaks []audio.Float64
|
||||
}
|
||||
|
||||
func NewVUMeter(sampleRate physic.Frequency, channel, channels int) *VUMeter {
|
||||
if channel < 1 {
|
||||
channel = 1
|
||||
} else if channel > 2 {
|
||||
channel = 2
|
||||
}
|
||||
if channels < 1 {
|
||||
channels = 1
|
||||
} else if channels > 2 {
|
||||
channels = 2
|
||||
}
|
||||
|
||||
v := &VUMeter{
|
||||
rate: sampleRate,
|
||||
channel: channel,
|
||||
channels: channels,
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *VUMeter) Process(samples audio.Slice) {
|
||||
var sum float64
|
||||
for i, l := 0, samples.Len(); i < l; i++ {
|
||||
k := samples.At(i)
|
||||
if k < 0 {
|
||||
k = -k
|
||||
}
|
||||
if k > 1 {
|
||||
k = 1
|
||||
}
|
||||
if n := i % v.channels; n == v.channel {
|
||||
sum += math.Pow(k, 2)
|
||||
}
|
||||
}
|
||||
|
||||
// RMS level
|
||||
v.level = math.Sqrt(sum / float64(samples.Len()))
|
||||
}
|
||||
|
||||
func (v *VUMeter) Render(dst draw.Image, origin image.Point, c color.Color) {
|
||||
// Clear buffer
|
||||
draw.Draw(dst, dst.Bounds(), image.Black, image.Point{}, draw.Src)
|
||||
|
||||
// Draw background
|
||||
drawSprite(dst, origin.X, origin.Y, vumeterBackground[v.channel-1], c)
|
||||
|
||||
var (
|
||||
scale = 1.0 / float64(len(needleCoordinates))
|
||||
angle = int(v.level / scale)
|
||||
point = needleCoordinates[angle].Add(origin)
|
||||
)
|
||||
drawLine(dst, point.X, point.Y, origin.X+64, origin.Y+96, c)
|
||||
}
|
||||
|
||||
var needleCoordinates = []image.Point{
|
||||
{0, 23},
|
||||
{1, 23},
|
||||
{2, 22},
|
||||
{3, 21},
|
||||
{3, 21},
|
||||
{4, 20},
|
||||
{5, 19},
|
||||
{6, 19},
|
||||
{7, 18},
|
||||
{8, 17},
|
||||
{9, 17},
|
||||
{10, 16},
|
||||
{10, 16},
|
||||
{11, 15},
|
||||
{12, 14},
|
||||
{13, 14},
|
||||
{14, 13},
|
||||
{15, 13},
|
||||
{16, 12},
|
||||
{17, 12},
|
||||
{18, 11},
|
||||
{19, 11},
|
||||
{20, 10},
|
||||
{21, 10},
|
||||
{22, 9},
|
||||
{23, 9},
|
||||
{24, 8},
|
||||
{25, 8},
|
||||
{26, 7},
|
||||
{27, 7},
|
||||
{28, 6},
|
||||
{29, 6},
|
||||
{30, 6},
|
||||
{31, 5},
|
||||
{32, 5},
|
||||
{33, 5},
|
||||
{34, 4},
|
||||
{35, 4},
|
||||
{36, 4},
|
||||
{37, 3},
|
||||
{38, 3},
|
||||
{39, 3},
|
||||
{40, 2},
|
||||
{41, 2},
|
||||
{42, 2},
|
||||
{43, 2},
|
||||
{45, 1},
|
||||
{46, 1},
|
||||
{47, 1},
|
||||
{48, 1},
|
||||
{49, 1},
|
||||
{50, 0},
|
||||
{51, 0},
|
||||
{52, 0},
|
||||
{53, 0},
|
||||
{54, 0},
|
||||
{55, 0},
|
||||
{56, 0},
|
||||
{57, 0},
|
||||
{59, 0},
|
||||
{60, 0},
|
||||
{61, 0},
|
||||
{62, 0},
|
||||
{63, 0},
|
||||
{64, 0},
|
||||
{65, 0},
|
||||
{66, 0},
|
||||
{67, 0},
|
||||
{68, 0},
|
||||
{70, 0},
|
||||
{71, 0},
|
||||
{72, 0},
|
||||
{73, 0},
|
||||
{74, 0},
|
||||
{75, 0},
|
||||
{76, 0},
|
||||
{77, 0},
|
||||
{78, 1},
|
||||
{79, 1},
|
||||
{80, 1},
|
||||
{81, 1},
|
||||
{82, 1},
|
||||
{84, 2},
|
||||
{85, 2},
|
||||
{86, 2},
|
||||
{87, 2},
|
||||
{88, 3},
|
||||
{89, 3},
|
||||
{90, 3},
|
||||
{91, 4},
|
||||
{92, 4},
|
||||
{93, 4},
|
||||
{94, 5},
|
||||
{95, 5},
|
||||
{96, 5},
|
||||
{97, 6},
|
||||
{98, 6},
|
||||
{99, 6},
|
||||
{100, 7},
|
||||
{101, 7},
|
||||
{102, 8},
|
||||
{103, 8},
|
||||
{104, 9},
|
||||
{105, 9},
|
||||
{106, 10},
|
||||
{107, 10},
|
||||
{108, 11},
|
||||
{109, 11},
|
||||
{110, 12},
|
||||
{111, 12},
|
||||
{112, 13},
|
||||
{113, 13},
|
||||
{114, 14},
|
||||
{115, 14},
|
||||
{116, 15},
|
||||
{117, 16},
|
||||
{117, 16},
|
||||
{118, 17},
|
||||
{119, 17},
|
||||
{120, 18},
|
||||
{121, 19},
|
||||
{122, 19},
|
||||
{123, 20},
|
||||
{124, 21},
|
||||
{124, 21},
|
||||
{125, 22},
|
||||
{126, 23},
|
||||
{127, 23},
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package audio
|
||||
|
||||
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, 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,
|
||||
}}
|
||||
@@ -0,0 +1,43 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"math"
|
||||
)
|
||||
|
||||
type Waveform struct {
|
||||
bins []int8
|
||||
height int
|
||||
scale float64
|
||||
decimate int
|
||||
r image.Rectangle
|
||||
}
|
||||
|
||||
func NewWaveform(x, y int) *Waveform {
|
||||
return &Waveform{
|
||||
bins: make([]int8, x),
|
||||
height: y,
|
||||
scale: float64(y>>1) / math.MaxInt16,
|
||||
decimate: 1,
|
||||
r: image.Rect(0, 0, x, y),
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Waveform) Process(sample int16) {
|
||||
v.shift()
|
||||
v.bins[0] = int8(float64(sample) * v.scale)
|
||||
}
|
||||
|
||||
func (v *Waveform) shift() {
|
||||
copy(v.bins[1:], v.bins)
|
||||
v.bins[0] = 0
|
||||
}
|
||||
|
||||
func (v *Waveform) Draw(i draw.Image, o image.Point) {
|
||||
draw.Draw(i, v.r.Add(o), image.Black, image.Point{}, draw.Src)
|
||||
for x, h := range v.bins {
|
||||
drawLine(i, o.X+x, o.Y+int(h), o.X+x, o.Y+v.height, color.White)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user