mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add basic volume scaling to the Transformer demo app.
PiperOrigin-RevId: 553086635
This commit is contained in:
parent
4302102cf0
commit
fec6252065
2 changed files with 26 additions and 6 deletions
|
|
@ -119,6 +119,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||||
public static final int SAMPLE_RATE_INDEX = 1;
|
public static final int SAMPLE_RATE_INDEX = 1;
|
||||||
public static final int SKIP_SILENCE_INDEX = 2;
|
public static final int SKIP_SILENCE_INDEX = 2;
|
||||||
public static final int CHANNEL_MIXING_INDEX = 3;
|
public static final int CHANNEL_MIXING_INDEX = 3;
|
||||||
|
public static final int VOLUME_SCALING_INDEX = 4;
|
||||||
|
|
||||||
// Color filter options.
|
// Color filter options.
|
||||||
public static final int COLOR_FILTER_GRAYSCALE = 0;
|
public static final int COLOR_FILTER_GRAYSCALE = 0;
|
||||||
|
|
@ -165,7 +166,11 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||||
"720p H264 video with no audio",
|
"720p H264 video with no audio",
|
||||||
};
|
};
|
||||||
private static final String[] AUDIO_EFFECTS = {
|
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 = {
|
private static final String[] VIDEO_EFFECTS = {
|
||||||
"Dizzy crop",
|
"Dizzy crop",
|
||||||
|
|
|
||||||
|
|
@ -414,14 +414,29 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||||
processors.add(silenceSkippingAudioProcessor);
|
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();
|
ChannelMixingAudioProcessor mixingAudioProcessor = new ChannelMixingAudioProcessor();
|
||||||
for (int inputChannelCount = 1; inputChannelCount <= 6; inputChannelCount++) {
|
for (int inputChannelCount = 1; inputChannelCount <= 6; inputChannelCount++) {
|
||||||
float[] mixingCoefficients = new float[inputChannelCount];
|
ChannelMixingMatrix matrix;
|
||||||
Arrays.fill(mixingCoefficients, 1f / inputChannelCount);
|
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(
|
mixingAudioProcessor.putChannelMixingMatrix(
|
||||||
new ChannelMixingMatrix(
|
scaleVolumeToHalf ? matrix.scaleBy(0.5f) : matrix);
|
||||||
inputChannelCount, /* outputChannelCount= */ 1, mixingCoefficients));
|
|
||||||
}
|
}
|
||||||
processors.add(mixingAudioProcessor);
|
processors.add(mixingAudioProcessor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue