Rediger

Del via


To Decode Audio to S/PDIF

[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Audio encoded with the Windows Media Audio 9 Professional codec can be decoded to Sony/Philips Digital Interconnect Format (S/PDIF). To generate S/PDIF output, perform the following steps:

  1. Open a file that contains a Windows Media Audio 9 Professional stream by calling the IWMReader::Open method.
  2. Identify the output number of the stream that you want. For more information, see To Identify Output Numbers.
  3. Call the IWMReaderAdvanced2::SetOutputSetting method to configure S/PDIF output. Use g_wszEnableWMAProSPDIFOutput for the setting name. The data type is WMT_TYPE_BOOL; set the value to TRUE to enable S/PDIF output.
  4. Get the output properties interface (IWMOutputMediaProps) of the desired output format by calling the IWMReader::GetOutputFormat method. For more information about enumerating output formats, see Assigning Output Formats.
  5. Set the output format by calling the IWMReader::SetOutputProps method. Pass in a pointer to the IWMOutputMediaProps interface obtained in step 4.
  6. Make any other configuration changes and begin playback.

Note

You can perform the preceding steps on the synchronous reader by using the corresponding methods of the IWMSyncReader interface.

 

The following example code demonstrates how to set an audio stream to output audio as S/PDIF data. This function assumes that a file has already been loaded in the reader and that the output number has been identified. For more information about using this code, see Using the Code Examples.

HRESULT SetSPDIF(DWORD dwOutputNum, IWMReader* pReader)
{
    HRESULT hr = S_OK;

    IWMReaderAdvanced2*  pReaderAdv   = NULL;
    IWMOutputMediaProps* pOutputProps = NULL; 

    BOOL fValue = TRUE;

    // Get the advanced reader interface.
    hr = pReader->QueryInterface(IID_IWMReaderAdvanced2,
                                 (void**)&pReaderAdv);
    GOTO_EXIT_IF_FAILED(hr);

    // Set S/PDIF output.
    hr = pReaderAdv->SetOutputSetting(dwOutputNum, 
                                      g_wszEnableWMAProSPDIFOutput, 
                                      WMT_TYPE_BOOL, 
                                      (BYTE*)&fValue, 
                                      sizeof(BOOL));
    GOTO_EXIT_IF_FAILED(hr);

    // Get the first output format for the stream.
    // NOTE: You could also enumerate the available output formats
    // and pick one to use.

    hr = pReader->GetOutputFormat(dwOutputNum, 0, &pOutputProps);
    GOTO_EXIT_IF_FAILED(hr);

    // Set the output properties back on the reader.
    hr = pReader->SetOutputProps(dwOutputNum, pOutputProps);

Exit:
    SAFE_RELEASE(pReaderAdv);
    SAFE_RELEASE(pOutputProps);

    return hr;
}

Advanced Topics

Reading ASF Files

IWMReader Interface

IWMReaderAdvanced2 Interface

IWMSyncReader Interface