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

📄 wmprofiles.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 2 页
字号:
                                                       WM_CHANNEL_ALL
                                                     );
                if ( WM_ERROR( newStatus ) )
                {
                    WM_TRACE( hDevice, (
                              "pActions[%d]: set volume of signal %s to %d (%.02fdB) failed: %s",
                              action,
                              WMSignalName( pAction->dest.signal ),
                              pAction->val.intval,
                              WM_SIGNAL_LEVEL_TO_DB( (float) pAction->val.intval ),
                              WMStatusText( newStatus )
                            ));
                }
                break;

            case WMA_MUTE_SIGNAL:
                newStatus = WMAudioMuteSignal( hDevice,
                                               pAction->dest.signal,
                                               pAction->val.boolval
                                             );
                if ( WM_ERROR( newStatus ) )
                {
                    WM_TRACE( hDevice, (
                              "pActions[%d]: %s signal %s failed: %s",
                              action,
                              pAction->val.boolval ? "mute" : "unmute",
                              WMSignalName( pAction->dest.signal ),
                              WMStatusText( newStatus )
                            ));
                }
                break;

#endif /* WM_AUDIO */
            case WMA_LOAD_PROFILE:
                newStatus = WMLoadNamedProfile( hDevice, pAction->val.string );
                if ( WM_ERROR( newStatus ) )
                {
                    WM_TRACE( hDevice, (
                              "pActions[%d]: load profile %s failed: %s",
                              action,
                              pAction->val.string,
                              WMStatusText( newStatus )
                            ));
                }
                break;

            default:
                newStatus = WMS_UNSUPPORTED;
                WM_TRACE( hDevice, (
                          "pActions[%d]: action not recognised (%d)",
                          action,
                          pAction->action
                        ));
                break;
        }
        
        /* Update our status with the new status */
        if ( WM_SUCCESS( status ) )
            status = newStatus;
    }
        
    /*
     * And say whether it worked.
     */
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMLoadNamedProfile
 *
 * Loads the named profile with the given name. It checks the profiles in
 * Wolfson\Common\UserProfiles.c first, followed by the profiles in the
 * codec's chipdef when looking for the profiles to load, and calls
 * WMLoadProfile with the first profile with a matching name. Name
 * comparison is case insensitive.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      profile             name of profile to load
 *
 * Returns:     WMSTATUS
 *      WMS_UNKNOWN_PROFILE if there is no profile with that name for the
 *      given device.
 *      The first error status, or WMS_SUCCESS if all actions completed
 *      successfully.  Note: even if this function returns an error status,
 *      some actions may have been executed.
 *---------------------------------------------------------------------------*/
WMSTATUS WMLoadNamedProfile( WM_DEVICE_HANDLE   hDevice,
                             const char         *profile
                           )
{
    WMSTATUS            status;
    const WM_PROFILE    *pProfile;
    const WM_CHIPDEF    *pChipDef = WMGetChipDef( hDevice );
    
    WM_ASSERT( hDevice, pChipDef );
    if ( !pChipDef )
    {
    	status = WMS_NO_SUPPORTED_DEVICE;
        goto finish;
    }

    /*
     * Try the user table first.
     */
    pProfile = private_FindProfile( profile,
                                    pChipDef->deviceType,
                                    g_UserProfiles,
                                    g_nUserProfiles
                                  );
    if ( !pProfile )
    {
        /*
         * Not there.  Try the codec.
         */
        pProfile = private_FindProfile( profile,
                                        pChipDef->deviceType,
                                        pChipDef->profiles,
                                        pChipDef->nProfiles
                                      );
    }
    
    /*
     * If we found it, try loading it.
     */
    if ( pProfile )
    {
        status = WMLoadProfile( hDevice, pProfile->actions, pProfile->nActions );
    }
    else
    {
        status = WMS_UNKNOWN_PROFILE;
    }
    
    /*
     * We're done.
     */
finish:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    private_FindProfile
 *
 * Looks for a profile with the given name in the table of profiles and
 * returns a pointer to it.
 *
 * Parameters:
 *      name                name of profile to load
 *      deviceType          device for which this profile has been created
 *      profiles            profile table to check
 *      nProfiles           number of profiles in the table
 *
 * Returns:     const WM_PROFILE *
 *      The first profile with a matching name and chiptype, or NULL if
 *      no profiles match.
 *---------------------------------------------------------------------------*/
static const WM_PROFILE *private_FindProfile( const char        *name,
                                              WM_CHIPTYPE       deviceType,
                                              const WM_PROFILE  *profiles,
                                              unsigned int      nProfiles
                                            )
{
    unsigned int i;
    
    for ( i = 0; i < nProfiles; i++ )
    {
        const WM_PROFILE *pProfile = &profiles[i];
        if ( private_NamesMatch( name, pProfile->name ) &&
             pProfile->deviceType == deviceType
           )
        {
            return pProfile;
        }
    }
    
    return NULL;
}

/*-----------------------------------------------------------------------------
 * Function:    private_NamesMatch
 *
 * Checks whether two strings are the same name.
 *
 * Parameters:
 *      name1               first name to check
 *      name2               second name to check
 *
 * Returns:     WM_BOOL
 *      TRUE if the two names match.
 *      FALSE otherwise.
 *---------------------------------------------------------------------------*/
static WM_BOOL private_NamesMatch( const char *name1, const char *name2 )
{
    const char *cPtr1 = name1;
    const char *cPtr2 = name2;
    
    for ( cPtr1 = name1, cPtr2 = name2;
          '\0' != *cPtr1 && '\0' != *cPtr2;
          cPtr1++, cPtr2++
        )
    {
        /* If the characters don't match, nor do the strings */
        if ( toupper( *cPtr1 ) != toupper( *cPtr2 ) )
        {
            return FALSE;
        }
    }
    
    /* They match if both strings are empty */
    if ( '\0' == *cPtr1 && '\0' == *cPtr2 )
    {
        return TRUE;
    }
    
    /* One string hasn't finished yet - no match */
    return FALSE;
}

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

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