mixerInG

package module
v0.0.0-...-99236d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 5 Imported by: 0

README

Say Thanks!

Mixer in G

Mixer in G is a PCM audio stream mixer package written in pure Go using the go-audio framework and does not require binding to non-native libraries, such as SoX or FFmpeg, as other mixers do.

To import Mixer in G into your project:
go get github.com/ScriptTiger/mixerInG
Then just import "github.com/ScriptTiger/mixerInG" and get started with using its functions.

Please refer to the dev package docs and reference implementation for more details and ideas on how to integrate Mixer in G into your project.

Dev package docs:
https://pkg.go.dev/github.com/ScriptTiger/mixerInG

Reference implementation:
https://github.com/ScriptTiger/mixerInG/blob/main/ref/ref.go

Reference Implementation

Usage: mixerInG [options...]

Argument Description
-i <file> Input WAV file (must be used for each input, for at least 2 inputs)
-o <file> Destination WAV file of mix
-bits <number> Bit depth of mix WAV file (16|24|32)
-attenuate Attenuate linearly to prevent clipping, dividing by number of tracks mixed

If no output file is given, or - is given, the mix is written to standard output with a bit depth of 24 and can be piped into FFmpeg, FFplay, VLC, or other compatible media applications.

Attenuating linearly is best done when going from source tracks of lower bit depths to mixes of higher bit depths to diminish resolution loss. This will result in an output mix which will always be perceptually "quieter," but still retain better resolution than if it were a mix of the same or lower bit depth as the original tracks. This is because the mix itself, and attenuation division, is performed in 64-bit floating point and results in trailing digits behind a decimal which will be removed when the mix track is truncated to its destination bit depth, of 32 bits or lower, signed and not floating point. So, mixing to higher bit depths than the original will scale some of that data which would otherwise be behind the decimal to in front of the decimal and preserve it in the resulting mix.

However, it's also important to note that attenuating linearly is only recommended when mixing incohesive tracks, such as more raw and experimental tracks which were not previously mastered together to prevent clipping in the mix already. By not attenuating at all, there will never be any trailing digits behind a decimal since there would be no division occurring, unless scaling down from source tracks of higher bit depths to mixes of lower bit depths, which should also be avoided.

Other projects using Mixer in G

FLACSFX:
https://github.com/ScriptTiger/FLACSFX

More About ScriptTiger

For more ScriptTiger scripts and goodies, check out ScriptTiger's GitHub Pages website:
https://scripttiger.github.io/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttenuateFloatBuffer

func AttenuateFloatBuffer(mixTrack *audio.FloatBuffer, numTracks, bufferSize int)

Function to attenuate linearly to prevent clipping in real-time without knowing/using true peak, RMS, LUFS, etc.

func Mix

func Mix(mixTrack *audio.FloatBuffer, sourceTracks []*TrackInfo, bitDepth int, attenuate bool) (mixBufferSize int)

Function to mix TrackInfo float buffers to a provided mix float buffer, performing common scaling and attenuation operations as needed, and return length of longest buffer

func MixWavDecoders

func MixWavDecoders(wavDecs []*wav.Decoder, wavOut *os.File, bitDepth int, attenuate bool) error

Function to mix wav decoders and write mix to output

func MixWavFiles

func MixWavFiles(files []*string, outWavName *string, bitDepth int, attenuate bool) error

Function to mix wav files and write mix to output

func ReadWavsToBuffers

func ReadWavsToBuffers(wavDecs []*wav.Decoder, tracks []*TrackInfo) (mixBufferSize int)

Function to read PCM data from a wav decoder into a TrackInfo's buffers, set bufferSize, and return length of longest buffer

func ScaleFloatBuffers

func ScaleFloatBuffers(tracks []*TrackInfo, bitDepth int)

Function to scale input bit depth to output bit depth

func SumFloatBuffers

func SumFloatBuffers(mixTrack *audio.FloatBuffer, sourceTracks []*TrackInfo) (mixBufferSize int)

Function to sum TrackInfo float buffers to a mix float buffer and return buffer size of mix, equal to length of longest buffer

Types

type TrackInfo

type TrackInfo struct {
	BitDepth    int
	BufferSize  int
	IntBuffer   *audio.IntBuffer
	FloatBuffer *audio.FloatBuffer
}

Structure to hold information for a track

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL