11package mixing
22
3- import "github.com/gotracker/gomixing/volume"
3+ import (
4+ "github.com/gotracker/gomixing/sampling"
5+ "github.com/gotracker/gomixing/volume"
6+ )
47
58// Mixer is a manager for mixing multiple single- and multi-channel samples into a single multi-channel output stream
69type Mixer struct {
@@ -10,7 +13,7 @@ type Mixer struct {
1013
1114// NewMixBuffer returns a mixer buffer with a number of channels
1215// of preallocated sample data
13- func (m * Mixer ) NewMixBuffer (samples int ) MixBuffer {
16+ func (m Mixer ) NewMixBuffer (samples int ) MixBuffer {
1417 return make (MixBuffer , samples )
1518}
1619
@@ -21,8 +24,9 @@ func GetDefaultMixerVolume(numMixedChannels int) volume.Volume {
2124}
2225
2326// Flatten will to a final saturation mix of all the row's channel data into a single output buffer
24- func (m * Mixer ) Flatten (panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume ) []byte {
27+ func (m Mixer ) Flatten (panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume , sampleFormat sampling. Format ) []byte {
2528 data := m .NewMixBuffer (samplesLen )
29+ formatter := sampling .GetFormatter (sampleFormat )
2630 for _ , rdata := range row {
2731 for _ , cdata := range rdata {
2832 if cdata .Flush != nil {
@@ -34,12 +38,12 @@ func (m *Mixer) Flatten(panmixer PanMixer, samplesLen int, row []ChannelData, mi
3438 }
3539 }
3640 }
37- return data .ToRenderData (samplesLen , m .BitsPerSample , m . Channels , mixerVolume )
41+ return data .ToRenderData (samplesLen , m .Channels , mixerVolume , formatter )
3842}
3943
4044// FlattenToInts runs a flatten on the channel data into separate channel data of int32 variety
4145// these int32s still respect the BitsPerSample size
42- func (m * Mixer ) FlattenToInts (panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume ) [][]int32 {
46+ func (m Mixer ) FlattenToInts (panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume ) [][]int32 {
4347 data := m .NewMixBuffer (samplesLen )
4448 for _ , rdata := range row {
4549 for _ , cdata := range rdata {
@@ -56,8 +60,9 @@ func (m *Mixer) FlattenToInts(panmixer PanMixer, samplesLen int, row []ChannelDa
5660}
5761
5862// FlattenTo will to a final saturation mix of all the row's channel data into a single output buffer
59- func (m * Mixer ) FlattenTo (resultBuffers [][]byte , panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume ) {
63+ func (m Mixer ) FlattenTo (resultBuffers [][]byte , panmixer PanMixer , samplesLen int , row []ChannelData , mixerVolume volume.Volume , sampleFormat sampling. Format ) {
6064 data := m .NewMixBuffer (samplesLen )
65+ formatter := sampling .GetFormatter (sampleFormat )
6166 for _ , rdata := range row {
6267 for _ , cdata := range rdata {
6368 if cdata .Flush != nil {
@@ -69,5 +74,5 @@ func (m *Mixer) FlattenTo(resultBuffers [][]byte, panmixer PanMixer, samplesLen
6974 }
7075 }
7176 }
72- data .ToRenderDataWithBufs (resultBuffers , samplesLen , m . BitsPerSample , mixerVolume )
77+ data .ToRenderDataWithBufs (resultBuffers , samplesLen , mixerVolume , formatter )
7378}
0 commit comments