Loading...
Searching...
No Matches
WaveformSummary.hpp
1#pragma once
2#include <algorithm>
3#include <cstdint>
4#include <memory>
5
6namespace Media
7{
8// Remove the compile time overhead of std::pair for this
10{
11 float first, second;
12};
13
32{
34 int64_t bucket{};
35
37 int64_t bucketCount{};
38
39 int32_t channels{};
40
42 int64_t frames{};
43
45 std::unique_ptr<FloatPair[]> data;
46
47 const FloatPair* channel(int c) const noexcept
48 {
49 return data.get() + c * bucketCount;
50 }
51
59 static int64_t bucketFor(int64_t frames, int32_t channels) noexcept
60 {
61 constexpr int64_t max_bytes = 32ll * 1024 * 1024;
62 constexpr int64_t max_bucket = 1ll << 20;
63 const int64_t max_buckets
64 = max_bytes / (int64_t(sizeof(FloatPair)) * std::max(1, int(channels)));
65
66 int64_t b = 64;
67 while(b < max_bucket && frames / b > max_buckets)
68 b *= 2;
69 return b;
70 }
71};
72}
Definition WaveformSummary.hpp:10
Definition WaveformSummary.hpp:32
std::unique_ptr< FloatPair[]> data
channels * bucketCount pairs, channel-major.
Definition WaveformSummary.hpp:45
int64_t bucketCount
Buckets per channel. The last one may cover fewer than bucket frames.
Definition WaveformSummary.hpp:37
static int64_t bucketFor(int64_t frames, int32_t channels) noexcept
Definition WaveformSummary.hpp:59
int64_t frames
Frames the summary accounts for.
Definition WaveformSummary.hpp:42
int64_t bucket
Frames per bucket. A power of two, at least 64.
Definition WaveformSummary.hpp:34