|
ASX Version4.20.14
|
This is an example of how to use the ASX Volume functions.
/* $Header: /home/eliot/asi/repo/cvsrepo/Repository/apps/asx/examples/volume/main.c,v 1.2 2010/06/22 18:15:12 as-age Exp $ */ #include "stdio.h" #include "stdlib.h" #include "asx.h" #include "asxstring.h" ASX_HANDLE hSystem=0; int CheckError(ASX_HANDLE hObj, const int nLine); void PrintControlName(ASX_HANDLE hControl); int main(int argc, char* argv[]) { ASX_HANDLE hAdapter; ASX_HANDLE hMixer; ASX_HANDLE hVolume; int nAdapterToUse=0; char szName[ASX_SHORT_STRING]; int nLength; int nVol; float fGain[2]; float fMin,fMax,fStep; int nChannels; // create the system ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem); CheckError( hSystem, __LINE__); // get the adapter ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter); CheckError( hSystem, __LINE__); // get the adapter name ASX_Adapter_GetName(hAdapter,szName,sizeof(szName),&nLength); CheckError( hAdapter, __LINE__); printf("Adapter [%d] is %s \n", nAdapterToUse,szName); // get the mixer handle ASX_Adapter_GetMixer( hAdapter, &hMixer ); CheckError( hAdapter, __LINE__); // get a volume object ASX_Mixer_GetControlByNodeTypeAndIndex( hMixer, asxNODE_PLAYER,0, // play object, index 0 asxNODE_LINE_OUT,0, // line out object, index 0 asxCONTROL_VOLUME, &hVolume); CheckError( hMixer, __LINE__); // print out control name PrintControlName(hVolume); ASX_Volume_GetRange( hVolume, &fMin, &fMax, &fStep); CheckError( hVolume, __LINE__); printf("Volume max %f, min %f, step %f\n",fMax,fMin,fStep); printf("Enter a volume to apply. 0 is fullscale, -100 is off.\n>"); scanf("%d",&nVol); printf("Volume set.\n"); fGain[0] = (float)nVol; // index 0 is the left channel fGain[1] = (float)nVol; // index 1 is the right channel ASX_Volume_GetChannels( hVolume, &nChannels); CheckError( hVolume, __LINE__); ASX_Volume_SetGain( hVolume, fGain, nChannels); CheckError( hVolume, __LINE__); printf("Press ENTER to exit\n"); getchar(); ASX_System_Delete(hSystem); return 0; } void PrintControlName(ASX_HANDLE hControl) { char *pszName; int nLen; enum asxCONTROL eControl; ASX_Control_GetType(hControl, &eControl); ASXSTRING_EnumToString(eControl,0,0,&nLen); pszName=(char *)malloc(nLen); ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen); printf("Control : %s\n",pszName); free(pszName); } int CheckError(ASX_HANDLE hObj, const int nLine) { int nError; int asxSubSystemErrorCode=0; char *pszAsxErrorString; char *pszAsxSubSystemErrorString; int nLen1,nLen2; ASX_Error_GetLast( hObj, (ASX_ERROR*)&nError, &asxSubSystemErrorCode); if(!nError) return 0; ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2); pszAsxErrorString = (char *)malloc(nLen1); pszAsxSubSystemErrorString = (char *)malloc(nLen2); ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2); printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n", nError, pszAsxErrorString, asxSubSystemErrorCode, pszAsxSubSystemErrorString ); printf("When called from source %s line %d\n",__FILE__,nLine); printf("Press ENTER to exit\n"); getchar(); free(pszAsxErrorString); free(pszAsxSubSystemErrorString); ASX_System_Delete(hSystem); exit(1); return 1; }
1.7.3