Skip to content

Commit

Permalink
Merge branch 'release/1.0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstark committed Jan 23, 2021
2 parents e703a38 + e72f103 commit b7dd84a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
34 changes: 31 additions & 3 deletions AudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,25 @@ bool AudioFile<T>::load (std::string filePath)
return false;
}

file.unsetf (std::ios::skipws);
std::istream_iterator<uint8_t> begin (file), end;
std::vector<uint8_t> fileData (begin, end);
std::vector<uint8_t> fileData;

file.unsetf (std::ios::skipws);

file.seekg (0, std::ios::end);
size_t length = file.tellg();
file.seekg (0, std::ios::beg);

// allocate
fileData.resize (length);

file.read(reinterpret_cast<char*> (fileData.data()), length);
file.close();

if (file.gcount() != length)
{
reportError ("ERROR: Couldn't read entire file\n" + filePath);
return false;
}

// get audio file format
audioFileFormat = determineAudioFileFormat (fileData);
Expand Down Expand Up @@ -564,6 +580,12 @@ bool AudioFile<T>::decodeWaveFile (std::vector<uint8_t>& fileData)
{
int sampleIndex = samplesStartIndex + (numBytesPerBlock * i) + channel * numBytesPerSample;

if ((sampleIndex + (bitDepth / 8) - 1) >= fileData.size())
{
reportError ("ERROR: read file error as the metadata indicates more samples than there are in the file data");
return false;
}

if (bitDepth == 8)
{
T sample = singleByteToSample (fileData[sampleIndex]);
Expand Down Expand Up @@ -702,6 +724,12 @@ bool AudioFile<T>::decodeAiffFile (std::vector<uint8_t>& fileData)
{
int sampleIndex = samplesStartIndex + (numBytesPerFrame * i) + channel * numBytesPerSample;

if ((sampleIndex + (bitDepth / 8) - 1) >= fileData.size())
{
reportError ("ERROR: read file error as the metadata indicates more samples than there are in the file data");
return false;
}

if (bitDepth == 8)
{
int8_t sampleAsSigned8Bit = (int8_t)fileData[sampleIndex];
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#===============================================================================
cmake_minimum_required (VERSION 3.12)

project ("AudioFile" VERSION 1.0.8
project ("AudioFile" VERSION 1.0.9
DESCRIPTION "A simple C++ library for reading and writing audio files."
HOMEPAGE_URL "https://github.com/adamstark/AudioFile")

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AudioFile

<!-- Version and License Badges -->
![Version](https://img.shields.io/badge/version-1.0.8-green.svg?style=flat-square)
![Version](https://img.shields.io/badge/version-1.0.9-green.svg?style=flat-square)
![License](https://img.shields.io/badge/license-GPL-blue.svg?style=flat-square)
![Language](https://img.shields.io/badge/language-C++-yellow.svg?style=flat-square)

Expand Down Expand Up @@ -156,6 +156,11 @@ If you prefer not to see these messages, you can disable this error logging beha
Versions
-------

##### 1.0.9 - 23rd January 2021

- Faster loading of audio files
- Bug fixes

##### 1.0.8 - 18th October 2020

- CMake support
Expand Down Expand Up @@ -198,6 +203,7 @@ Contributions
* Read/write of iXML data chunks ([mynameisjohn](https://github.com/mynameisjohn))
* Remove warnings ([Abhinav1997](https://github.com/Abhinav1997))
* Better support on Ubuntu ([BenjaminHinchliff](https://github.com/BenjaminHinchliff))
* Faster loading of audio files ([helloimmatt](https://github.com/helloimmatt/))

Want to Contribute?
-------
Expand Down

0 comments on commit b7dd84a

Please sign in to comment.