Add basic volume scaling to the Transformer demo app.
PiperOrigin-RevId: 553086635
This commit is contained in:
parent
4302102cf0
commit
fec6252065
@ -119,6 +119,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
public static final int SAMPLE_RATE_INDEX = 1;
|
||||
public static final int SKIP_SILENCE_INDEX = 2;
|
||||
public static final int CHANNEL_MIXING_INDEX = 3;
|
||||
public static final int VOLUME_SCALING_INDEX = 4;
|
||||
|
||||
// Color filter options.
|
||||
public static final int COLOR_FILTER_GRAYSCALE = 0;
|
||||
@ -165,7 +166,11 @@ 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", "Mix channels into mono"
|
||||
"High pitched",
|
||||
"Sample rate of 48000Hz",
|
||||
"Skip silence",
|
||||
"Mix channels into mono",
|
||||
"Scale volume to 50%"
|
||||
};
|
||||
private static final String[] VIDEO_EFFECTS = {
|
||||
"Dizzy crop",
|
||||
|
@ -414,14 +414,29 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
processors.add(silenceSkippingAudioProcessor);
|
||||
}
|
||||
|
||||
if (selectedAudioEffects[ConfigurationActivity.CHANNEL_MIXING_INDEX]) {
|
||||
boolean mixToMono = selectedAudioEffects[ConfigurationActivity.CHANNEL_MIXING_INDEX];
|
||||
boolean scaleVolumeToHalf = selectedAudioEffects[ConfigurationActivity.VOLUME_SCALING_INDEX];
|
||||
if (mixToMono || scaleVolumeToHalf) {
|
||||
ChannelMixingAudioProcessor mixingAudioProcessor = new ChannelMixingAudioProcessor();
|
||||
for (int inputChannelCount = 1; inputChannelCount <= 6; inputChannelCount++) {
|
||||
float[] mixingCoefficients = new float[inputChannelCount];
|
||||
Arrays.fill(mixingCoefficients, 1f / inputChannelCount);
|
||||
ChannelMixingMatrix matrix;
|
||||
if (mixToMono) {
|
||||
float[] mixingCoefficients = new float[inputChannelCount];
|
||||
// Each channel is equally weighted in the mix to mono.
|
||||
Arrays.fill(mixingCoefficients, 1f / inputChannelCount);
|
||||
matrix =
|
||||
new ChannelMixingMatrix(
|
||||
inputChannelCount, /* outputChannelCount= */ 1, mixingCoefficients);
|
||||
} else {
|
||||
// Identity matrix.
|
||||
matrix =
|
||||
ChannelMixingMatrix.create(
|
||||
inputChannelCount, /* outputChannelCount= */ inputChannelCount);
|
||||
}
|
||||
|
||||
// Apply the volume adjustment.
|
||||
mixingAudioProcessor.putChannelMixingMatrix(
|
||||
new ChannelMixingMatrix(
|
||||
inputChannelCount, /* outputChannelCount= */ 1, mixingCoefficients));
|
||||
scaleVolumeToHalf ? matrix.scaleBy(0.5f) : matrix);
|
||||
}
|
||||
processors.add(mixingAudioProcessor);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user