Skip to content

Commit

Permalink
Add support for hashing from raw sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Mar 2, 2025
1 parent 82ff2d3 commit 83ee767
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion include/ResourceCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <fstream>
#include <memory>
#include <unordered_map>
#include "SampleFrame.h"

namespace lmms {
class ResourceCache
Expand Down Expand Up @@ -96,7 +97,7 @@ class ResourceCache

static void hash(QCryptographicHash& hasher, const std::string& base64Audio, int sampleRate)
{
hasher.addData(QByteArray::fromStdString(base64Audio));
hash(hasher, base64Audio);
hasher.addData(reinterpret_cast<const char*>(&sampleRate), sizeof(sampleRate));
}

Expand All @@ -105,6 +106,20 @@ class ResourceCache
hasher.addData(QByteArray::fromStdString(str));
}

static void hash(QCryptographicHash& hasher, const SampleFrame* data, size_t size, int sampleRate)
{
hash(hasher, data, size);
hasher.addData(reinterpret_cast<const char*>(&sampleRate), sizeof(sampleRate));
}

static void hash(QCryptographicHash& hasher, const SampleFrame* data, size_t size)
{
for (auto i = std::size_t{0}; i < size; ++i)
{
hasher.addData(reinterpret_cast<const char*>(data + i), sizeof(SampleFrame));
}
}

ResourceCache() { s_resources.reserve(CacheSize); }
inline static std::unordered_map<std::string, std::shared_ptr<Resource>> s_resources;
};
Expand Down

0 comments on commit 83ee767

Please sign in to comment.