Documentation
¶
Overview ¶
Package multichannel provides data structure used for manipulating multi-channel audio data.
Index ¶
- type Buffer
- type CBuffer
- func (c *CBuffer) Add(buffer TSMBuffer)
- func (c *CBuffer) Divide(buffer NormalizeBuffer, n int)
- func (c *CBuffer) Len() int
- func (c *CBuffer) Peek(samples Buffer) int
- func (c *CBuffer) Read(buffer Buffer) int
- func (c *CBuffer) RemainingSpace() int
- func (c *CBuffer) Remove(n int)
- func (c *CBuffer) SetReadable(n int)
- func (c *CBuffer) Write(buffer Buffer) int
- type NormalizeBuffer
- type TSMBuffer
- func (b TSMBuffer) ApplyWindow(window []float64)
- func (b TSMBuffer) Channel(channel int) []float64
- func (b TSMBuffer) Channels() int
- func (b TSMBuffer) Len() int
- func (b TSMBuffer) Sample(channel int, index int) float64
- func (b TSMBuffer) SetSample(channel int, index int, value float64)
- func (b TSMBuffer) Slice(from int, to int) Buffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer interface {
// Channels returns the number of channels of the buffer.
Channels() int
// Len returns the number of samples of each channel of the buffer.
Len() int
// Sample returns the index-th sample of the channel-th channel of the
// buffer.
Sample(channel int, index int) float64
// SetSample sets the index-th sample of the channel-c channel of the
// buffer to value.
SetSample(channel int, index int, value float64)
// Slice returns a Buffer containing only the audio samples between from
// (included) and to (excluded) for each channel. It is the equivalent of
// buffer[from:to], if buffer is a mono-channel buffer represented by a
// slice.
Slice(from int, to int) Buffer
}
A Buffer is a representation of a multi-channel audio buffer.
type CBuffer ¶
type CBuffer struct {
// contains filtered or unexported fields
}
A CBuffer is a fixed-size circular buffer used to store multi-channel audio data.
A CBuffer is divided into two parts : a readable part, that can be read but cannot be modified, and an writable part that can be modified but cannot be read.
func NewCBuffer ¶
NewCBuffer creates a new empty CBuffer, each channel containing at most size samples.
func (*CBuffer) Add ¶
Add adds a buffer to the CBuffer element-wise.
The buffer is added in the writable part of the CBuffer, but does not mark the samples as readable, allowing them to be modified again by the Add and Divide methods. SetReadable should be called to mark these samples as readable and to prevent them from being modified.
Add will panic if the two buffer do not have the same number of channels or if there is not enough space in the writable part of the CBuffer.
c := multichannel.NewCBuffer(1, 4)
c.Add(multichannel.Buffer{{1, 2}}
buffer := multichannel.NewBuffer(1, 3)
fmt.Println(c.Len()) // prints 0
fmt.Println(c.Read(buffer)) // prints 0, and leaves buffer unchanged
fmt.Println(buffer) // prints [[0, 0, 0]]
c.SetReadable(2)
fmt.Println(c.Len()) // prints 2
fmt.Println(c.Read(buffer)) // prints 2
fmt.Println(buffer) // prints [[1, 2, 0]]
func (*CBuffer) Divide ¶
func (c *CBuffer) Divide(buffer NormalizeBuffer, n int)
Divide divides each channel of the CBuffer by the first n values of the NormalizeBuffer element-wise.
The CBuffer is divided in its writable part, and the samples are not marked as readable, allowing them to be modified again by the Add and Divide methods. SetReadable should be called to mark these samples as readable and to prevent them from being modified.
The values of the NormalizeBuffer that are lower than 0.0001 are ignored to avoid division by zero.
Divide will panic if there is not enough space in the writable part of the CBuffer.
func (*CBuffer) Len ¶
Len returns the number of samples that each channel contains (i.e. the size of the readable part).
func (*CBuffer) Peek ¶
Peek reads as many samples from the CBuffer as possible (min(c.Len(), buffer.Len())) without removing them from the CBuffer, writes them to the buffer, and returns the number of samples that were read.
It panics if the two buffer do not have the same number of channels.
func (*CBuffer) Read ¶
Read reads as many samples from the CBuffer as possible (min(c.Len(), buffer.Len()), removes them from the CBuffer, writes them to the buffer, and returns the number of samples that were read.
It panics if the two buffer do not have the same number of channels.
func (*CBuffer) RemainingSpace ¶
RemainingSpace returns the number of samples that can be added to each channel (i.e. the size of the writable part).
func (*CBuffer) Remove ¶
Remove removes the first n samples of the buffer, preventing them to be read again, and leaving more space for new samples to be written.
func (*CBuffer) SetReadable ¶
SetReadable sets the next n samples as readable.
It panics if there is not enough space in the CBuffer.
type NormalizeBuffer ¶
type NormalizeBuffer struct {
// contains filtered or unexported fields
}
NormalizeBuffer is a mono-channel circular buffer, used to normalize audio buffers.
func NewNormalizeBuffer ¶
func NewNormalizeBuffer(n int) NormalizeBuffer
NewNormalizeBuffer returns a new NormalizeBuffer of length n.
func (*NormalizeBuffer) Add ¶
func (b *NormalizeBuffer) Add(window []float64)
Add adds a window element-wise to the buffer.
func (*NormalizeBuffer) Get ¶
func (b *NormalizeBuffer) Get(i int) float64
Get returns the i-th value of the buffer.
func (*NormalizeBuffer) Remove ¶
func (b *NormalizeBuffer) Remove(n int)
Remove removes the first n values of the buffer.
type TSMBuffer ¶
type TSMBuffer [][]float64
A TSMBuffer is a representation of a multi-channel audio buffer which implements the Buffer interface and is used internally by the tsm package.
If buffer is a TSMBuffer, the value at buffer[c][i] is the value of the i-th sample of the c-th channel. Each channel should have the same number of samples. This representation makes it easy to work on each channel individually, which is often required for time-scale modifications.
func NewTSMBuffer ¶
NewTSMBuffer creates a new TSMBuffer, each channel containing length samples.
func (TSMBuffer) ApplyWindow ¶
ApplyWindow applies a window to each channel of the buffer.
A window is a slice of float64 (as returned by the functions of the packages tsm/windows and github.com/mjibson/go-dsp/window), and is applied by multiplying each channel by the window element-wise.
ApplyWindow will panic if the buffer and the window have different lengths.