📄 g711tesc.c
字号:
* ------- ---- -----
* 1.0.0, 30/06/1998 first release
*
************************************************************************************/
static void Menu( unsigned int numberOptions )
{
if( numberOptions == G711_OPTIONS ) {
printf( " 1. Convert linear PCM -> A-law using ARM Assembler.\n" ) ;
printf( " 2. Convert linear PCM -> A-law using C.\n" ) ;
printf( " 3. Convert A-law -> linear PCM using ARM Assembler.\n" ) ;
printf( " 4. Convert A-law -> linear PCM using C.\n" ) ;
printf( "\n" ) ;
printf( " 5. Convert linear PCM -> u-law using ARM Assembler.\n" ) ;
printf( " 6. Convert linear PCM -> u-law using C.\n" ) ;
printf( " 7. Convert u-law -> linear PCM using ARM Assembler.\n" ) ;
printf( " 8. Convert u-law -> linear PCM using ARM Assembler.\n" ) ;
printf( "\n" ) ;
printf( " 9. Convert linear PCM -> A-law using ARM Assembler -> linear PCM using ARM Assembler.\n" ) ;
printf( "10. Convert linear PCM -> A-law using C -> linear PCM using C.\n" ) ;
printf( "11. Convert linear PCM -> A-law using ARM Assembler -> linear PCM using C.\n" ) ;
printf( "12. Convert linear PCM -> A-law using C -> linear PCM using ARM Assembler.\n" ) ;
printf( "\n" ) ;
printf( "13. Convert linear PCM -> u-law using ARM Assembler -> linear PCM using ARM Assembler.\n" ) ;
printf( "14. Convert linear PCM -> u-law using C -> linear PCM using C.\n" ) ;
printf( "15. Convert linear PCM -> u-law using ARM Assembler -> linear PCM using C.\n" ) ;
printf( "16. Convert linear PCM -> u-law using C -> linear PCM using ARM Assembler.\n" ) ;
printf( "\n" ) ;
printf( "17. Convert A-law -> u-law using ARM Assembler.\n" ) ;
printf( "18. Convert A-law -> u-law using C.\n" ) ;
printf( "\n" ) ;
printf( "19. Convert u-law -> A-law using ARM Assembler.\n" ) ;
printf( "20. Convert u-law -> A-law using C.\n" ) ;
printf( "\n" ) ;
printf( "21. Convert A-law -> u-law using ARM Assembler -> A-law using ARM Assembler.\n" ) ;
printf( "22. Convert A-law -> u-law using C -> A-law using C.\n" ) ;
printf( "23. Convert A-law -> u-law using ARM Assembler -> A-law using C.\n" ) ;
printf( "24. Convert A-law -> u-law using C -> A-law using ARM Assembler.\n" ) ;
printf( "\n" ) ;
printf( "25. Convert u-law -> A-law using ARM Assembler -> u-law using ARM Assembler.\n" ) ;
printf( "26. Convert u-law -> A-law using C -> u-law using C.\n" ) ;
printf( "27. Convert u-law -> A-law using ARM Assembler -> u-law using C.\n" ) ;
printf( "28. Convert u-law -> A-law using C -> u-law using ARM Assembler.\n" ) ;
}
else {
fprintf( stderr, "[Menu] Error in arguments, aborting.\n\n" ) ;
/* function name given since intended as internal error for programmer */
}
}
/**** PerformConversion *************************************************************
*
* Version & Date
* ------- ----
* 1.0.0, 30/06/1998
*
* Description
* -----------
* given an array of data values, either PCM or A/u-law, encode or decode them into
* the required PCM, A-law or u-law values and return these new values
*
* Inputs
* ------
* inputs
* - an array referencing the inputs either PCM or A/u-law samples
* numberBytes
* - the number of data points referenced by the array inputs (each entry 1 byte)
* this is not necessarily the number of inputs, since data may not be 1 byte each
* inBytes
* - the size in bytes of each input data item
* numberBytes/inBytes is the number of input data items being passed
* outBytes
* - the size in bytes for the output data items
* numberBytesOut
* - a pointer to an integer to hold the actual number of bytes written out
* this value gives the size of the character array returned
* ConvRoutine
* - a pointer to the conversion routine to be applied to the data
* the conversion routine should take one integer input with all unused top
* bits clear
* the conversion routine should return one integer the result of the conversion
* with all unused top bits clear
* this routine will perform the actual conversion between the data
* Outputs
* -------
* numberBytesOut
* - the number of bytes referenced by the returned character array
* the actual number of data items is numberBytesOut/outBytes
* undefined if NULL returned (see Return Values)
* Return Values
* ------ ------
* char * - an array of samples of PCM, A-law or u-law dependent on conversion
* NULL - some error occurred (memory allocation failed?)
*
* Memory allocated (not deallocated)
* ------ --------- --- -----
* the returned array of shorts
* deallocate after use
*
* History (with dates)
* ------- ---- -----
* 1.0.0, 30/06/1998 first release
*
************************************************************************************/
static char *PerformConversion( char inputs[ ], unsigned int numberBytes, unsigned int inBytes, unsigned int outBytes, unsigned int *numberBytesOut, int ( *ConvRoutine )( int ) )
{
unsigned char *ucinputs = ( unsigned char * )inputs ;
unsigned int numberInSamples ;
char *outputs ;
unsigned char *ucoutputs ;
unsigned int counter ;
int input ;
int output ;
if( ( !inputs ) || ( !numberBytesOut ) || ( !ConvRoutine ) ) {
fprintf( stderr, "[PerformConversion] Error in input arguments, aborting.\n\n" ) ;
/* function name given since intended as internal error for programmer */
return NULL ;
}
numberInSamples = numberBytes/inBytes ;
*numberBytesOut = numberInSamples * outBytes ;
if( ( outputs = ( char * )calloc( *numberBytesOut, sizeof( char ) ) ) == NULL ) {
fprintf( stderr, "Failure to create array for output data, aborting.\n\n" ) ;
*numberBytesOut = -1 ;
return NULL ;
}
ucoutputs = ( unsigned char * )outputs ;
for( counter = 0 ; counter < numberInSamples ; counter += 1 ) {
switch( inBytes ) {
case 1 :
input = ucinputs[ counter ] ;
input <<= 24 ;
input >>= 24 ;
break ;
case 2 :
input = ucinputs[ counter << 1 ] + ( ucinputs[ ( counter << 1 ) + 1 ] << 8 ) ;
input <<= 16 ;
input >>= 16 ;
break ;
case 4 :
input = ucinputs[ counter << 2 ] + ( ucinputs[ ( counter << 2 ) + 1 ] << 8 )
+ ( ucinputs[ ( counter << 2 ) + 2 ] << 16 )
+ ( ucinputs[ ( counter << 2 ) + 3 ] << 24 ) ;
break ;
default :
free( ( void * ) outputs ) ;
return NULL ;
}
output = ConvRoutine( input ) ;
switch( outBytes ) {
case 1 :
ucoutputs[ counter ] = ( unsigned char )output ;
break ;
case 2 :
ucoutputs[ ( counter << 1 ) ] = ( unsigned char )output ;
output >>= 8 ;
ucoutputs[ ( counter << 1 ) + 1 ] = ( unsigned char )output ;
break ;
case 4 :
ucoutputs[ ( counter << 2 ) ] = ( unsigned char )output ;
output >>= 8 ;
ucoutputs[ ( counter << 2 ) + 1 ] = ( unsigned char )output ;
output >>= 8 ;
ucoutputs[ ( counter << 2 ) + 2 ] = ( unsigned char )output ;
output >>= 8 ;
ucoutputs[ ( counter << 2 ) + 3 ] = ( unsigned char )output ;
break ;
default :
break ;
}
}
return outputs ;
}
/**** ProcessConvert ****************************************************************
*
* Version & Date
* ------- ----
* 1.0.0, 30/06/1998
*
* Description
* -----------
* given an array of data values, either PCM or A/u-law, determine the type of
* conversion required, set up the conversion routine and byte sizes for input and
* output data and then encode or decode the data into the required PCM, A-law or
* u-law values and return these new values
*
* Inputs
* ------
* inputs
* - an array referencing the inputs either PCM or A/u-law samples
* numberBytes
* - the number of data points referenced by the array inputs (each entry 1 byte)
* this is not necessarily the number of inputs, since data may not be 1 byte each
* option
* - the conversion to be performed determined from that given by the user adjusted
* to the range 1 to 12 as only performs one transformation here
* this defines whether data is PCM, A-law or u-law and thus byte size
* for the input data and the resulting data type and byte size
* numberBytesOut
* - a pointer to an integer to hold the actual number of bytes written out
* this value gives the size of the character array returned
* Outputs
* -------
* numberBytesOut
* - the number of bytes referenced by the returned character array
* the actual number of data items can be determined from numberBytesOut and
* option which defines the sample type returned and thus byte size for data
* undefined if NULL returned (see Return Values)
* Return Values
* ------ ------
* char * - an array of samples of PCM, A-law or u-law dependent on conversion
* NULL - some error occurred (memory allocation failed?)
*
* Memory allocated (not deallocated)
* ------ --------- --- -----
* the returned array of shorts
* deallocate after use
*
* History (with dates)
* ------- ---- -----
* 1.0.0, 30/06/1998 first release
*
************************************************************************************/
static char *ProcessConvert( char inputs[ ], unsigned int numberBytesIn, unsigned int option, unsigned int *numberBytesOut )
{
unsigned int inBytes ;
unsigned int outBytes ;
int ( *convRoutine )( int ) ;
if( ( !inputs ) || ( !numberBytesOut ) ) {
fprintf( stderr, "[ProcessConvert] Error in input arguments, aborting.\n\n" ) ;
/* function name given since intended as internal error for programmer */
return NULL ;
}
switch( option ) {
case 1 :
inBytes = LINEARBYTES ;
outBytes = ALAWBYTES ;
convRoutine = G711_linear2alaw ;
break ;
case 2 :
inBytes = LINEARBYTES ;
outBytes = ALAWBYTES ;
convRoutine = linear2alaw ;
break ;
case 3 :
inBytes = ALAWBYTES ;
outBytes = LINEARBYTES ;
convRoutine = G711_alaw2linear ;
break ;
case 4 :
inBytes = ALAWBYTES ;
outBytes = LINEARBYTES ;
convRoutine = alaw2linear ;
break ;
case 5 :
inBytes = LINEARBYTES ;
outBytes = ULAWBYTES ;
convRoutine = G711_linear2ulaw ;
break ;
case 6 :
inBytes = LINEARBYTES ;
outBytes = ULAWBYTES ;
convRoutine = linear2ulaw ;
break ;
case 7 :
inBytes = ULAWBYTES ;
outBytes = LINEARBYTES ;
convRoutine = G711_ulaw2linear ;
break ;
case 8 :
inBytes = ULAWBYTES ;
outBytes = LINEARBYTES ;
convRoutine = ulaw2linear ;
break ;
case 9 :
inBytes = ALAWBYTES ;
outBytes = ULAWBYTES ;
convRoutine = G711_alaw2ulaw ;
break ;
case 10 :
inBytes = ALAWBYTES ;
outBytes = ULAWBYTES ;
convRoutine = alaw2ulaw ;
break ;
case 11 :
inBytes = ULAWBYTES ;
outBytes = ALAWBYTES ;
convRoutine = G711_ulaw2alaw ;
break ;
case 12 :
inBytes = ULAWBYTES ;
outBytes = ALAWBYTES ;
convRoutine = ulaw2alaw ;
break ;
default :
return NULL ;
}
printf( "Number of samples for conversion is '%d'\n\n", numberBytesIn/inBytes ) ;
return PerformConversion( inputs, numberBytesIn, inBytes, outBytes, numberBytesOut, convRoutine ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -