//
//  AudioBufferConversion.hpp
//  SwitchboardSDK
//
//  Created by Balazs Kiss on 2025. 12. 16.
//

#pragma once

#include <switchboard/export.h>
#include <switchboard_core/AudioBuffer.hpp>
#include <switchboard_core/SwitchboardCore.hpp>

namespace switchboard {

/**
 *  @brief Interleaves input buffer channels into output buffer.
 *  @details Input and output buffers must have the same number of channels. Input and output buffers must have the same number of frames.
 *
 *  @param inputBuffer AudioBuffer to be interleaved. Must be non-interleaved.
 *  @param outputBuffer AudioBuffer to store input data. Must be interleaved.
 */
template <typename T>
void interleave(const AudioBuffer<T>& inputBuffer, AudioBuffer<T>& outputBuffer);

/**
 *  @brief Deinterleaves input buffer into output buffer channels
 *  @details Input and output buffers must have the same number of channels. Input and output buffers must have the same number of frames.
 *
 *  @param inputBuffer AudioBuffer to be deinterleaved. Must be interleaved.
 *  @param outputBuffer AudioBuffer to store input data. Must be non-interleaved.
 */
template <typename T>
void SWITCHBOARDSDK_EXPORT deinterleave(const AudioBuffer<T>& inputBuffer, AudioBuffer<T>& outputBuffer);

/**
 *  @brief Converts float AudioBuffer to int16 AudioBuffer.
 *  @details Input and output buffers must have the same number of channels and same number of frames.
 *
 *  @param inputBuffer The float AudioBuffer that needs to be converted.
 *  @param outputBuffer The int16 AudioBuffer that will store the converted data.
 */
void SWITCHBOARDSDK_EXPORT floatToShortInt(const AudioBuffer<float>& inputBuffer, AudioBuffer<int16_t>& outputBuffer);

/**
 *  @brief Converts int16 AudioBuffer to float AudioBuffer.
 *  @details Input and output buffers must have the same number of channels. Input and output buffers must have the same number of frames.
 *
 *  @param inputBuffer The int16 AudioBuffer that needs to be converted.
 *  @param outputBuffer The float AudioBuffer that will store the converted data.
 */
void SWITCHBOARDSDK_EXPORT shortIntToFloat(const AudioBuffer<int16>& inputBuffer, AudioBuffer<float>& outputBuffer);

}
