This project has moved and is read-only. For the latest updates, please go here.

RTP conversation to WaveFileWriter - audio issue with both Tx and Rx

Oct 28, 2014 at 7:51 PM
I'm having the same issue as the folks at the bottom of this discussion:

In fact, I think we're working off the same root project, SIPDump.

If I write my packets to two separate WaveFileWriters, each wav file is perfect. I tried mixing the two, but since one side of the conversation doesn't start until they answer, I can't seem to get the two sides in sync. In other words, when using the MixingSampleProvider, both wav files are mixed starting at the same time, when one should be delayed until they answer.

If I write both Tx and Rx to the same file, the resulting audio file is about twice as long as it should be. It almost sounds like a a bit of silence is inserted between each sample. I've validated that the RTP and UDP headers are precisely accounted for (I'm also parsing out each header field, and to mention again that using the same means of writing to wav works perfectly when the Tx/Rx are split into separate files).

The basic code for writing the packets:
short pcm = MuLawDecoder.MuLawToLinearSample(pp.Bytes[index]);
var pcm2 = BitConverter.GetBytes(pcm);
ar2.wave.Write(pcm2, 0, 2);
Any ideas on why the two sides of the conversation cannot be written to the wave file in the order they are read from the packets without introducing new artifacts?
Oct 28, 2014 at 8:38 PM
Edited Oct 28, 2014 at 8:40 PM
I did manage to get the two files synced up by calculating the TimeSpan between the timestamp of the first packet and the timestamps of the first packets of each SSRC, and then adding those TimeSpans to the beginning of each input through the OffsetSampleProvider.
var inputs = new List<ISampleProvider>();

foreach (var x in audio_files)
           var input = new WaveFileReader(x.path).ToSampleProvider();
           var o = new OffsetSampleProvider(input);
           o.DelayBy = (x.start_time.Value-start_time.Value);
var mixer = new MixingSampleProvider(inputs);
WaveFileWriter.CreateWaveFile16("mixed.wav", mixer);