Class WeightedChannelMixBlock
- Assembly
- VisioForge.Core.dll
Weighted channel mix audio processing block for dual-mono audio sources like CD+G karaoke files. This block mixes left and right stereo channels with independently adjustable weights and outputs the merged mono signal to both speakers. Essential for karaoke applications where users need to control the balance between instrumental music (typically on left channel) and vocals (typically on right channel). Provides runtime-adjustable mixing with smooth transitions and a convenient VocalLevel property for simplified karaoke control. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public class WeightedChannelMixBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Examples
Basic usage for CD+G karaoke playback:
// Create pipeline and CDG source
var pipeline = new MediaBlocksPipeline();
var cdgSource = new CDGSourceBlock(new CDGSourceSettings { Filename = "song.cdg" });
// Create weighted channel mix block for vocal control
var channelMix = new WeightedChannelMixBlock();
channelMix.VocalLevel = 0.3f; // 30% vocals, 70% music
// Connect to audio renderer
pipeline.Connect(cdgSource.AudioOutput, channelMix.Input);
pipeline.Connect(channelMix.Output, audioRenderer.Input);
await pipeline.StartAsync();
Constructors
WeightedChannelMixBlock()
Initializes a new instance of the VisioForge.Core.MediaBlocks.AudioProcessing.WeightedChannelMixBlock class with default settings (50% mix of both channels).
public WeightedChannelMixBlock()WeightedChannelMixBlock(WeightedChannelMixAudioEffect)
Initializes a new instance of the VisioForge.Core.MediaBlocks.AudioProcessing.WeightedChannelMixBlock class with specified weighted channel mix settings.
public WeightedChannelMixBlock(WeightedChannelMixAudioEffect settings)Parameters
settingsWeightedChannelMixAudioEffect-
The weighted channel mix settings controlling mixing parameters.
WeightedChannelMixBlock(float, float, bool)
Initializes a new instance of the VisioForge.Core.MediaBlocks.AudioProcessing.WeightedChannelMixBlock class with specified channel weights for simplified configuration.
public WeightedChannelMixBlock(float leftWeight, float rightWeight, bool outputStereo = true)Parameters
leftWeightfloat-
The weight for the left channel (0.0 to 1.0).
rightWeightfloat-
The weight for the right channel (0.0 to 1.0).
outputStereobool-
if set to
trueoutput as stereo (default).
Properties
Input
Gets the input.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets the inputs.
public override MediaBlockPad[] Inputs { get; }Property Value
LeftChannelWeight
Gets or sets the weight (volume multiplier) for the left audio channel. Range: 0.0 (silent) to 1.0 (full volume). Values above 1.0 may cause clipping. For CD+G karaoke, the left channel typically contains instrumental music only.
public float LeftChannelWeight { get; set; }Property Value
Remarks
Changes to this property take effect immediately during playback without pipeline reconstruction.
Output
Gets the output.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets the outputs.
public override MediaBlockPad[] Outputs { get; }Property Value
RightChannelWeight
Gets or sets the weight (volume multiplier) for the right audio channel. Range: 0.0 (silent) to 1.0 (full volume). Values above 1.0 may cause clipping. For CD+G karaoke, the right channel typically contains the full mix (music + vocals).
public float RightChannelWeight { get; set; }Property Value
Remarks
Changes to this property take effect immediately during playback without pipeline reconstruction.
Settings
Gets or sets the weighted channel mix settings that control audio mixing parameters. Includes individual channel weights and output format configuration.
public WeightedChannelMixAudioEffect Settings { get; set; }Property Value
Type
Gets the type.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Constructs and initializes the weighted channel mix filter and its associated GStreamer elements. This method creates the filter bin with deinterleave, volume, mixer, and converter elements, establishes input and output pads, and prepares the block for mixing stereo audio streams with adjustable channel weights.
public override bool Build()Returns
- bool
-
trueif the filter was successfully built and configured;falseif initialization failed.
CleanUp()
Releases all resources and performs cleanup operations for this weighted channel mix block. This method disposes of the GStreamer elements and resets the build state.
public void CleanUp()Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
GetCore()
Gets the core BaseElement wrapper that provides additional functionality around the GStreamer weighted channel mix filter element.
public BaseElement GetCore()Returns
- BaseElement
-
The BaseElement wrapper instance that encapsulates the GStreamer filter.
GetElement()
Gets the underlying GStreamer element that performs the weighted channel mix processing.
public Element GetElement()Returns
- Element
-
The GStreamer Element instance representing the channel mix filter bin.
IsAvailable()
Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.
public static bool IsAvailable()Returns
- bool
-
trueif this media block is available; otherwise,false.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Associates this weighted channel mix block with a pipeline and initializes its internal context. This method is called internally when the block is added to a pipeline.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline instance that will manage this block.