~aleteoryx/muditaos

muditaos/module-audio/Audio/transcode/TransformComposite.cpp -rw-r--r-- 1.9 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "TransformComposite.hpp"
#include "Transform.hpp"

#include <Audio/AudioFormat.hpp>

#include <algorithm>
#include <memory>
#include <initializer_list>

using audio::transcode::Transform;
using audio::transcode::TransformComposite;

TransformComposite::TransformComposite(std::vector<std::shared_ptr<Transform>> transforms) : children(transforms)
{}

auto TransformComposite::transform(const Span &input, const Span &conversionSpace) const -> Span
{
    auto output = input;

    for (auto t : children) {
        output = t->transform(output, conversionSpace);
    }
    return output;
}

auto TransformComposite::validateInputFormat(const audio::AudioFormat &inputFormat) const noexcept -> bool
{
    auto checkFormat = inputFormat;

    for (auto t : children) {
        if (!t->validateInputFormat(checkFormat)) {
            return false;
        }
        checkFormat = t->transformFormat(checkFormat);
    }

    return true;
}

auto TransformComposite::transformFormat(const audio::AudioFormat &inputFormat) const noexcept -> audio::AudioFormat
{
    auto outputFormat = inputFormat;

    for (auto t : children) {
        outputFormat = t->transformFormat(outputFormat);
    }

    return outputFormat;
}

auto TransformComposite::transformBlockSize(std::size_t blockSize) const noexcept -> std::size_t
{
    std::size_t transformedBlockSize = blockSize;

    for (auto t : children) {
        transformedBlockSize = t->transformBlockSize(transformedBlockSize);
    }

    return transformedBlockSize;
}

auto TransformComposite::transformBlockSizeInverted(std::size_t blockSize) const noexcept -> std::size_t
{
    std::size_t transformedBlockSize = blockSize;

    for (auto t : children) {
        transformedBlockSize = t->transformBlockSizeInverted(transformedBlockSize);
    }

    return transformedBlockSize;
}