46 lines
1.5 KiB
Java
46 lines
1.5 KiB
Java
|
|
package org.jcodec.audio;
|
||
|
|
|
||
|
|
import java.nio.FloatBuffer;
|
||
|
|
import org.jcodec.common.AudioFormat;
|
||
|
|
import org.jcodec.common.Preconditions;
|
||
|
|
|
||
|
|
public class ChannelMerge implements AudioFilter {
|
||
|
|
private AudioFormat format;
|
||
|
|
|
||
|
|
public ChannelMerge(AudioFormat format) {
|
||
|
|
this.format = format;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void filter(FloatBuffer[] _in, long[] inPos, FloatBuffer[] out) {
|
||
|
|
if (_in.length != this.format.getChannels())
|
||
|
|
throw new IllegalArgumentException("Channel merge must be supplied with " + this.format.getChannels() + " input buffers to hold the channels.");
|
||
|
|
if (out.length != 1)
|
||
|
|
throw new IllegalArgumentException("Channel merget invoked on more then one output");
|
||
|
|
FloatBuffer out0 = out[0];
|
||
|
|
int min = Integer.MAX_VALUE;
|
||
|
|
for (int k = 0; k < _in.length; k++) {
|
||
|
|
if (_in[k].remaining() < min)
|
||
|
|
min = _in[k].remaining();
|
||
|
|
}
|
||
|
|
for (int j = 0; j < _in.length; j++)
|
||
|
|
Preconditions.checkState((_in[j].remaining() == min));
|
||
|
|
if (out0.remaining() < min * _in.length)
|
||
|
|
throw new IllegalArgumentException("Supplied output buffer is not big enough to hold " + min + " * " + _in.length + " = " + min * _in.length + " output samples.");
|
||
|
|
for (int i = 0; i < min; i++) {
|
||
|
|
for (int m = 0; m < _in.length; m++)
|
||
|
|
out0.put(_in[m].get());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getDelay() {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getNInputs() {
|
||
|
|
return this.format.getChannels();
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getNOutputs() {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
}
|