~aleteoryx/muditaos

muditaos/module-audio/Audio/transcode/Transform.hpp -rw-r--r-- 2.8 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
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <Audio/AudioFormat.hpp>
#include <Audio/AbstractStream.hpp>

namespace audio::transcode
{

    /**
     * @brief Data transform which can be applied on a data range.
     */
    class Transform
    {
      public:
        using Span = audio::AbstractStream::Span;

        virtual ~Transform() = default;

        /**
         * @brief Transforms data within range
         *
         * @param inputSpan - input data to transform
         * @param outputSpan - space for transformation output
         * @return Output data
         */
        virtual auto transform(const Span &inputSpan, const Span &outputSpan) const -> Span = 0;

        /**
         * @brief Checks if audio format is suitable for transformation.
         *
         * @param inputFormat - format to be checked
         * @return true if inputFormat is suitable for transformation, false otherwise
         */
        virtual auto validateInputFormat(const audio::AudioFormat &inputFormat) const noexcept -> bool = 0;

        /**
         * @brief Calculates the audio format on transform output based on the
         * input format.
         *
         * @param inputFormat - format of the data on input
         * @return format of the data on output.
         */
        virtual auto transformFormat(const audio::AudioFormat &inputFormat) const noexcept -> audio::AudioFormat = 0;

        /**
         * @brief Calculates the size of an output data after the transform.
         *
         * @param blockSize - size of an input block
         * @return size of an output block
         */
        virtual auto transformBlockSize(std::size_t blockSize) const noexcept -> std::size_t = 0;

        /**
         * @brief Calculates required size of an input data to get transformed data of size equal
         * outputBlockSize
         *
         * @param outputBlockSize - size of an output block
         * @return std::size_t
         */
        virtual auto transformBlockSizeInverted(std::size_t outputBlockSize) const noexcept -> std::size_t = 0;

        /**
         * @brief A convenience transform operator.
         */
        inline auto operator()(const Span &span, const Span &transformSpace)
        {
            return transform(span, transformSpace);
        }

        /**
         * @brief A convenience wrapper for transforms which has transcoding size
         * same as output size and a transcoding operation is performed in-place.
         *
         * @param span to transform
         * @return transformed span
         */
        inline auto transform(const Span &span)
        {
            return transform(span, span);
        }
    };

}; // namespace audio::transcode