Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Audio time resolution.

$
0
0

Thanks again Mark this project is so cool.

I got it to work perfectly but there are a few things to consider

While waveout.position returns the total number of bytes it has passed to the sound card you can’t simply convert that to seconds and subtract that from the current time because it will not be accurate if you jump forward or backward in the audio file.

To overcome this I made a class that inherits from your wavefilereader and gave it a public property BytesRead.

Then override the Read function to count the totalbytes as they are read from the file

Excuse my VB. ;-)

 Public Overrides Function Read(array() As Byte, offset As Integer, cout As IntegerAs Integer 

        BytesRead += count

        Return MyBase.Read(array, offset, count)

 End Function

 

So now I can subtract the number of bytes processed from the number of bytes read to give me a true position.

I placed the following code into a timer to get a high resolution position display regardless of the size of the buffers being read from the file.

Dim span As TimeSpan = waveout1.CurrentTime

DisplayTime.Text = span.TotalSeconds - ((wavereader.BytesRead - waveout1.GetPosition) / waveout1.WaveFormat.AverageBytesPerSecond)

 Thanks again for all of your work with Naudio I love it and I like to pass on my modifications whenever I think you can use them.

Next step here might be for me to override the CurrentTime function to make it all a little more tidy.

Cheers

Max


Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>