Struct RAWAudioFrame
- Namespace
- VisioForge.Core.Types
- Assembly
- VisioForge.Core.dll
Represents a raw audio frame, designed for direct memory manipulation and interop scenarios. This struct holds a pointer to the raw audio data, its size, and basic audio format information, along with timing details.
public struct RAWAudioFrameInherited Members
Examples
// Example of receiving a RAWAudioFrame from a native component (conceptual)
public void ProcessRawAudio(RAWAudioFrame rawFrame)
{
Console.WriteLine($"Received raw audio frame: {rawFrame.DataSize} bytes at {rawFrame.Timestamp} ms.");
// Convert to managed AudioFrame for easier processing if needed
AudioFrame audioFrame = rawFrame.ToAudioFrame();
// Now you can work with audioFrame.GetDataArray() or other managed properties
byte[] audioData = audioFrame.GetDataArray();
Console.WriteLine($"Converted to AudioFrame with {audioData.Length} bytes.");
// Important: If the RAWAudioFrame.Data was allocated by a native component,
// ensure it is freed when no longer needed, typically by the component that allocated it.
}
Remarks
This struct is marked with [StructLayout(LayoutKind.Sequential)] to ensure its memory layout is compatible with unmanaged code.
It is primarily used for high-performance audio processing where direct access to audio buffers is required.
The VisioForge.Core.Types.RAWAudioFrame.Data field is an IntPtr, meaning memory management (allocation and deallocation) for the audio data buffer
must be handled externally or by converting to VisioForge.Core.Types.AudioFrame which manages its own data.
This struct is commonly used in callbacks from native audio components or in high-throughput audio processing pipelines.
The timing fields (Timestamp and Duration) are in milliseconds for compatibility with native code, unlike the managed AudioFrame which uses TimeSpan.
When receiving a RAWAudioFrame from native code, ensure that the memory pointed to by Data remains valid for the duration of processing.
Fields
Data
A pointer to the unmanaged memory buffer containing the raw audio data.
public nint DataField Value
DataSize
The size of the raw audio data buffer in bytes.
public int DataSizeField Value
Duration
The duration of the audio frame in milliseconds.
public long DurationField Value
Info
Contains detailed information about the raw audio format, such as channels, sample rate, and bit depth.
public RAWBaseAudioInfo InfoField Value
Timestamp
The presentation timestamp of the audio frame in milliseconds.
public long TimestampField Value
Methods
ToAudioFrame()
Converts the current VisioForge.Core.Types.RAWAudioFrame instance into an VisioForge.Core.Types.AudioFrame object. This conversion facilitates working with the audio frame in a more managed and object-oriented way.
public AudioFrame ToAudioFrame()Returns
- AudioFrame
-
A new VisioForge.Core.Types.AudioFrame instance populated with data from the raw frame.