Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:28:51 +01:00
1 parent 7b6db17870
commit 0295eb1ad2
125 files changed
+59376

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
package audio
import "math"
// Int8 represents a signed 8-bit linear PCM encoded audio sample.
type Int8 []int8
// Int8ToFloat64 converts a Int8 encoded audio sample to Float64.
func Int8ToFloat64(s int8) float64 {
return float64(s) / float64(math.MaxInt8)
}
// Float64ToInt8 converts a Float64 encoded audio sample to Int8.
func Float64ToInt8(s float64) int8 {
return int8(math.Floor((s * float64(math.MaxInt8)) + 0.5))
}
// Len implements the Slice interface.
func (p Int8) Len() int {
return len(p)
}
// Cap implements the Slice interface.
func (p Int8) Cap() int {
return cap(p)
}
// At implements the Slice interface.
func (p Int8) At(i int) float64 {
return Int8ToFloat64(p[i])
}
// Set implements the Slice interface.
func (p Int8) Set(i int, s float64) {
p[i] = Float64ToInt8(s)
}
// Slice implements the Slice interface.
func (p Int8) Slice(low, high int) Slice {
return p[low:high]
}
// Make implements the Slice interface.
func (p Int8) Make(length, capacity int) Slice {
return make(Int8, length, capacity)
}
// CopyTo implements the Slice interface.
func (p Int8) CopyTo(dst Slice) int {
if d, ok := dst.(Int8); ok {
return copy(d, p)
}
if d, ok := dst.(Int16); ok {
for i, v := range p {
d[i] = int16(v) * 255
}
return p.Len()
}
return sliceCopy(dst, p)
}