Skip to main content

WAV Format

WAV (Waveform Audio File Format) is not a codec but rather an uncompressed audio container format that stores raw PCM (Pulse-Code Modulation) data. The WAV output in VisioForge SDK provides functionality for creating WAV files with various PCM data configurations. Since WAV is uncompressed, it preserves the original audio quality but results in larger file sizes compared to compressed formats like MP3 or AAC.

Understanding WAV Format

WAV files store raw audio samples without any compression. When you "encode" to WAV format, you're essentially:

  1. Organizing raw PCM audio data into the WAV container format
  2. Specifying how the raw data should be interpreted (sample rate, bit depth, channels)
  3. Adding appropriate WAV headers and metadata

This means that a 1-minute stereo WAV file at 44.1kHz with 16-bit samples will always occupy the same amount of space:

File size = Sample Rate × Bit Depth × Channels × Duration / 8
Example: 44100 × 16 × 2 × 60 / 8 = 10,584,000 bytes (approximately 10.1 MB)

Cross-platform MP3 output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)

Features

  • Configurable audio format (default: S16LE)
  • Adjustable sample rate (8kHz - 192kHz)
  • Support for mono and stereo channels

Configuration Options

Audio Format

The encoder supports various audio formats through the AudioFormatX enum. The default format is S16LE (16-bit Little-Endian).

Sample Rate

  • Range: 8,000 Hz to 192,000 Hz
  • Default: 48,000 Hz
  • Step size: 8,000 Hz

Channels

  • Supported values: 1 (mono) or 2 (stereo)
  • Default: 2 (stereo)

Code Examples

Basic Usage

// Create WAV encoder with default settings
var wavEncoder = new WAVEncoderSettings();
// Create encoder with custom settings
var customWavEncoder = new WAVEncoderSettings(
format: AudioFormatX.S16LE,
sampleRate: 44100,
channels: 2
);

Add the WAV output to the Video Capture SDK core instance

// Create a Video Capture SDK core instance
var core = new VideoCaptureCoreX();

// Create a WAV output instance
var wavOutput = new WAVOutput("output.wav");

// Add the WAV output
core.Outputs_Add(wavOutput, true);

Add the WAV output to the Video Edit SDK core instance

// Create a Video Edit SDK core instance
var core = new VideoEditCoreX();

// Create a WAV output instance
var wavOutput = new WAVOutput("output.wav");

// Set the output format
core.Output_Format = wavOutput;

Create a Media Blocks WAV output instance

// Create a WAV encoder settings instance
var wavSettings = new WAVEncoderSettings();

// Create a WAV output instance
var wavOutput = new WAVEncoderBlock(wavSettings);

// Add File Sink block
var fileSink = new FileSinkBlock("output.wav");

// Connect the WAV output to the File Sink
pipeline.Connect(wavOutput.Output, fileSink.Input); // pipeline is MediaBlocksPipeline

Checking Encoder Availability

if (WAVEncoderSettings.IsAvailable())
{
// Encoder is available, proceed with encoding
var encoder = new WAVEncoderSettings();
// ... configure and use encoder
}
else
{
// Handle unavailability
Console.WriteLine("WAV encoder is not available on this system");
}

Custom Configuration

var wavEncoder = new WAVEncoderSettings
{
Format = AudioFormatX.S16LE,
SampleRate = 96000,
Channels = 1 // Mono audio
};

Creating an Encoder Block

var settings = new WAVEncoderSettings();
MediaBlock encoderBlock = settings.CreateBlock();
// Use the encoder block in your media pipeline

Getting Supported Parameters

// Get list of supported formats
IEnumerable<string> formats = WAVEncoderSettings.GetFormatList();

// Get supported sample rates
var settings = new WAVEncoderSettings();
int[] sampleRates = settings.GetSupportedSampleRates();
// Returns array of values from 8000 to 192000 in steps of 8000

// Get supported channel counts
int[] channels = settings.GetSupportedChannelCounts();
// Returns [1, 2] for mono and stereo

Best Practices

  1. Sample Rate Selection:

    • Choose a sample rate appropriate for your audio quality requirements
    • Higher sample rates provide better quality but increase file size
    • Common values: 44.1kHz (CD quality) or 48kHz (professional audio)
  2. Channel Configuration:

    • Use mono (1 channel) for voice recordings or when space is a concern
    • Use stereo (2 channels) for music or when spatial audio is important
  3. Format Selection:

    • S16LE (16-bit Little-Endian) is the most widely compatible format
    • Consider your target platform's requirements when selecting a format

Limitations

  • File size can be large compared to compressed formats like MP3 or AAC