Creating an Audio Application

When you create an audio application, the steps are the same as for other applications, except for additional steps that add audio features.

    To create an audio application

  1. Create a message loop that uses GetMessage or DispatchMessage.
  2. Call GetFormsManager to create an instance of a Forms Manager.
  3. Call the function CreateFormRadio to create a form.

    CreateFormRadio creates a form by loading it from the resource file and getting all the interfaces for the controls contained in the form. As you create a form, get the interface pointers to access the controls. Each Auto PC application must have at least one form.

  4. Start the form.
  5. Add menus.
  6. Add controls and strings.
  7. Initialize the audio manager.

    The audio manager gives you access and control over audio sources. For example, if you want to use the CD player and the radio is running, you need software that stops the radio before starting the CD player.

  8. Initialize the AM/FM tuner.
  9. Create an event sink.

This procedure uses code examples from a sample audio application, Tuneit.cpp, included in the SDK. Tuneit.cpp highlights the use of tuner and audio manager APIs.

In the Tuneit.cpp file, the WinMain function shows how to program a message loop, and the GetFormsManager function shows how the Forms Manager is created. The TuneSink.cpp and TuneSink.h files show how to create an event sink.

Tuneit.cpp has only one form: form radio. The CreateFormRadio function creates a form by loading it from the resource file and getting all the interfaces for the controls contained in the form.

The following code example shows how to set up and initialize an audio manager. It shows only bass and treble; you need to cover all other application settings.

HRESULT
CTuneitApp::InitAudioManager()
{
    long lRet;
    long bMute = FALSE;
    DWORD dwEQCaps = NULL;

    // Verify support for bass and treble
    if(AAM_GetEQCaps(&dwEQCaps))
    {
        return E_FAIL;
    }
    // Set local audio manager storage variables using
    // local flags understood by your resource script
    // menu-loading function.
    if(dwEQCaps & AAM_FLAG_BASS) m_dwfAudioCaps |= FLAG_BASS;
    if(dwEQCaps & AAM_FLAG_TREBLE) m_dwfAudioCaps |= FLAG_TREBLE;

    // Get minimum, maximum, and current bass values.
    if(!AAM_EQPreset(AAM_FLAG_BASS | AAM_FLAG_GET, &lRet))
    {
        m_lSetting[BASS] = lRet;
        AAM_EQPreset(AAM_FLAG_BASS | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
        m_lSettingMin[BASS] = -LOWORD(lRet);
        m_lSettingMax[BASS] = LOWORD(lRet);
    }

    // Get minimum, maximum, and current treble values.
    if(!AAM_EQPreset(AAM_FLAG_TREBLE | AAM_FLAG_GET, &lRet))
    {
        m_lSetting[TREBLE] = lRet;
        AAM_EQPreset(AAM_FLAG_TREBLE | AAM_FLAG_GET | AAM_FLAG_RANGE, &lRet);
        m_lSettingMin[TREBLE] = -LOWORD(lRet);
        m_lSettingMax[TREBLE] = LOWORD(lRet);
    }

    // Turn off mute.
    AAM_VolumeControl(AAM_FLAG_MUTE | AAM_FLAG_SET, &bMute);

    // Set the source to radio.
    AAM_SelectSource(AAM_SRC_TUNER);

    return NOERROR;
}