Add channel mixing effect to demo application.

PiperOrigin-RevId: 547465758
This commit is contained in:
samrobinson 2023-07-12 13:18:19 +01:00 committed by Rohit Singh
parent e81ae0a8eb
commit aa1ca747de
2 changed files with 17 additions and 1 deletions

View File

@ -118,6 +118,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
public static final int HIGH_PITCHED_INDEX = 0;
public static final int SAMPLE_RATE_INDEX = 1;
public static final int SKIP_SILENCE_INDEX = 2;
public static final int CHANNEL_MIXING_INDEX = 3;
// Color filter options.
public static final int COLOR_FILTER_GRAYSCALE = 0;
@ -164,7 +165,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
"720p H264 video with no audio",
};
private static final String[] AUDIO_EFFECTS = {
"High pitched", "Sample rate of 48000Hz", "Skip silence"
"High pitched", "Sample rate of 48000Hz", "Skip silence", "Mix channels into mono"
};
private static final String[] VIDEO_EFFECTS = {
"Dizzy crop",

View File

@ -54,6 +54,8 @@ import androidx.media3.common.DebugViewProvider;
import androidx.media3.common.Effect;
import androidx.media3.common.MediaItem;
import androidx.media3.common.audio.AudioProcessor;
import androidx.media3.common.audio.ChannelMixingAudioProcessor;
import androidx.media3.common.audio.ChannelMixingMatrix;
import androidx.media3.common.audio.SonicAudioProcessor;
import androidx.media3.common.util.BitmapLoader;
import androidx.media3.common.util.GlUtil;
@ -99,6 +101,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@ -411,6 +414,18 @@ public final class TransformerActivity extends AppCompatActivity {
processors.add(silenceSkippingAudioProcessor);
}
if (selectedAudioEffects[ConfigurationActivity.CHANNEL_MIXING_INDEX]) {
ChannelMixingAudioProcessor mixingAudioProcessor = new ChannelMixingAudioProcessor();
for (int inputChannelCount = 1; inputChannelCount <= 6; inputChannelCount++) {
float[] mixingCoefficients = new float[inputChannelCount];
Arrays.fill(mixingCoefficients, 1f / inputChannelCount);
mixingAudioProcessor.putChannelMixingMatrix(
new ChannelMixingMatrix(
inputChannelCount, /* outputChannelCount= */ 1, mixingCoefficients));
}
processors.add(mixingAudioProcessor);
}
return processors.build();
}