Documentation
¶
Overview ¶
Example (ResamplingFile) ¶
package main import ( "github.com/gunter-q12/resample" "io" "os" ) func main() { input, _ := os.Open("./original.raw") output, _ := os.Create("./resampled.raw") res, _ := resample.New(output, resample.FormatInt16, 48000, 16000, 2) _, _ = io.Copy(res, input) }
Example (ResamplingSlice) ¶
package main import ( "bytes" "encoding/binary" "fmt" "github.com/gunter-q12/resample" ) func main() { // Convert slice of values into a slice of bytes input := []int16{1, 3, 5} inputData := new(bytes.Buffer) _ = binary.Write(inputData, binary.LittleEndian, input) // Resample outBuf := new(bytes.Buffer) res, _ := resample.New(outBuf, resample.FormatInt16, 1, 2, 1, resample.WithLinearFilter()) _, _ = res.Write(inputData.Bytes()) // Convert bytes back to a slice of values output := make([]int16, 5) _ = binary.Read(outBuf, binary.LittleEndian, output) fmt.Println(output) }
Output: [1 2 3 4 5]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option is a struct used to configure Resampler.
func WithKaiserBestFilter ¶
func WithKaiserBestFilter() Option
WithKaiserBestFilter function returns option that configures Resampler to use KaiserBestFilter.
Compared to default (Kaiser Fast) filter, KaiserBestFilter provides higher resampling quality in exchange for lower speed and higher memory usage.
func WithKaiserFastFilter ¶
func WithKaiserFastFilter() Option
WithKaiserFastFilter function returns option that configures Resampler to use KaiserFastFilter.
Used by default.
func WithKaiserFastestFilter ¶
func WithKaiserFastestFilter() Option
WithKaiserFastestFilter function returns option that configures Resampler to use KaiserFastestFilter.
Compared to default (Kaiser Fast) filter, KaiserFastestFilter provides higher resampling speed and lower memory usage in exchange for lower quality.
func WithLinearFilter ¶
func WithLinearFilter() Option
WithLinearFilter function returns option that configures Resampler to use linear filter.
This option should be used only for testing purposes because linear filter provides poor resampling quality.
func WithNoMemoization ¶
func WithNoMemoization() Option
WithNoMemoization function returns option that disables memoization in Resampler.
This option should be used when Resampler consumers too much memory. Such behaviour may occur when resampling between sampling rages with a small greatest common divisor (e.g. 9999 and 10000).
Enabling this function slows the resampling progress significantly. Therefore, most users should avoid it and switch used filter instead.
type Resampler ¶
type Resampler struct {
// contains filtered or unexported fields
}
A Resampler is a struct used for resampling.
func New ¶
func New(outBuffer io.Writer, format Format, inRate, outRate, ch int, options ...Option) (*Resampler, error)
New creates a new Resampler.
Calling Resampler.Write and Resampler.ReadFrom methods on the returned Resampler will resample data according to provided format, inRate, outRate and number of channels. Results are written to the io.Writer.
Default filter is KaiserFastFilter, use WithXFilter options to change it. Memoization is enabled by default, use WithNoMemoization function to disable it.
func (*Resampler) ReadFrom ¶
ReadFrom reads all the data from reader using batching to reduce memory usage.
func (*Resampler) Write ¶
Write writes resampled data to an io.Writer provided during a New call.
If Write is called multiple times, the data is appended to the same io.Writer. Note that calling Write on separate parts of the same file may result in imperfect resampling at the boundaries. For large files that do not fit into memory, use io.Copy instead.