carb/audio/IAudioCapture.h
File members: carb/audio/IAudioCapture.h
// Copyright (c) 2018-2023, 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 "../assets/IAssets.h"
#include "AudioTypes.h"
namespace carb
{
namespace audio
{
/******************************** typedefs, enums, & macros **************************************/
typedef void(CARB_ABI* DeviceChangeCallback)(Context* context, void* userData);
typedef uint32_t CaptureDeviceFlags;
constexpr CaptureDeviceFlags fCaptureDeviceFlagIgnoreOverruns = 0x1;
struct CaptureDeviceDesc
{
CaptureDeviceFlags flags = 0;
size_t deviceIndex = 0;
size_t frameRate = 0;
size_t channels = 0;
SampleFormat sampleFormat = SampleFormat::eDefault;
size_t bufferLength = 0;
UnitType lengthType = UnitType::eFrames;
size_t bufferFragments = 8;
void* ext = nullptr;
};
typedef uint32_t CaptureContextFlags;
struct CaptureContextDesc
{
CaptureContextFlags flags = 0;
DeviceChangeCallback changeCallback = nullptr;
void* callbackContext = nullptr;
CaptureDeviceDesc device;
void* ext = nullptr;
};
struct LockRegion
{
void* ptr1;
size_t len1;
void* ptr2;
size_t len2;
};
/********************************** IAudioCapture Interface **************************************/
struct IAudioCapture
{
CARB_PLUGIN_INTERFACE("carb::audio::IAudioCapture", 1, 0)
/************************ device and context management functions ****************************/
size_t(CARB_ABI* getDeviceCount)();
AudioResult(CARB_ABI* getDeviceCaps)(size_t deviceIndex, DeviceCaps* caps);
Context*(CARB_ABI* createContext)(const CaptureContextDesc* desc);
AudioResult(CARB_ABI* destroyContext)(Context* context);
AudioResult(CARB_ABI* setSource)(Context* context, const CaptureDeviceDesc* desc);
bool(CARB_ABI* isSourceValid)(Context* context);
/**************************** capture state management functions *****************************/
AudioResult(CARB_ABI* captureStart)(Context* context, bool looping);
AudioResult(CARB_ABI* captureStop)(Context* context);
AudioResult(CARB_ABI* getCaptureCursor)(Context* context, UnitType type, size_t* position);
bool(CARB_ABI* isCapturing)(Context* context);
/********************************* data management functions *********************************/
AudioResult(CARB_ABI* lock)(Context* context, size_t length, LockRegion* region);
AudioResult(CARB_ABI* unlock)(Context* context);
size_t(CARB_ABI* calculateReadBufferSize)(Context* context, size_t frameCount);
AudioResult(CARB_ABI* read)(Context* context, void* buffer, size_t lengthInFrames, size_t* framesRead);
size_t(CARB_ABI* getBufferSize)(Context* context, UnitType type);
AudioResult(CARB_ABI* getSoundFormat)(Context* context, SoundFormat* format);
AudioResult(CARB_ABI* clear)(Context* context);
AudioResult(CARB_ABI* getAvailableFrames)(Context* context, size_t* available);
};
} // namespace audio
} // namespace carb