Skip to content

Commit

Permalink
Make magic_map a global constant to avoid creating temporary instanc…
Browse files Browse the repository at this point in the history
…es on every call
  • Loading branch information
SamVanheer committed Sep 25, 2022
1 parent e95e517 commit be65e2c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,21 @@ void NyquistIO::Load(AudioData * data, const std::string & path)

namespace
{
const char no_extension[]{"none"};
}

void NyquistIO::Load(AudioData * data, const std::vector<uint8_t> & buffer)
{

const std::map<std::vector<int16_t>, std::string> magic_map{
static const std::map<std::vector<int16_t>, std::string> magic_map{
{{ 'w', 'v', 'p', 'k' }, "wv" },
{{ 'M', 'P', 'C', 'K' }, "mpc" },
{{ 0xFF, 0xFB }, "mp3" }, // ÿû, mp3 without ID3 header
{{ 'I', 'D', '3' }, "mp3" }, // mp3 with ID3 header
{{ 'O', 'g', 'g', 'S' }, "ogg_or_vorbis" }, // see `match_ogg_subtype`
{{ 'f', 'L', 'a', 'C' }, "flac" },
{{ 0x52, 0x49, 0x46, 0x46, -0x1, -0x1, -0x1, -0x1, 0x57, 0x41, 0x56, 0x45 }, "wav" } // RIFF....WAVE
};
};

const char no_extension[]{"none"};
}

void NyquistIO::Load(AudioData * data, const std::vector<uint8_t> & buffer)
{
auto match_magic = [](const uint8_t * data, const std::vector<int16_t> & magic)
{
for (int i = 0; i < magic.size(); ++i)
Expand Down

0 comments on commit be65e2c

Please sign in to comment.