admin b5c083e06f
Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
first commit
2026-06-04 18:10:52 +07:00

43 lines
1.1 KiB
Go

package transcode
import (
"context"
"github.com/gopxl/beep"
"github.com/gopxl/beep/effects"
)
func buildPipeline(streamer beep.Streamer, format beep.Format, opt Options) (beep.Streamer, beep.Format) {
out := streamer
if opt.SampleRate > 0 && format.SampleRate != beep.SampleRate(opt.SampleRate) {
out = beep.Resample(4, format.SampleRate, beep.SampleRate(opt.SampleRate), out)
format.SampleRate = beep.SampleRate(opt.SampleRate)
}
if opt.Channels == 1 {
out = effects.Mono(out)
format.NumChannels = 1
}
return out, format
}
func drainSamples(ctx context.Context, s beep.Streamer) ([]float64, error) {
buf := make([][2]float64, 4096)
var samples []float64
for {
if err := ctx.Err(); err != nil {
return nil, err
}
n, ok := s.Stream(buf)
if !ok {
if err := s.Err(); err != nil {
return nil, err
}
break
}
for i := 0; i < n; i++ {
samples = append(samples, buf[i][0])
}
}
return samples, nil
}