From b4e22218e61fc4667a06dcf9bd71ced2835e97b8 Mon Sep 17 00:00:00 2001 From: oparviai Date: Thu, 30 Aug 2012 16:30:13 +0000 Subject: [PATCH] Added utility function to get elapsed duration i.e. how much so far has been read from the WAV file --- source/SoundStretch/WavFile.cpp | 8 ++++++++ source/SoundStretch/WavFile.h | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/SoundStretch/WavFile.cpp b/source/SoundStretch/WavFile.cpp index 3c4406b..7bc482a 100644 --- a/source/SoundStretch/WavFile.cpp +++ b/source/SoundStretch/WavFile.cpp @@ -651,6 +651,14 @@ uint WavInFile::getLengthMS() const } +/// Returns how many milliseconds of audio have so far been read from the file +uint WavInFile::getElapsedMS() const +{ + return (uint)(1000.0 * (double)dataRead / (double)header.format.byte_rate); +} + + + ////////////////////////////////////////////////////////////////////////////// // // Class WavOutFile diff --git a/source/SoundStretch/WavFile.h b/source/SoundStretch/WavFile.h index cde1079..3a47352 100644 --- a/source/SoundStretch/WavFile.h +++ b/source/SoundStretch/WavFile.h @@ -116,8 +116,11 @@ private: /// File pointer. FILE *fptr; + /// Position within the audio stream + long position; + /// Counter of how many bytes of sample data have been read from the file. - uint dataRead; + long dataRead; /// WAV header information WavHeader header; @@ -175,6 +178,11 @@ public: /// Get the audio file length in milliseconds uint getLengthMS() const; + /// Returns how many milliseconds of audio have so far been read from the file + /// + /// \return elapsed duration in milliseconds + uint getElapsedMS() const; + /// Reads audio samples from the WAV file. This routine works only for 8 bit samples. /// Reads given number of elements from the file or if end-of-file reached, as many /// elements as are left in the file.