carb/audio/IAudioUtils.h

File members: carb/audio/IAudioUtils.h

// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once

#include "../Interface.h"
#include "AudioTypes.h"
#include "IAudioData.h"

namespace carb
{
namespace audio
{

/************************************* Interface Objects *****************************************/
struct OutputStream;

/********************************* Sound Data Conversion Objects *********************************/
typedef uint32_t ConvertFlags;

constexpr ConvertFlags fConvertFlagInPlace = 0x00000001;

constexpr ConvertFlags fConvertFlagCopy = 0x00000002;

constexpr ConvertFlags fConvertFlagReferenceData = 0x00000004;

constexpr ConvertFlags fConvertFlagForceCopy = 0x00000008;
struct ConversionDesc
{
    ConvertFlags flags = 0;

    SoundData* soundData;

    SampleFormat newFormat = SampleFormat::eDefault;

    void* encoderSettings = nullptr;

    void* readCallbackContext = nullptr;

    SoundDataDestructionCallback destructionCallback = nullptr;

    void* destructionCallbackContext = nullptr;

    void* ext = nullptr;
};

typedef uint32_t TranscodeFlags;

struct TranscodeDesc
{
    TranscodeFlags flags = 0;

    SampleFormat inFormat;

    SampleFormat outFormat;

    const void* inBuffer;

    void* outBuffer;

    size_t samples;

    void* ext = nullptr;
};

/*********************************** Sound Data Output Objects ***********************************/
typedef uint32_t SaveFlags;

constexpr SaveFlags fSaveFlagDefault = 0x00000000;

constexpr SaveFlags fSaveFlagStripMetaData = 0x00000001;

constexpr SaveFlags fSaveFlagStripEventPoints = 0x00000002;

constexpr SaveFlags fSaveFlagStripPeaks = 0x00000004;

struct SoundDataSaveDesc
{
    SaveFlags flags = 0;

    SampleFormat format = SampleFormat::eDefault;

    const SoundData* soundData;

    const char* filename;

    void* encoderSettings = nullptr;

    void* ext = nullptr;
};

typedef uint32_t OutputStreamFlags;

constexpr OutputStreamFlags fStreamFlagFlushAfterWrite = 0x00000001;

constexpr OutputStreamFlags fStreamFlagDisableOnFailure = 0x00000002;

struct OutputStreamDesc
{
    OutputStreamFlags flags = 0;

    const char* filename;

    SampleFormat inputFormat;

    SampleFormat outputFormat = SampleFormat::eDefault;

    size_t frameRate;

    size_t channels;

    void* encoderSettings = nullptr;

    void* ext = nullptr;
};

/********************************* Audio Visualization Objects ***********************************/
using AudioImageFlags = uint32_t;

constexpr AudioImageFlags fAudioImageNoClear = 0x01;

constexpr AudioImageFlags fAudioImageUseLines = 0x02;

constexpr AudioImageFlags fAudioImageNoiseColor = 0x04;

constexpr AudioImageFlags fAudioImageMultiChannel = 0x08;

constexpr AudioImageFlags fAudioImageAlphaBlend = 0x10;

constexpr AudioImageFlags fAudioImageSplitChannels = 0x20;

struct AudioImageDesc
{
    AudioImageFlags flags;

    const SoundData* sound;

    size_t length;

    int64_t offset;

    UnitType lengthType;

    size_t channel;

    void* image;

    size_t width;

    size_t pitch;

    size_t height;

    Float4 background;

    Float4 colors[kMaxChannels];
};

struct IAudioUtils
{
    CARB_PLUGIN_INTERFACE("carb::audio::IAudioUtils", 1, 0)

    /*************************** Sound Data Object Modifications ********************************/
    bool(CARB_ABI* clearToSilence)(SoundData* sound);

    /**************************** Sound Data Saving and Streaming ********************************/
    bool(CARB_ABI* saveToFile)(const SoundDataSaveDesc* desc);

    OutputStream*(CARB_ABI* openOutputStream)(const OutputStreamDesc* desc);

    void(CARB_ABI* closeOutputStream)(OutputStream* stream);

    bool(CARB_ABI* writeDataToStream)(OutputStream* stream, const void* data, size_t lengthInFrames);

    /***************************** Sound Data Format Conversion **********************************/
    carb::audio::SoundData*(CARB_ABI* convert)(const ConversionDesc* desc);

    carb::audio::SoundData*(CARB_ABI* duplicate)(const SoundData* sound);

    bool(CARB_ABI* transcodePcm)(const TranscodeDesc* desc);

    /***************************** Audio Visualization *******************************************/
    bool(CARB_ABI* drawWaveform)(const AudioImageDesc* desc);
};

} // namespace audio

} // namespace carb