static ISoundObj Splice(string infileL, int peakPosL, string infileR, int peakPosR, string outfile)
{
//int tmp1;
//bool tmp2;
WaveReader reader1 = new WaveReader(infileL, WaveFormat.IEEE_FLOAT, 32, 1);
// reader1.Skip(peakPosL, out tmp1, out tmp2);
SoundBuffer buff1 = new SoundBuffer(reader1);
buff1.ReadAll();
// Normalize loudness for each channel
double g = Loudness.WeightedVolume(buff1);
buff1.ApplyGain(1/g);
WaveReader reader2 = new WaveReader(infileR, WaveFormat.IEEE_FLOAT, 32, 1);
// reader2.Skip(peakPosR, out tmp1, out tmp2);
SoundBuffer buff2 = new SoundBuffer(reader2);
buff2.ReadAll();
g = Loudness.WeightedVolume(buff2);
buff2.ApplyGain(1/g);
ChannelSplicer splicer = new ChannelSplicer();
splicer.Add(buff1);
splicer.Add(buff2);
// General-purpose:
// Find the extremities of the DRC impulse,
// window asymmetrically.
//
// But, since we specifically used linear-phase filters on target and mic,
// we know that the impulse is centered.
// We want an impulse length (_filterLen)
// so window the 2048 samples at each end (which are pretty low to begin with - less than -100dB)
ISoundObj output;
int nCount = (int)(buff1.Count / 2);
if (nCount > _filterLen/2)
{
BlackmanHarris bhw = new BlackmanHarris(nCount, 2048, (nCount / 2) - 2048);
bhw.Input = splicer;
SampleBuffer sb = new SampleBuffer(bhw);
output = sb.Subset(_filterLen/2, _filterLen);
}
else
{
output = splicer;
}
ISoundObj result = output;
if (!_noSkew)
{
// Apply skew to compensate for time alignment in the impulse responses
Skewer skewer = new Skewer(true);
skewer.Input = output;
skewer.Skew = peakPosL - peakPosR;
result = skewer;
}
WaveWriter writer = new WaveWriter(outfile);
writer.Input = result;
writer.Dither = DitherType.NONE;
writer.Format = WaveFormat.IEEE_FLOAT;
writer.BitsPerSample = 32;
writer.SampleRate = _sampleRate;
writer.NumChannels = splicer.NumChannels;
if (Double.IsNaN(_gain))
{
writer.Normalization = 0;
}
else
{
writer.Gain = MathUtil.gain(_gain);
}
writer.Run();
writer.Close();
reader1.Close();
reader2.Close();
return result;
}