⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmaudiopaths.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 4 页
字号:
/*-----------------------------------------------------------------------------
 * Copyright (c) Wolfson Microelectronics plc.  All rights reserved.
 *
 * This software as well as any related documentation is furnished under 
 * license and may only be used or copied in accordance with the terms of the 
 * license. The information in this file is furnished for informational use 
 * only, is subject to change without notice, and should not be construed as 
 * a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
 * assumes no responsibility or liability for any errors or inaccuracies that
 * may appear in this document or any software that may be provided in
 * association with this document. 
 *
 * Except as permitted by such license, no part of this document may be 
 * reproduced, stored in a retrieval system, or transmitted in any form or by 
 * any means without the express written consent of Wolfson Microelectronics plc. 
 *
 * $Id: WMAudioPaths.c 2935 2006-04-13 13:27:49Z ian $
 *
 * This file contains definitions and routines for controlling audio paths.
 *
 * NOTE: This code is here as an example. Each application is different
 * and the input paths require will vary. You should optimise these functions
 * for your particular application.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 *---------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMControlLink.h"
#include "WMAudio.h"
#include "WMAudioPaths.h"
#include "WM8753Audio.h"

/*
 * Global definitions
 */

/*
 * Sequences in which to mute/unmute signals
 */
static WM_AUDIO_SIGNAL outputMuteSequence[] =
{
	WM_AUDIO_SPEAKER,
	WM_AUDIO_HEADPHONE,
	WM_AUDIO_MONOOUT,
	WM_AUDIO_OUT3,
	WM_AUDIO_OUT4,
    WM_AUDIO_FRONT_MIXER
};

static WM_AUDIO_SIGNAL outputUnmuteSequence[] =
{
    WM_AUDIO_FRONT_MIXER,
	WM_AUDIO_MONOOUT,
	WM_AUDIO_OUT3,
	WM_AUDIO_OUT4,
	WM_AUDIO_HEADPHONE,
	WM_AUDIO_SPEAKER
};

/*
 * NOTE: Only mute/unmute the WM_AUDIO_VIDEO  and WM_AUDIO_AUXIN inputs 
 * if this is a non-touch build. 
 * On the WM9705 this inputs are used by the touch screen for 
 * X+, X-, Y+ and Y- so unmuting these inputs will cause a lot of noise. 
 * Unfortunalty we cannot tell the difference between an '05 * and a '10 
 * as the vendor ID is the same.
 * These signals are only available on the '05 and the '10 so will be
 * marked as unsupported for all other devices.
 */
static WM_AUDIO_SIGNAL inputMuteSequence[] =
{
	WM_AUDIO_LINEIN,
	WM_AUDIO_MONOIN,
	WM_AUDIO_MIC1,
	WM_AUDIO_MIC2,
	WM_AUDIO_MIC2A,
	WM_AUDIO_MIC2B,
	WM_AUDIO_MIC2BTOA,
	WM_AUDIO_CD,
#if !WM_TOUCH
	WM_AUDIO_VIDEO,
	WM_AUDIO_AUXIN,
#endif /* !WM_TOUCH */
	WM_AUDIO_PCBEEP,
};

static WM_AUDIO_SIGNAL inputUnmuteSequence[] =
{
	WM_AUDIO_LINEIN,
	WM_AUDIO_MONOIN,
	WM_AUDIO_MIC1,
	WM_AUDIO_MIC2,
	WM_AUDIO_MIC2A,
	WM_AUDIO_MIC2B,
	WM_AUDIO_MIC2BTOA,
	WM_AUDIO_CD,
#if !WM_TOUCH
	WM_AUDIO_VIDEO,
	WM_AUDIO_AUXIN,
#endif /* !WM_TOUCH */
	WM_AUDIO_PCBEEP
};

/*
 * Only build this if we are asked to.
 */
#if WM_AUDIO

/*
 * Function prototypes
 */
static WMSTATUS private_muteSignals( WM_DEVICE_HANDLE hDevice, 
                                     WM_BOOL          isOutput,
                                     WM_BOOL          mute
                                   );

static WMSTATUS private_enableMixersToOutputs( WM_DEVICE_HANDLE hDevice, 
                                               WM_BOOL          enable
                                             );

static WMSTATUS private_EnableHiFiOutputPaths( WM_DEVICE_HANDLE hDevice,
                                               WM_BOOL enable
                                             );

static WMSTATUS private_EnableVoiceOutputPaths( WM_DEVICE_HANDLE hDevice,
                                                WM_BOOL enable
                                              );

static WMSTATUS private_EnableMonoOutputPaths( WM_DEVICE_HANDLE hDevice,
                                               WM_BOOL enable
                                             );

static WMSTATUS private_EnableHiFiInputPaths( WM_DEVICE_HANDLE hDevice,
                                              WM_BOOL enable
                                            );

static WMSTATUS private_EnableVoiceInputPaths( WM_DEVICE_HANDLE hDevice,
                                               WM_BOOL enable
                                             );

/*-----------------------------------------------------------------------------
 * Function:    WMAudioConfigurePath
 *
 * Configure and enable the paths from the DAC to the outputs (for an output
 * stream) or from the inputs to the ADC (for an input stream).
 * 
 * NOTE: This function works by loading specific profiles.  You can see what
 * these profiles do by looking in the file corresponding to your codec in
 * the ChipDefs subdirectory, and you can override the behaviour by adding
 * your own profiles with the same name in Common\UserProfiles.c .
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      stream      The stream to configure
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioConfigurePath( WM_DEVICE_HANDLE hDevice,
                               WM_STREAM_ID     stream
                             )
{
    WMSTATUS status;
    
    switch ( stream )
    {
        case WM_STREAM_HIFI_OUT:
            status = WMLoadNamedProfile( hDevice, "HiFi playback" );
            break;

#if WM_VOICE
        case WM_STREAM_VOICE_OUT:
            status = WMLoadNamedProfile( hDevice, "Voice playback" );
            break;
#endif

#if WM_MONODAC
        case WM_STREAM_MONO_OUT:
            status = WMLoadNamedProfile( hDevice, "Mono playback" );
            break;
#endif

        case WM_STREAM_HIFI_IN:
        case WM_STREAM_VOICE_IN:

            status = WMAudioSetRecPaths( hDevice, 
                                         WM_AUDIO_DEFAULT_RECORD_LEFT_PATH,
                                         WM_AUDIO_DEFAULT_RECORD_RIGHT_PATH
                                       );
            break;

        default:
            status = WMS_UNSUPPORTED;
    }

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioUnconfigurePath
 *
 * Unconfigure and disable the paths from the DAC to the outputs (for an output
 * stream) or from the inputs to the ADC (for an input stream).
 * 
 * NOTE: This function works by loading specific profiles.  You can see what
 * these profiles do by looking in the file corresponding to your codec in
 * the ChipDefs subdirectory, and you can override the behaviour by adding
 * your own profiles with the same name in Common\UserProfiles.c .
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      stream      The stream to configure
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioUnconfigurePath( WM_DEVICE_HANDLE hDevice,
                                 WM_STREAM_ID     stream
                               )
{
    WMSTATUS status;
    
    /*
     * Now do stream-specific setup.
     */
    switch ( stream )
    {
        case WM_STREAM_HIFI_OUT:
            status = WMLoadNamedProfile( hDevice, "Stop HiFi playback" );
            break;

#if WM_VOICE
        case WM_STREAM_VOICE_OUT:
            status = WMLoadNamedProfile( hDevice, "Stop Voice playback" );
            break;
#endif

#if WM_MONODAC
        case WM_STREAM_MONO_OUT:
            status = WMLoadNamedProfile( hDevice, "Stop Mono playback" );
            break;
#endif

        case WM_STREAM_HIFI_IN:
        case WM_STREAM_VOICE_IN:

            status = WMAudioClearRecPaths( hDevice, 
                                           WM_AUDIO_DEFAULT_RECORD_LEFT_PATH,
                                           WM_AUDIO_DEFAULT_RECORD_RIGHT_PATH
                                         );
            break;

        default:
            status = WMS_UNSUPPORTED;
    }

    return status;
}
/*-----------------------------------------------------------------------------
 * Function:    WMAudioMuteAllOutputs
 *
 * This function will mute or unmute the outputs depending on the value of
 * the parameter mute.
 * 
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      mute        TRUE to mute the outputs. FALSE to unmute the outputs.
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioMuteAllOutputs( WM_DEVICE_HANDLE hDevice, WM_BOOL mute )
{
    WMSTATUS status = WMS_SUCCESS;

    /*
     * Run through all the outputs muting/unmuting them in a defined
     * sequence.
     */
    status = private_muteSignals( hDevice, TRUE, mute );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        /* If this is not a supported signal on the device then
         * the library will not try to mute or unmute. 
         * If it is any other error then report it.
         */
        WM_TRACE( hDevice,
                  ( "WMAudioMuteAllOutputs failed: %s",
                    WMStatusText( status ) ) );
    }

    if ( WMS_UNSUPPORTED == status )
        status = WMS_SUCCESS;

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioMuteAllInputs
 *
 * This function will mute or unmute the inputs depending on the value of
 * the parameter mute.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      mute        TRUE to mute the inputs. FALSE to unmute the inputs.
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioMuteAllInputs( WM_DEVICE_HANDLE hDevice, WM_BOOL mute )
{
    WMSTATUS status = WMS_SUCCESS;

    /*
     * Run through all the inputs muting/unmuting them in a defined
     * sequence.
     */
    status = private_muteSignals( hDevice, FALSE, mute );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        /* If this is not a supported signal on the device then
         * the library will not try to mute or unmute. 
         * If it is any other error then report it.
         */
        WM_TRACE( hDevice,
                  ( "WMAudioMuteAllInputs failed: %s",
                    WMStatusText( status ) ) );
    }

    if ( WMS_UNSUPPORTED == status )
        status = WMS_SUCCESS;

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    private_muteSignals
 *
 * This function will mute or unmute a sequence of signals depending on the
 * value of the parameter mute.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      isOutput            TRUE for Outputs. FALSE for Inputs.
 *      mute                TRUE to mute the signals. FALSE to unmute the signals.
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
static WMSTATUS private_muteSignals( WM_DEVICE_HANDLE hDevice,
                                     WM_BOOL          isOutput,
                                     WM_BOOL          mute
                                   )
{
    WMSTATUS        status = WMS_SUCCESS;
    unsigned int    i;
    unsigned int    maxSignals = 0;
    WM_AUDIO_SIGNAL *pSignalSequence;

    if ( isOutput )
    {
        if ( mute )
        {
            pSignalSequence = outputMuteSequence;
            maxSignals = WM_ARRAY_COUNT( outputMuteSequence );
        }
        else
        {
           pSignalSequence = outputUnmuteSequence;
           maxSignals = WM_ARRAY_COUNT( outputUnmuteSequence );
        }
    }
    else
    {
        if ( mute )
        {
            pSignalSequence = inputMuteSequence;
            maxSignals = WM_ARRAY_COUNT( inputMuteSequence );
        }
        else
        {
            pSignalSequence = inputUnmuteSequence;
            maxSignals = WM_ARRAY_COUNT( inputMuteSequence );
        }
    }

    
    for ( i=0; i < maxSignals; i++ )
    {
        status = WMAudioMuteSignal( hDevice, *pSignalSequence++, mute );
        if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
        {
            /* If this is not a supported signal on the device then
             * the library will not try to mute or unmute it. 
             */
            goto exit;
        }
    }

exit:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetRecPaths
 *
 * Set up left and/or right channel record paths.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      signalL     signal to record on the left channel.
 *      signalR     signal to record on the right channel.
 *
 * Returns:     WMSTATUS
 * 				WMS_UNSUPPORTED there is no guarantee that any record paths
 * 								been set as one of the parameters was unsupported.
 *      		For all other return values see WMStatus.h 
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetRecPaths( WM_DEVICE_HANDLE   hDevice,
                             WM_AUDIO_SIGNAL    signalL,
                             WM_AUDIO_SIGNAL    signalR
                           )
{
	WM_AUDIO_SIGNAL secondary_signal = WM_AUDIO_IGNORE;
	WMSTATUS status = WMS_INVALID_SIGNAL;

    if ( !WM_SIGNAL_IS_VALID(signalL) || !WM_SIGNAL_IS_VALID(signalR) )
	{
        WM_TRACE( hDevice,
                  ( "WMAudioSetRecPaths failed: not a valid signal (L=0x%X, R=0x%X)",
                    signalL,
                    signalR
                  )
                );
		goto exit;
	}

	/* 
	 * Any input sources where the types of left and right signals
	 * are the same, should be handled here. e.g. 2 mic inputs. 
	 * If not then we will have to set up the right signal later. 
	 */
	switch (signalL)
	{
	case WM_AUDIO_LINEIN:
		status = WMAudioSetLineInRecPaths( hDevice, 
										   signalL,
										   ( WM_SIGNAL_IS_LINEIN(signalR) ) ? signalR : WM_AUDIO_IGNORE
										 );

		/* we have processed both signals so quit */
		if ( WM_SIGNAL_IS_LINEIN(signalR) )
		{
			goto exit;
		}
		break;
	
	case WM_AUDIO_MIC:
	case WM_AUDIO_MIC2:
	case WM_AUDIO_MIC2A:
	case WM_AUDIO_MIC2B:
	case WM_AUDIO_MIC2BTOA:
		status = WMAudioSetMicRecPaths( hDevice, 
										signalL, 
										( WM_SIGNAL_IS_MIC(signalR) ) ? signalR : WM_AUDIO_IGNORE
									  );

		/* we have processed both signals so quit */
 		if (WM_SIGNAL_IS_MIC( signalR) )
		{
			goto exit;
		}
		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -