Skip to content

Add option to select mixing algorithm#68

Merged
charneykaye merged 6 commits into
mainfrom
copilot/choose-mixing-algorithm
Jan 7, 2026
Merged

Add option to select mixing algorithm#68
charneykaye merged 6 commits into
mainfrom
copilot/choose-mixing-algorithm

Conversation

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Implementation Plan: Choose Mixing Algorithm

  • Explore repository structure and understand current implementation
  • Define mixing algorithm types (logarithmic and linear)
  • Add algorithm selection field to AudioSpec structure
  • Implement linear mixing function
  • Update NextSample to use selected algorithm
  • Add tests for both mixing algorithms
  • Update documentation to explain algorithm options
  • Verify changes with existing tests

Summary

Added the ability to choose between two mixing algorithms:

  1. Logarithmic (Default): Paul Vögler's logarithmic normalization with automatic loudness normalization and dynamic range compression
  2. Linear: Simple linear mixing with clamping at [-1, 1] range

Changes Made

  • Added MixAlgorithm type and constants (MixLogarithmic, MixLinear) to bind/spec/spec.go
  • Added Algorithm field to AudioSpec structure (defaults to logarithmic for backward compatibility)
  • Implemented mixLinearClamp() function for linear mixing
  • Implemented mixApplyAlgorithm() dispatcher to select algorithm at runtime
  • Updated Configure() to set the mixing algorithm from AudioSpec
  • Added comprehensive tests for both algorithms
  • Updated documentation in README.md and mix.go package docs with usage examples

Usage Example

import "github.com/go-mix/mix/bind/spec"

// Use logarithmic mixing (default)
audioSpec := spec.AudioSpec{
    Freq:      48000,
    Format:    spec.AudioF32,
    Channels:  2,
    Algorithm: spec.MixLogarithmic, // or omit for default
}

// Use linear mixing
audioSpec := spec.AudioSpec{
    Freq:      48000,
    Format:    spec.AudioF32,
    Channels:  2,
    Algorithm: spec.MixLinear,
}
mix.Configure(audioSpec)

Testing

All tests pass including:

  • Algorithm selection tests
  • Linear clamping behavior tests
  • Logarithmic compression tests
  • Algorithm dispatcher tests
  • Full test suite across all packages

Backward Compatibility

The feature is fully backward compatible - existing code continues to use logarithmic mixing by default when Algorithm field is not specified.

Original prompt

This section details on the original issue you should resolve

<issue_title>Choose mixing algorithm</issue_title>
<issue_description>Current built-in is Paul Vogler's logarithmic normalization. Would like ability to select between that and linear, at least.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 6, 2026 09:47
Co-authored-by: charneykaye <8584836+charneykaye@users.noreply.github.com>
Co-authored-by: charneykaye <8584836+charneykaye@users.noreply.github.com>
@charneykaye

Copy link
Copy Markdown
Contributor

@copilot try again

Co-authored-by: charneykaye <8584836+charneykaye@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot try again

Done! The mixing algorithm selection feature is now complete.

Implemented in commit 19867ec:

  • Added MixAlgorithm type with MixLogarithmic and MixLinear constants
  • Linear mixing with clamping implemented alongside existing logarithmic algorithm
  • Algorithm can be selected via AudioSpec.Algorithm field
  • Defaults to logarithmic for backward compatibility
  • Full test coverage and documentation added

Users can now choose their mixing algorithm:

spec := spec.AudioSpec{
    Freq:      48000,
    Format:    spec.AudioF32,
    Channels:  2,
    Algorithm: spec.MixLinear, // or spec.MixLogarithmic (default)
}

Co-authored-by: charneykaye <8584836+charneykaye@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to select mixing algorithm Add option to select mixing algorithm Jan 7, 2026
@charneykaye charneykaye marked this pull request as ready for review January 7, 2026 08:21
@charneykaye charneykaye merged commit 5819594 into main Jan 7, 2026
@charneykaye charneykaye deleted the copilot/choose-mixing-algorithm branch January 7, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Choose mixing algorithm

2 participants