Skip to content

Commit

Permalink
test in-memory decoding of ogg
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiakopoulos committed Apr 2, 2018
1 parent 6640c05 commit c8e8eda
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -121,6 +122,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion examples/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, const char **argv) try
//loader.Load(fileData.get(), "test_data/1ch/44100/8/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/16/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/24/test.wav");
loader.Load(fileData.get(), "test_data/1ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/64/test.wav");

// 2-channel wave
Expand Down Expand Up @@ -85,6 +85,10 @@ int main(int argc, const char **argv) try
// 1 + 2 channel musepack
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_stereo.mpc");
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_mono.mpc");

// In-memory ogg
auto memory = ReadFile("test_data/ad_hoc/BlockWoosh_Stereo.ogg");
loader.Load(fileData.get(), "ogg", memory.buffer);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions include/libnyquist/AudioDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef std::pair<std::string, std::shared_ptr<nqr::BaseDecoder>> DecoderPair;
class NyquistIO
{
std::string ParsePathForExtension(const std::string & path) const;
std::shared_ptr<nqr::BaseDecoder> GetDecoderForExtension(const std::string ext);
std::shared_ptr<nqr::BaseDecoder> GetDecoderForExtension(const std::string & ext);
void BuildDecoderTable();
void AddDecoderToTable(std::shared_ptr<nqr::BaseDecoder> decoder);
std::map<std::string, std::shared_ptr<BaseDecoder>> decoderTable;
Expand All @@ -72,8 +72,8 @@ class NyquistIO
NyquistIO();
~NyquistIO();
void Load(AudioData * data, const std::string & path);
void Load(AudioData *data, std::string extension, const std::vector<uint8_t> & buffer);
bool IsFileSupported(const std::string path) const;
void Load(AudioData * data, const std::string & extension, const std::vector<uint8_t> & buffer);
bool IsFileSupported(const std::string & path) const;
};

} // end namespace nqr
Expand Down
2 changes: 1 addition & 1 deletion include/libnyquist/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct NyquistFileBuffer
size_t size;
};

NyquistFileBuffer ReadFile(std::string pathToFile);
NyquistFileBuffer ReadFile(const std::string & pathToFile);

int GetFormatBitsPerSample(PCMFormat f);
PCMFormat MakeFormatForBits(int bits, bool floatingPt, bool isSigned);
Expand Down
6 changes: 3 additions & 3 deletions src/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void NyquistIO::Load(AudioData * data, const std::string & path)
}
}

void NyquistIO::Load(AudioData * data, std::string extension, const std::vector<uint8_t> & buffer)
void NyquistIO::Load(AudioData * data, const std::string & extension, const std::vector<uint8_t> & buffer)
{
if (decoderTable.find(extension) == decoderTable.end())
{
Expand All @@ -94,7 +94,7 @@ void NyquistIO::Load(AudioData * data, std::string extension, const std::vector<
}
}

bool NyquistIO::IsFileSupported(const std::string path) const
bool NyquistIO::IsFileSupported(const std::string & path) const
{
auto fileExtension = ParsePathForExtension(path);
if (decoderTable.find(fileExtension) == decoderTable.end()) return false;
Expand All @@ -107,7 +107,7 @@ std::string NyquistIO::ParsePathForExtension(const std::string & path) const
return std::string("");
}

std::shared_ptr<BaseDecoder> NyquistIO::GetDecoderForExtension(const std::string ext)
std::shared_ptr<BaseDecoder> NyquistIO::GetDecoderForExtension(const std::string & ext)
{
if (decoderTable.size()) return decoderTable[ext];
else throw std::runtime_error("No available decoders.");
Expand Down
3 changes: 1 addition & 2 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

using namespace nqr;

NyquistFileBuffer nqr::ReadFile(std::string pathToFile)
NyquistFileBuffer nqr::ReadFile(const std::string & pathToFile)
{
//std::cout << "[Debug] Open: " << pathToFile << std::endl;
FILE * audioFile = fopen(pathToFile.c_str(), "rb");
Expand Down Expand Up @@ -55,7 +55,6 @@ NyquistFileBuffer nqr::ReadFile(std::string pathToFile)

fclose(audioFile);

// Copy out to user
return data;
}

Expand Down

0 comments on commit c8e8eda

Please sign in to comment.