Skip to content

Add FlipChannels and IsolateChannel to mixer stub #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/AudioOutputMixer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
AudioOutputMixer
Simple mixer which can combine multiple inputs to a single output stream

Copyright (C) 2018 Earle F. Philhower, III

This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -48,6 +48,27 @@ bool AudioOutputMixerStub::SetChannels(int channels)
return parent->SetChannels(channels, id);
}

bool AudioOutputMixerStub::FlipChannels()
{
this->channelsFlipped = !this->channelsFlipped;
return true;
}

bool AudioOutputMixerStub::FlipChannels(bool flipped)
{
this->channelsFlipped = flipped;
return true;
}

bool AudioOutputMixerStub::IsolateChannel(uint8_t channel)
{
if(channel < 0 || channel > 2){
return false;
}
this->channelIsolated = channel;
return true;
}

bool AudioOutputMixerStub::begin()
{
return parent->begin(id);
Expand All @@ -56,8 +77,10 @@ bool AudioOutputMixerStub::begin()
bool AudioOutputMixerStub::ConsumeSample(int16_t sample[2])
{
int16_t amp[2];
amp[LEFTCHANNEL] = Amplify(sample[LEFTCHANNEL]);
amp[RIGHTCHANNEL] = Amplify(sample[RIGHTCHANNEL]);

amp[this->channelsFlipped ? RIGHTCHANNEL:LEFTCHANNEL] = (this->channelIsolated == 2) ? 0 : Amplify(sample[this->channelsFlipped ? RIGHTCHANNEL : LEFTCHANNEL]);
amp[this->channelsFlipped ? LEFTCHANNEL:RIGHTCHANNEL] = (this->channelIsolated == 1) ? 0 : Amplify(sample[this->channelsFlipped ? LEFTCHANNEL : RIGHTCHANNEL]);

return parent->ConsumeSample(amp, id);
}

Expand Down Expand Up @@ -156,7 +179,7 @@ bool AudioOutputMixer::begin(int id)
return true;
}
}

AudioOutputMixerStub *AudioOutputMixer::NewInput()
{
for (int i=0; i<maxStubs; i++) {
Expand Down
7 changes: 6 additions & 1 deletion src/AudioOutputMixer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
AudioOutputMixer
Simple mixer which can combine multiple inputs to a single output stream

Copyright (C) 2017 Earle F. Philhower, III

This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -35,13 +35,18 @@ class AudioOutputMixerStub : public AudioOutput
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
virtual bool SetChannels(int channels) override;
virtual bool FlipChannels(); // Invert current state of channelsFlipped
virtual bool FlipChannels(bool flip); // Set channelsFlipped true/false
virtual bool IsolateChannel(uint8_t channel); // Isolate channel 0 both, 1 left, 2 right
virtual bool begin() override;
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual bool stop() override;

protected:
AudioOutputMixer *parent;
int id;
bool channelsFlipped = false;
uint8_t channelIsolated = 0;
};

// Single mixer object per output
Expand Down