package utils import "encoding/binary" // Float64ToPCM16 converts float64 samples [-1.0, 1.0] to signed 16-bit PCM (LittleEndian) bytes. func Float64ToPCM16(samples []float64) []byte { buf := make([]byte, len(samples)*2) for i, sample := range samples { // Clamp to [-1.0, 1.0] if sample > 1.0 { sample = 1.0 } else if sample < -1.0 { sample = -1.0 } // Convert to 16-bit PCM binary.LittleEndian.PutUint16(buf[i*2:], uint16(int16(sample*32767))) } return buf }