| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsCorePrerequisites.h" |
| 6 | |
| 7 | namespace bs |
| 8 | { |
| 9 | /** @addtogroup Audio |
| 10 | * @{ |
| 11 | */ |
| 12 | |
| 13 | /** Provides various utility functionality relating to audio. */ |
| 14 | class BS_CORE_EXPORT AudioUtility |
| 15 | { |
| 16 | public: |
| 17 | /** |
| 18 | * Converts a set of audio samples using multiple channels into a set of mono samples. |
| 19 | * |
| 20 | * @param[in] input A set of input samples. Per-channels samples should be interleaved. Size of each sample |
| 21 | * is determined by @p bitDepth. Total size of the buffer should be @p numSamples * |
| 22 | * @p numChannels * @p bitDepth / 8. |
| 23 | * @param[out] output Pre-allocated buffer to store the mono samples. Should be of @p numSamples * |
| 24 | * @p bitDepth / 8 size. |
| 25 | * @param[in] bitDepth Size of a single sample in bits. |
| 26 | * @param[in] numSamples Number of samples per a single channel. |
| 27 | * @param[in] numChannels Number of channels in the input data. |
| 28 | */ |
| 29 | static void convertToMono(const UINT8* input, UINT8* output, UINT32 bitDepth, UINT32 numSamples, UINT32 numChannels); |
| 30 | |
| 31 | /** |
| 32 | * Converts a set of audio samples of a certain bit depth to a new bit depth. |
| 33 | * |
| 34 | * @param[in] input A set of input samples. Total size of the buffer should be @p numSamples * |
| 35 | * @p inBitDepth / 8. |
| 36 | * @param[in] inBitDepth Size of a single sample in the @p input array, in bits. |
| 37 | * @param[out] output Pre-allocated buffer to store the output samples in. Total size of the buffer should be |
| 38 | * @p numSamples * @p outBitDepth / 8. |
| 39 | * @param[in] outBitDepth Size of a single sample in the @p output array, in bits. |
| 40 | * @param[in] numSamples Total number of samples to process. |
| 41 | */ |
| 42 | static void convertBitDepth(const UINT8* input, UINT32 inBitDepth, UINT8* output, UINT32 outBitDepth, UINT32 numSamples); |
| 43 | |
| 44 | /** |
| 45 | * Converts a set of audio samples of a certain bit depth to a set of floating point samples in range [-1, 1]. |
| 46 | * |
| 47 | * @param[in] input A set of input samples. Total size of the buffer should be @p numSamples * |
| 48 | * @p inBitDepth / 8. All input samples should be signed integers. |
| 49 | * @param[in] inBitDepth Size of a single sample in the @p input array, in bits. |
| 50 | * @param[out] output Pre-allocated buffer to store the output samples in. Total size of the buffer should be |
| 51 | * @p numSamples * sizeof(float). |
| 52 | * @param[in] numSamples Total number of samples to process. |
| 53 | */ |
| 54 | static void convertToFloat(const UINT8* input, UINT32 inBitDepth, float* output, UINT32 numSamples); |
| 55 | |
| 56 | /** |
| 57 | * Converts a 24-bit signed integer into a 32-bit signed integer. |
| 58 | * |
| 59 | * @param[in] input 24-bit signed integer as an array of 3 bytes. |
| 60 | * @return 32-bit signed integer. |
| 61 | */ |
| 62 | static INT32 convert24To32Bits(const UINT8* input); |
| 63 | }; |
| 64 | |
| 65 | /** @} */ |
| 66 | } |