This project has moved. For the latest updates, please go here.

WaveOffsetStream is cutting off the end of my wave file

Sep 28, 2012 at 7:10 PM

So I have an audioplayer that plays audio according to time and delay's the playback of the next audio file based on write time.


 

offset_stream = new WaveOffsetStream(file_stream);
channel_stream = new WaveChannel32(offset_stream);

 

public TimeSpan Delay_Playback
{
     get
     {
          return offset_stream.StartTime;
     }
     set
     {
          offset_stream.StartTime = value;
     }
}


Example:

I'm playing 4 different wave files that are roughly the same length between 10:00 and 10:15.
If the wave files are in different directories I don't bother comparing the last write time,
however if there are say two files in the same directory I compare the last write time and play
the early of the two first. I also save the difference between last write times and delay the
later of the two by that difference.

So say, one file was written at 10:00:00 AM and the next was written at 10:00:36 AM, then the
10:00:00 AM file is played, but the 10:00:36 is delayed by 36 seconds. This works great, however,
it also cuts off the audio at the end by the same amount. So a 10 min file only plays for 9:24.

 

Coordinator
Sep 30, 2012 at 6:30 AM

You need to ensure the SourceLength is set up correctly

Oct 1, 2012 at 2:09 PM

Ok, I thought I set it up already, but maybe I was doing it wrong.

I set the SourceLength = to the TotalTime of the file being delayed. This didn't solve my problem however.

 

// Check to see if the Directory of each Audio Sample being compared are the same
if (Sample[i].Directory == Sample[i + 1].Directory)
{
     // If the Directories are equal, then check to see which Audio Sample has an earlier Write_Time
     if (Sample[i].Write_Time < Sample[i + 1].Write_Time)
     {
          Sample[i].Position = 0;
          time = Sample[i + 1].Write_Time - Sample[i].Write_Time;
          Sample[i + 1].Pre_Delay = time;
          Sample[i + 1].Read_Length = Sample[i + 1].TotalTime;
     }
     else if (Sample[i].Write_Time > Sample[i + 1].Write_Time)
     {
          Sample[i + 1].Position = 0;
          time = Sample[i].Write_Time - Sample[i + 1].Write_Time;
          Sample[i].Pre_Delay = time;
          Sample[i].Read_Length = Sample[i].TotalTime;
     }
}
else
{
     Sample[i].Position = 0;
}

 


public TimeSpan Read_Length
{
     get
     {
          return offset_stream.SourceLength;
     }
     set
     {
          offset_stream.SourceLength = value;
     }
}

 

Oct 2, 2012 at 7:16 PM

I found my issue:

offset_stream = new WaveOffsetStream(file_stream);

I'm not passing the TimeSpan value(s) to WaveOffsetStream. Thanks for the advice, it caused me to take another look :-)