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

📄 wmaudiosignals.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
 /*-----------------------------------------------------------------------------
 * 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: WMAudioSignals.c 4254 2006-10-26 11:04:01Z fb $
 *
 * This file contains platform-independent routines for controlling the audio
 * signals on Wolfson codecs.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 * -----------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMControlLink.h"
#include "WMPlatformI2S.h"
#include "WM8753Audio.h"
#include "WMAudio.h"
#include "WMDMA.h"
#include "WMVoice.h"
#include "WMPower.h"

/*
 * Only build this if we're doing Audio support.
 */
#if WM_AUDIO

/*
 * Global definitions
 */
typedef struct tagVolumeLookup
{
#if DEBUG
    unsigned short  pattern;
#endif
    int             level;
} VolumeLookup;

/*
 * Private data
 */
 
/*
 * Lookup table for the significant bits in the perceived volume -> dbVal
 * calculation.
 */
#define VOL_SIGNIFICANT_BITS    6
#define VOL_SIGNIFICANT_MASK    0xFC00
#define VOL_INSIGNIFICANT_MASK  0x03FF

#if DEBUG
#	define VOL_ENTRY( _pattern, _level )	{ _pattern, _level }
#else
#	define VOL_ENTRY( _pattern, _level )	{ _level }
#endif

static VolumeLookup s_VolumeTable[] = 
{
    VOL_ENTRY( 0x8000,   160 ),   /* 100000 */
	VOL_ENTRY( 0x8400,   153 ),   /* 100001 */
    VOL_ENTRY( 0x8800,   146 ),   /* 100010 */
    VOL_ENTRY( 0x8C00,   139 ),   /* 100011 */
    VOL_ENTRY( 0x9000,   133 ),   /* 100100 */
    VOL_ENTRY( 0x9400,   126 ),   /* 100101 */
    VOL_ENTRY( 0x9800,   120 ),   /* 100110 */
    VOL_ENTRY( 0x9C00,   114 ),   /* 100111 */
    VOL_ENTRY( 0xA000,   108 ),   /* 101000 */
    VOL_ENTRY( 0xA400,   103 ),   /* 101001 */
    VOL_ENTRY( 0xA800,    97 ),   /* 101010 */
    VOL_ENTRY( 0xAC00,    92 ),   /* 101011 */
    VOL_ENTRY( 0xB000,    86 ),   /* 101100 */
    VOL_ENTRY( 0xB400,    81 ),   /* 101101 */
    VOL_ENTRY( 0xB800,    76 ),   /* 101110 */
    VOL_ENTRY( 0xBC00,    71 ),   /* 101111 */
    VOL_ENTRY( 0xC000,    66 ),   /* 110000 */
    VOL_ENTRY( 0xC400,    62 ),   /* 110001 */
    VOL_ENTRY( 0xC800,    57 ),   /* 110010 */
    VOL_ENTRY( 0xCC00,    52 ),   /* 110011 */
    VOL_ENTRY( 0xD000,    48 ),   /* 110100 */
    VOL_ENTRY( 0xD400,    44 ),   /* 110101 */
    VOL_ENTRY( 0xD800,    39 ),   /* 110110 */
    VOL_ENTRY( 0xDC00,    35 ),   /* 110111 */
    VOL_ENTRY( 0xE000,    31 ),   /* 110100 */
    VOL_ENTRY( 0xE400,    27 ),   /* 111001 */
    VOL_ENTRY( 0xE800,    23 ),   /* 111010 */
    VOL_ENTRY( 0xEC00,    19 ),   /* 111011 */
    VOL_ENTRY( 0xF000,    15 ),   /* 111100 */
    VOL_ENTRY( 0xF400,    11 ),   /* 111101 */
    VOL_ENTRY( 0xF800,     7 ),   /* 111110 */
    VOL_ENTRY( 0xFC00,     4 ),   /* 111111 */
    VOL_ENTRY( 0x0000,     0 ),   /* 000000 */
};

/*
 * Function prototypes
 */
static WMSTATUS private_GetSignalVolumeUnits( WM_DEVICE_HANDLE  hDevice,
                                              WM_AUDIO_SIGNAL   signal,
                                              int               *pVol,
                                              WM_AUDIO_CHANNELS channels,
                                              int               baseUnit
                                            );
static WMSTATUS private_Set2ChannelVolumeBase( WM_DEVICE_HANDLE  hDevice,
                                               WM_AUDIO_SIGNAL   left,
                                               WM_AUDIO_SIGNAL   right,
                                               int               leftVal,
                                               int               rightVal
                                             );
static const WM_RECSOURCE_SIGNALS *private_LookupRecordSource( WM_DEVICE_HANDLE hDevice,
                                                               WM_AUDIO_SIGNAL  signal
                                                             );
static const WM_SIGNAL_DETAILS *private_SignalDetails( WM_DEVICE_HANDLE hDevice,
                                                       WM_AUDIO_SIGNAL  signal
                                                     );
static const WM_MIC_CONTROL_DETAILS *private_MicControlDetails( WM_DEVICE_HANDLE hDevice,
                                                                WM_AUDIO_SIGNAL  signal
                                                              );
static WMSTATUS private_SetSignalVolumeAdv( WM_DEVICE_HANDLE     hDevice,
                                            WM_AUDIO_SIGNAL      signal,
                                            int                  baseVol,
                                            WM_AUDIO_CHANNELS    channels
                                          );
#if WM_OUTPUT_GAIN_RAMP
static WMSTATUS private_GetdBRange( WM_DEVICE_HANDLE hDevice,
                                    WM_AUDIO_SIGNAL signal,
                                    int                 *pdbMin,
                                    int                 *pdbMax,
                                    int                 *pdbStep
                                  );
static WMSTATUS private_SaveGlobalOutputGain( WM_DEVICE_HANDLE      hDevice,
                                              WM_AUDIO_SIGNAL       signal,
                                              int                   dBGain,
                                              WM_AUDIO_CHANNELS     channels
                                            );
static WMSTATUS private_RetrieveGlobalOutputGain( WM_DEVICE_HANDLE  hDevice,
                                                  WM_AUDIO_SIGNAL   signal,
                                                  int               *pdBGain,
                                                  WM_AUDIO_CHANNELS channels
                                               );
static WMSTATUS private_GetCurrentOutputGain( WM_DEVICE_HANDLE      hDevice,
                                               WM_AUDIO_SIGNAL       signal
                                             );
static WM_BOOL private_IsOutputGainInitialised( WM_DEVICE_HANDLE  hDevice,
                                                WM_AUDIO_SIGNAL   signal
                                              );
static WM_BOOL private_OutputGainInitialise( WM_DEVICE_HANDLE  hDevice,
                                             WM_AUDIO_SIGNAL   signal
                                           );
static WM_BOOL private_OutputGainInitialisation( WM_DEVICE_HANDLE  hDevice,
                                                 WM_AUDIO_SIGNAL   signal,
                                                 WM_BOOL           init
                                              );
static WMSTATUS private_StepSignalVolume( WM_DEVICE_HANDLE    hDevice,
                                            WM_AUDIO_SIGNAL     signal,
                                            WM_BOOL             rampUp
                                          );
static WMSTATUS private_SetSignalVolumeMin( WM_DEVICE_HANDLE   hDevice,
                                              WM_AUDIO_SIGNAL    signal
                                            );
#endif /* WM_OUTPUT_GAIN_RAMP */

#if DEBUG
void private_DumpSignal( WM_DEVICE_HANDLE        hDevice,
                         const WM_SIGNAL_DETAILS *pSignal
                       );
#define DUMP_SIGNAL( hDevice, pSignal ) private_DumpSignal( hDevice, pSignal )
#else
#define DUMP_SIGNAL( hDevice, pSignal ) 0
#endif

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsSignalSupported
 *
 * Check to see if the signal is supported on this device.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).
 *      signal          The signal to check.
 *
 * Returns:     WM_BOOL
 *      TRUE     - signal is supported
 *      FALSE    - signal is not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsSignalSupported( WM_DEVICE_HANDLE  hDevice,
                                  WM_AUDIO_SIGNAL   signal
                                )
{
    const WM_SIGNAL_DETAILS *pSignalDetails = NULL;

    /* Get the signal details */
    pSignalDetails = private_SignalDetails( hDevice, signal );
    
    if ( pSignalDetails )
        return TRUE;
    else
        return FALSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSignalHasVolume
 *
 * Check to see if the signal is supported and has volume control on this device.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).
 *      signal          The signal to check.
 *
 * Returns:     WM_BOOL
 *      TRUE     - signal volume control is supported
 *      FALSE    - signal volume control is not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioSignalHasVolume( WM_DEVICE_HANDLE  hDevice,
                                WM_AUDIO_SIGNAL   signal
                              )
{
    const WM_SIGNAL_DETAILS *pSignalDetails = NULL;

    /* Get the signal details */
    pSignalDetails = private_SignalDetails( hDevice, signal );
    
    if ( pSignalDetails && WM_REG_INVALID != pSignalDetails->reg )
        return TRUE;

    return FALSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSignalHasMute
 *
 * Check to see if the signal is supported and has a mute on this device.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).
 *      signal          The signal to check.
 *
 * Returns:     WM_BOOL
 *      TRUE     - signal mute is supported
 *      FALSE    - signal mute is not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioSignalHasMute( WM_DEVICE_HANDLE  hDevice,
                              WM_AUDIO_SIGNAL   signal
                            )
{
    const WM_SIGNAL_DETAILS *pSignalDetails = NULL;

    /* Get the signal details */
    pSignalDetails = private_SignalDetails( hDevice, signal );
    
    if ( pSignalDetails && WM_REG_INVALID != pSignalDetails->muteReg )
        return TRUE;

    return FALSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSignalHasNoSeparateMute
 *
 * Check to see if the signal is supported and is muted with a special volume
 * on this device (as opposed to using a bitfield).
 * 
 * If this is the case, the only way to unmute is to set the volume to a new
 * value, since there is no previous volume information held in the register.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).
 *      signal          The signal to check.
 *
 * Returns:     WM_BOOL
 *      TRUE     - signal mute is via a special volume value
 *      FALSE    - signal is not supported or mute uses a separate bitfield
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioSignalHasNoSeparateMute( WM_DEVICE_HANDLE  hDevice,
                                        WM_AUDIO_SIGNAL   signal
                                      )
{
    const WM_SIGNAL_DETAILS *pSignalDetails = NULL;

    /* Get the signal details */
    pSignalDetails = private_SignalDetails( hDevice, signal );
    
    if ( pSignalDetails && (pSignalDetails->flags & WM_SIG_VOLUME_MUTE) )
        return TRUE;

    return FALSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsSignalStereo
 *
 * Check to see if the signal is supported and is a stereo signal.
 * Note this does not tell you that the signal is mono - it might not be
 * supported.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).
 *      signal          The signal to check.
 *
 * Returns:     WM_BOOL
 *      TRUE             - signal is stereo
 *      FALSE            - signal is mono or not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsSignalStereo( WM_DEVICE_HANDLE  hDevice,
                               WM_AUDIO_SIGNAL   signal
                             )
{
    WMSTATUS            status;
    WM_AUDIO_CHANNELS   channels;
    
    status = WMAudioGetSignalChannels( hDevice, signal, &channels );
    if ( WM_SUCCESS( status ) )
    {
        if ( WM_CHANNEL_STEREO == (channels & WM_CHANNEL_STEREO) )
            return TRUE;
    }
    
    return FALSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsSignalPanned
 *
 * Check to see if the given signal's left and right channels are set to the
 * same gain.
 *
 * Parameters:
 *      hDevice         The handle to the device (from WMOpenDevice).

⌨️ 快捷键说明

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