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

📄 wmaudiosignals.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
                
                /* Now work out the dB value (in 1/16dB steps) */
                regVol -= pSignalDetails->zerodB;
                step = pSignalDetails->step;
                baseVol = regVol * step;
                
                /*
                 * Now convert into the appropriate units.
                 */
                if ( baseUnit > 1 )
                {
                    /*
                     * Work out what is the largest value less than half a unit
                     * (i.e. the largest value we can add to an exact multiple
                     * of the unit so we can guarantee it will not change on
                     * rounding.
                     */
                    int halfUnit = baseUnit/2;
                    halfUnit = halfUnit - 1;
        
                    /*
                     * Add it to the baseVol so it will round the right way.
                     */
                    if ( baseVol > 0 )
                        baseVol += halfUnit;
                    else
                        baseVol -= halfUnit;
        
                    baseVol = baseVol / baseUnit;
                }

                /* And we're done */
                break;
            }
        }
    } 

    /* Did we find it? */
    if ( WM_REG_INVALID == reg )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * Return the value.
     */
    *pVol = baseVol;
    return WMS_SUCCESS;

error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetOutputAttenuations
 *
 * Called to set the left and right channel attenuations applied to a 
 * given analogue output. For example, a 0dBFS input with 6dB attenuation 
 * would result in a -6dBFS signal from the output.
 * 
 * Note: the underlying device may not use dB step sizes.  In this case the
 *       applied attenuation will be rounded to the nearest available step.
 *       For example, if the device has a 1.5dB step size 
 *       (typical of AC'97 devices), an attenuation of either 4dB or 5dB would 
 *       result in a -4.5dBFS signal.
 *
 * Parameters:
 *      hDevice               handle to the device (from WMOpenDevice)
 *      outputL               left output to attenuate
 *      outputR               right output to attenuate
 *      attenuationdBLeft     left channel attenuation to apply in dB steps.
 *      attenuationdBRight    right channel attenuation to apply in dB steps.
 *
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetOutputAttenuations( WM_DEVICE_HANDLE  hDevice,
                                       WM_AUDIO_SIGNAL   outputL, 
                                       WM_AUDIO_SIGNAL   outputR, 
                                       int               attenuationdBLeft,
                                       int               attenuationdBRight
                                     )
{
    WMSTATUS                status;

    /*
     * Call through to our helper function.
     */
    status = private_Set2ChannelVolumeBase( hDevice,
                                            outputL,
                                            outputR,
                                            WM_SIGNAL_LEVEL( -attenuationdBLeft ),
                                            WM_SIGNAL_LEVEL( -attenuationdBRight )
                                          );

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetInputGains
 *
 * Called to set the gain applied to a given input.  
 * For example, a 0dBFS input with 6dB gain would result in the input signal
 * being increased by +6dBFS.
 * 
 * Note: the underlying device may not use dB step sizes.  In this case the
 *       applied gain will be rounded to the nearest available step.  For
 *       example, if the device has a 1.5dB step size (typical of AC'97 devices),
 *       an gain of either 4dB or 5dB would result in a +4.5dBFS signal.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      inputL          left input to gain
 *      inputR          right input to gain
 *      gain_dBL        left channel gain to apply in dB steps.
 *      gain_dBR        right channel gain to apply in dB steps.
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetInputGains( WM_DEVICE_HANDLE     hDevice,
							   WM_AUDIO_SIGNAL      inputL, 
							   WM_AUDIO_SIGNAL      inputR, 
							   int                  gain_dBL,
							   int                  gain_dBR
							 )
{
    WMSTATUS                status;

    /*
     * Call through to our helper function.
     */
    status = private_Set2ChannelVolumeBase( hDevice,
                                            inputL,
                                            inputR,
                                            WM_SIGNAL_LEVEL( gain_dBL ),
                                            WM_SIGNAL_LEVEL( gain_dBR )
                                          );

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetOutputVolumes
 *
 * Called to set the perceived volume for the left and right channels 
 * of a given analogue output.
 *
 * Note: Linearly reducing the perceived volume does _not_ result in a linear
 *       attenuation of the output signal.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      output          output to attenuate
 *      volPercentL     left channel perceived output volume, 
 *                      as a percentage of full-scale
 *      volPercentR     Right channel perceived output volume, 
 *                      as a percentage of full-scale
 *      channels		indicates channel(s) to set attenuation on.
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetOutputVolumes( WM_DEVICE_HANDLE  hDevice,
                                  WM_AUDIO_SIGNAL   output, 
                                  unsigned int      volPercentL,
                                  unsigned int      volPercentR,
								  WM_AUDIO_CHANNELS channels
                               )
{
    WMSTATUS        status;
    unsigned int    leftVol, rightVol;

    leftVol = 65535 * volPercentL / 100;
    rightVol = 65535 * volPercentR / 100;
    
    status = WMAudioSetSignalVolumes( hDevice, output, leftVol, rightVol );

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetOutputAttenuationsAC97
 *
 * Called to set the left and right channel attenuations applied to a given 
 * analogue output, using the AC97 attenuation values to write to the register
 *  - 1.5dB steps.
 * Note:
 * At the moment we only support setting the attenuation on 2 outputs if they 
 * have the same control register
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      outputL         left output to attenuate
 *      outputR         right output to attenuate
 *      rawValL         left channel attenuation to apply in 1.5dB steps.
 *      rawValR         right channel attenuation to apply in 1.5dB steps.
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetOutputAttenuationsAC97( WM_DEVICE_HANDLE  hDevice,
                                           WM_AUDIO_SIGNAL   outputL, 
                                           WM_AUDIO_SIGNAL   outputR, 
                                           int               rawValL,
                                           int               rawValR
                                         )
{
    WMSTATUS                status;

    /*
     * Call through to our helper function.
     */
    status = private_Set2ChannelVolumeBase( hDevice,
                                            outputL,
                                            outputR,
                                            WM_SIGNAL_LEVEL_AC97( -rawValL ),
                                            WM_SIGNAL_LEVEL_AC97( -rawValR )
                                          );

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioGetOutputAttenuationsAC97
 *
 * Called to get the left and right channel attenuations set at a given 
 * analogue output, outputiing the AC97 attenuation values obtained from the 
 * registers - 1.5dB steps.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      output          output to attenuate
 *      rawValL         left channel attenuation to get.
 *      rawValR         right channel attenuation to get.
 *      channels		indicates channel(s) attenuations to get.
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioGetOutputAttenuationsAC97( WM_DEVICE_HANDLE  hDevice,
                                           WM_AUDIO_SIGNAL   output, 
                                           int               *rawValL,
                                           int               *rawValR,
                                           WM_AUDIO_CHANNELS channels
                                         )
{
    WMSTATUS            		status;

    /*
     * Get left if asked for.
     */
    if ( rawValL && channels & WM_CHANNEL_LEFT )
    {
        status = private_GetSignalVolumeUnits( hDevice,
                                               output,
                                               rawValL,
                                               WM_CHANNEL_LEFT,
                                               WM_SIGNAL_LEVEL_AC97( -1 )
                                             );
        if ( WM_ERROR( status ) )
        {
            goto finish;
        }
    }

    /*
     * And right.
     */
    if ( rawValR && channels & WM_CHANNEL_RIGHT )
    {
        status = private_GetSignalVolumeUnits( hDevice,
                                               output,
                                               rawValR,
                                               WM_CHANNEL_RIGHT,
                                               WM_SIGNAL_LEVEL_AC97( -1 )
                                             );
        if ( WM_ERROR( status ) )
        {
            goto finish;
        }
    }

    /*
     * And return.
     */
finish:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioSetInputGainsAC97
 *
 * Called to set the gain applied to a given input, using the AC97
 * gain value to write to the register - All the inputs have a range of
 * +12dB to -34.5dB gain in 1.5dB steps except for PCBEEP.
 * PCBEEP on WM9705/07 has a range of 0dB to -45dB in 3dB steps.
 * PCBEEP on WM9712/13 has a range of 6dB to -15dB in 3dB steps.
 * 
 * NOTE: If we need to set gains for two entirely different inputs we will need 
 * to set (seperate) details for both the left and right imputs simultaneously.
 * This is not currently supported so WMAudioSetInputGainsAC97 must be called
 * separately to alter the left and right signals.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      inputL          left input to apply gain to.
 *      inputR          right input to apply gain to.
 *      rawValL         left channel gain to apply in 1.5dB steps.
 *      rawValR         right channel gain to apply in 1.5dB steps.
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetInputGainsAC97( WM_DEVICE_HANDLE  hDevice,
								   WM_AUDIO_SIGNAL   inputL, 
								   WM_AUDIO_SIGNAL   inputR, 
								   WM_REGVAL         rawValL,
								   WM_REGVAL         rawValR
								 )
{
    WMSTATUS                status;

    /*
     * Call through to our helper function.
     */
    status = private_Set2ChannelVolumeBase( hDevice,
                                            inputL,
                                            inputR,
                                            WM_SIGNAL_LEVEL_AC97( rawValL ),
                                            WM_SIGNAL_LEVEL_AC97( rawValR )
                                          );

    return status;
}

/*-------------------------

⌨️ 快捷键说明

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