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

📄 wm8753audiopaths.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
 * 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: WM8753AudioPaths.c 1738 2005-05-26 15:04:51Z ib $
 *
 * 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 "WM8753Audio.h"
#include "WM8753AudioPaths.h"

/*
 * Global definitions
 */

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

/*
 * Function prototypes
 */
WMSTATUS private_ConfigureHiFiPath( WM_DEVICE_HANDLE hDevice );
WMSTATUS private_ConfigureVoicePath( WM_DEVICE_HANDLE hDevice );

/*-----------------------------------------------------------------------------
 * Function:    WM8753ConfigurePath
 *
 * Configure and enable the paths from the DAC to the outputs.
 * NOTE: This function is enabling as many of the outputs as possible
 *       so that there is a good chance that anything coming from the
 *       DAC will end up being heard through any of the outputs.
 *       You will probably want to change this set up to suit your
 *       particular application.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      stream      The stream to configure
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM8753ConfigurePath( WM_DEVICE_HANDLE hDevice,
                              WM_STREAM_ID     stream
                            )
{
    WMSTATUS status;
    
    /*
     * Only try and do this if this is a WM8753.
     */
    if ( !IS_WM8753_FAMILY( hDevice ) )
    {
        status = WMS_UNSUPPORTED;
        goto end;
    }

    /* Make sure the stream is enabled */
    status = WMAudioEnableStream( hDevice, stream );
    if ( WM_ERROR( status ) )
    {
        goto end;
    }

    /*
     * Now do stream-specific setup.
     */
    switch ( stream )
    {
        case WM_STREAM_HIFI_OUT:
            status = private_ConfigureHiFiPath( hDevice );
            break;

#if WM_VOICE
        case WM_STREAM_VOICE_OUT:
            status = private_ConfigureVoicePath( hDevice );
            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;
    }

end:    
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    private_ConfigureHiFiPath
 *
 * Configure and enable the paths from the DAC to the outputs.
 * NOTE: This function is enabling as many of the outputs as possible
 *       so that there is a good chance that anything coming from the
 *       DAC will end up being heard through any of the outputs.
 *       You will probably want to change this set up to suit your
 *       particular application.
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS private_ConfigureHiFiPath( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS status;

    /* 0x08 Left Channel Digital Volume - 0dB */
    status = WMWrite( hDevice, 
                      WM8753_LEFT_DAC_VOLUME, 
                      WM8753_DACVOL(0)
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x09 Right Channel Digital Volume - 0dB and Update */
    status = WMWrite( hDevice, 
                      WM8753_RIGHT_DAC_VOLUME, 
                      ( WM8753_VOLUME_UPDATE        | 
                        WM8753_DACVOL(0) 
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x01 DAC Control - Umute DAC */
    status = WMClearField( hDevice, 
                           WM8753_DAC_CONTROL, 
                           WM8753_DAC_SOFT_MUTE 
                         );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x22 Left Mixer Control 1 - LDAC to left output, default gain (-9dB) */
    status = WMSetField( hDevice,
                         WM8753_LEFT_OUT_MIX_1,
                         ( WM8753_DAC2OUT           |
                           WM8753_MIXVOL_M9DB
                         ),
                         ( WM8753_DAC2OUT           |
                           WM8753_MIXVOL_MASK
                         )
                       );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x24 Right Mixer Control 1 - RDAC to right output, default gain (-9dB) */
    status = WMSetField( hDevice,
                         WM8753_RIGHT_OUT_MIX_1,
                         ( WM8753_DAC2OUT           |
                           WM8753_MIXVOL_M9DB
                         ),
                         (  WM8753_DAC2OUT          |
                            WM8753_MIXVOL_MASK
                         )
                       );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x26 Mono Mixer Control 1 - LDAC to mono output, default gain (-9dB) */
    status = WMSetField( hDevice,
                         WM8753_MONO_OUT_MIX_1,
                         ( WM8753_DAC2OUT           |
                           WM8753_MIXVOL_M9DB
                         ),
                         (  WM8753_DAC2OUT          |
                            WM8753_MIXVOL_MASK
                         )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x27 Mono Mixer Control 2 - RDAC to mono output, default gain (-9dB) */
    status = WMSetField( hDevice,
                         WM8753_MONO_OUT_MIX_2,
                         ( WM8753_DAC2OUT           |
                           WM8753_MIXVOL_M9DB
                         ),
                         (  WM8753_DAC2OUT          |
                            WM8753_MIXVOL_MASK
                         )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }
    
    /* 0x28h LOUT1 Volume - 0dB and zero cross enabled */
    WMWrite( hDevice,
             WM8753_LOUT1_VOLUME,
             ( WM8753_OUTVOL_ZEROCROSS              |
               WM8753_OUTVOL(0)
             )
           );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x29 ROUT1 - 0dB, zero cross enabled and update */
    status = WMWrite( hDevice,
                      WM8753_ROUT1_VOLUME,
                      ( WM8753_VOLUME_UPDATE        |
                        WM8753_OUTVOL_ZEROCROSS     |
                        WM8753_OUTVOL(0)
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x2A LOUT2 Volume - 0dB and zero cross enabled */
    status = WMWrite( hDevice,
                      WM8753_LOUT2_VOLUME,
                      ( WM8753_OUTVOL_ZEROCROSS     |
                        WM8753_OUTVOL(0)
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x2B ROUT2 Volume - 0dB, zero cross enabled and update */
    status = WMWrite( hDevice,
                      WM8753_ROUT2_VOLUME,
                      ( WM8753_VOLUME_UPDATE        |
                        WM8753_OUTVOL_ZEROCROSS     |
                        WM8753_OUTVOL(0)
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

   /* 0x2C MONOOUT Volume - 0dB and zero cross enabled */
    status = WMWrite( hDevice, 
                      WM8753_MONOOUT_VOLUME, 
                      ( WM8753_OUTVOL_ZEROCROSS  |
                           WM8753_OUTVOL(0)
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    return WMS_SUCCESS;

error:
    return status;
}

#if WM_VOICE
/*-----------------------------------------------------------------------------
 * Function:    private_ConfigureVoicePath
 *
 * Configure and enable the paths from the Voice DAC to the outputs.
 * NOTE: This function is enabling as many of the outputs as possible
 *       so that there is a good chance that anything coming from the
 *       Voice DAC will end up being heard through any of the outputs.
 *       You will probably want to change this set up to suit your
 *       particular application.
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS private_ConfigureVoicePath( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS status;

    /* 0x23 Left Mixer Control (2) - Voice DAC to Left Output + 0dB Vol*/
    status = WMSetField( hDevice, 
                         WM8753_LEFT_OUT_MIX_2, 
                         ( WM8753_DAC2OUT |
                           WM8753_VX_MIXVOL_0DB
                         ),
                         ( WM8753_DAC2OUT |
                           WM8753_VX_MIXVOL_MASK
                         )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x25 Right Mixer Control (2) - Voice DAC to Left Output + 0dB Vol*/
    status = WMSetField( hDevice, 
                         WM8753_RIGHT_OUT_MIX_2, 
                         ( WM8753_DAC2OUT |
                          WM8753_VX_MIXVOL_0DB
                         ),
                         ( WM8753_DAC2OUT |
                          WM8753_VX_MIXVOL_MASK
                         )
                        );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x27 Mono Mixer Control (2) - Voice DAC to Mono Mixer + 0dB Vol*/
    status = WMSetField( hDevice, 
                         WM8753_MONO_OUT_MIX_2, 
                         ( WM8753_DAC2OUT |
                           WM8753_VX_MIXVOL_0DB
                         ),
                         ( WM8753_DAC2OUT |
                           WM8753_VX_MIXVOL_MASK
                         )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x28 LOUT1 Volume Set update bit and Volume level to 0dB */
    status = WMWrite( hDevice, 
                      WM8753_LOUT1_VOLUME, 
                      ( WM8753_OUTVOL_ZEROCROSS | 
                        WM8753_OUTVOL_0DB
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x29 ROUT1 Volume Set update bit and Volume level to 0dB */
    status = WMWrite( hDevice, 
                      WM8753_ROUT1_VOLUME, 
                      ( WM8753_VOLUME_UPDATE    |
                        WM8753_OUTVOL_ZEROCROSS |
                        WM8753_OUTVOL_0DB
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x2A LOUT2 Volume Set update bit and Volume level to 0dB */
    status = WMWrite( hDevice, 
                      WM8753_LOUT2_VOLUME, 
                      ( WM8753_OUTVOL_ZEROCROSS |
                        WM8753_OUTVOL_0DB
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    /* 0x2B ROUT2 Volume Set update bit and Volume level to 0dB */
    status = WMWrite( hDevice, 
                      WM8753_ROUT2_VOLUME, 
                      ( WM8753_VOLUME_UPDATE    |
                        WM8753_OUTVOL_ZEROCROSS |
                        WM8753_OUTVOL_0DB
                      )
                    );
    if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
    {
        goto error;
    }

    return WMS_SUCCESS;

error:
    return status;
}
#endif /* WM_VOICE */

/*-----------------------------------------------------------------------------
 * Function:    WM8753SetLineInRecPaths
 *
 * Set up Line In as the record path.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      lineInL     signal to record on left ADC channel.
 *      lineInR     signal to record on right ADC channel.
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM8753SetLineInRecPaths( WM_DEVICE_HANDLE  hDevice, 
								  WM_AUDIO_SIGNAL   lineInL,
								  WM_AUDIO_SIGNAL   lineInR
                                )
{
    WMSTATUS status;

	/*
	 * Set Left ADC Volume.
	 */
    status = WMWrite( hDevice, 
                      WM8753_LEFT_ADC_VOLUME, 
                      WM8753_ADCVOL_0DB
                    );
    if( WM_ERROR( status ) )
    {
        goto error;
    }


	/*
	 * Set Right ADC Volume.
	 */
    status = WMWrite( hDevice, 
                      WM8753_RIGHT_ADC_VOLUME, 
                      WM8753_VOLUME_UPDATE      |
                      WM8753_ADCVOL_0DB
                    );
    if( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * Set the ADC input mode to LINE1 & LINE2.
     */
    status = WMSetField( hDevice, 
                         WM8753_ADC_INPUT_MODE, 
                         WM8753_RIGHTADCSEL_LINE2   |

⌨️ 快捷键说明

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