IWMEncAudienceObj::SetAudioConfig

Windows Media Encoder SDK banner art

The SetAudioConfig method specifies the audio format settings for the current audience.

Syntax

HRESULT SetAudioConfig(
  short  iRenderSiteIndex,
  short  nChannels,
  long  nSamplesPerSec,
  long  lBitrate,
  short  wBitsPerSample
);

Parameters

iRenderSiteIndex

[in]  short containing the audience stream index. Because an audience can only contain one stream of each type, iRenderSiteIndex must be zero.

nChannels

[in]  short containing the number of channels; for example, 2 for stereo or 1 for mono.

nSamplesPerSec

[in]  long containing the sampling rate, specified in samples per second (Hz).

lBitrate

[in]  long containing the bit rate, specified in bits per second (bps).

wBitsPerSample

[in]  short containing the bits per sample.

Return Values

If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.

Remarks

Use SetAudioConfig to select an audio format for the current audience by specifying its configuration settings. You must specify the settings of an audio format that is supported by the audio codec used by the current audience.

You can also use IWMEncProfile2::EnumAudioFormat to enumerate the supported audio formats and their settings, then use the put_AudioFormat method to specify the index of the audio format to use.

Example Code

// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"

    // Declare variables.
    HRESULT hr;
    IWMEncProfile2* pPro2;
    IWMEncAudienceObj* pAudnc;

    // Initialize the COM library and retrieve a pointer to an IWMEncProfile2 interface.
    hr = CoInitialize(NULL);

    if ( SUCCEEDED( hr ) )
    {
        hr = CoCreateInstance(CLSID_WMEncProfile2,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWMEncProfile2,
            (void**) &pPro2);
    }

    // Verify profile settings immediately as they are set.
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_ValidateMode(VARIANT_TRUE);
    }

    // Provide a name and description.
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_ProfileName(CComBSTR("Sample Profile"));
    }
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_ProfileDescription(CComBSTR("A test profile."));
    }

    // Set the profile's content type to audio and video.
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_ContentType(17);
    }

    // Set the VBR mode for both audio and video to CBR.
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_VBRMode(WMENC_AUDIO, 0, WMENC_PVM_NONE);
    }
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->put_VBRMode(WMENC_VIDEO, 0, WMENC_PVM_NONE);
    }

    // Add a new audience with a bit rate of 100 Kbps. By default, the WMA and
    // WMV codecs are used. The audio format defaults to the one closest to the
    // specified bit rate (10 Kbps, 16 kHz, mono CBR).
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->AddAudience(100000, &pAudnc);
    }

    // Change the audio configuration to 8 Kbps, 8 kHz, mono CBR.
    if ( SUCCEEDED( hr ) )
    {
        hr = pAudnc->SetAudioConfig(0, 1, 8000, 8000, 16);
    }


    // Release pointers.
    if ( pAudnc )
    {
        pAudnc->Release();
        pAudnc = NULL;
    }
    if ( pPro2 )
    {
        pPro2->Release();
        pPro2 = NULL;
    }

Requirements

Header: wmencode.h

Library: wmenc.exe

See Also