Skip to content

Feature request: Route mono source to stereo output and vice versa #26

@yorkshiretwist

Description

@yorkshiretwist

Please accept my apologies if this is in the docs somewhere.I see from the source code of BaseAudioSource.OutputChannelMapping that it looks like I can only route a source to the same number of channels, i.e. a mono source to 1 channel, a stereo source to 2 channels.

Is it possible to route a mono source to more than 1 channel (i.e. splitting it) or route a stereo source to 1 channel (summing L+R to a mono signal)?

I've also noticed, related to #25 that I need to set the number of targetChannels to 0 to get the correct value for StreamInfo.Channels. However, when I do that I must then route the source to a channel or playback is badly distorted. This simple program demonstrates it:

using OwnaudioNET;
using OwnaudioNET.Mixing;
using OwnaudioNET.Sources;
using System.Text.Json;

await OwnaudioNet.InitializeAsync();
OwnaudioNet.Start();

// Force Ownaudio.Native to be loaded so that [ModuleInitializer] can be run
var _ = typeof(Ownaudio.Native.NativeAudioEngine);

Console.WriteLine("WAV");
var fileSource = new FileSource("mono.wav", 8192, 48000, 0); // <== the final parameter here has to be 0 in order for StreamInfo.Channels to be 1
Console.WriteLine(JsonSerializer.Serialize(fileSource, new JsonSerializerOptions
{
    WriteIndented = true,
}));

Console.WriteLine("Press enter to play file...");
Console.ReadLine();

// if I comment out this line the audio is distorted
fileSource.RouteToChannels([0]);

var mixer = new AudioMixer(OwnaudioNet.Engine!.UnderlyingEngine);
mixer.Start();

mixer.AddSource(fileSource);

Console.WriteLine("Press enter to exit...");
Console.ReadLine();

mixer.Dispose();
await OwnaudioNet.ShutdownAsync();

mono.wav

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions