22 SNDFILE& file,
const std::vector<std::string>& trustedDistributors)
24 SF_LOOP_INFO loopInfo;
26 sf_command(&file, SFC_GET_LOOP_INFO, &loopInfo,
sizeof(loopInfo)) ==
31 loopInfo.loop_mode == SF_LOOP_BACKWARD ||
32 loopInfo.loop_mode == SF_LOOP_ALTERNATING)
36 if (loopInfo.loop_mode == SF_LOOP_NONE)
39 if (loopInfo.num_beats != 0)
44 std::memset(&info, 0,
sizeof(info));
45 sf_command(&file, SFC_GET_CURRENT_SF_INFO, &info,
sizeof(info));
46 if (info.samplerate == 0 || info.frames == 0)
48 const auto duration = 1. * info.frames / info.samplerate;
56 constexpr std::array<char, 4> listId = {
'L',
'I',
'S',
'T' };
57 std::copy(listId.begin(), listId.end(), info.id);
58 std::fill(info.id +
sizeof(listId), info.id +
sizeof(info.id),
'\0');
59 info.id_size =
sizeof(listId);
60 auto chunkIt = sf_get_chunk_iterator(&file, &info);
63 if (sf_get_chunk_size(chunkIt, &info) != SF_ERR_NO_ERROR)
65 constexpr std::array<char, 4> INFO = {
'I',
'N',
'F',
'O' };
66 constexpr std::array<char, 4> IDST = {
'I',
'D',
'S',
'T' };
68 constexpr auto dataPos =
sizeof(INFO) +
sizeof(IDST) + 4;
69 if (info.datalen < dataPos)
72 const auto chars = std::make_unique<char[]>(info.datalen);
73 info.data = chars.get();
74 if (sf_get_chunk_data(chunkIt, &info) != SF_ERR_NO_ERROR)
76 chunkIt = sf_next_chunk_iterator(chunkIt);
79 const auto firstFour =
80 std::string { chars.get() + pos, chars.get() + pos +
sizeof(INFO) };
81 if (firstFour != std::string { INFO.data(), INFO.size() })
86 std::string { chars.get() + pos, chars.get() + pos +
sizeof(IDST) };
87 if (nextFour != std::string { IDST.data(), IDST.size() })
92 const auto charsEnd = std::find_if(
93 chars.get() + dataPos, chars.get() + info.datalen,
94 [](
const char c) { return c ==
'\0'; });
95 const auto distributor = std::string { chars.get() + 12, charsEnd };
96 const auto isTrusted =
98 trustedDistributors.begin(), trustedDistributors.end(),
99 distributor) != trustedDistributors.end();
std::optional< LibFileFormats::AcidizerTags > GetAcidizerTags(SNDFILE &file, const std::vector< std::string > &trustedDistributors)
Get the Acidizer tags from a file if from a trusted distributor.
void copy(const T *src, T *dst, int32_t n)