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.