📄 g711tesc.c
字号:
/*
* G.711 C test harness
* Copyright (C) ARM Limited 1998-1999. All rights reserved.
*/
#include <stdlib.h>
#include <string.h>
#include "g711c.h"
#include "g711s.h"
#include "g711tesc.h"
#include "definesc.h"
#include "fileutlc.h"
#include "optionsc.h"
#define G711_OPTIONS 28
#define ALAWBYTES 1
#define LINEARBYTES 2
#define ULAWBYTES 1
/* define the number of bytes for data types */
static void Menu( unsigned int numberOptions ) ;
static char *ProcessConvert( char inputs[ ], unsigned int numberBytesIn, unsigned int option, unsigned int *numberBytesOut ) ;
/**** Convert ***********************************************************************
*
* Version & Date
* ------- ----
* 1.0.0, 30/06/1998
*
* Description
* -----------
* read a file of PCM or A/u-law data samples given by the user, encode them into
* one of A-law, u-law or PCM samples (depending on choice made from menu) using
* ARM or C routines, then if chosen, immediately decode them back
* to the original PCM or A/u-law samples using ARM or C routines, and write
* the new values calculated to a file given by the user
*
* information is also calculated including the number of bits in both the original
* data and encoded data (after one stage if fully transforming) with the percentage
* reduction between the original and new samples given
*
* Inputs
* ------
* option
* - a value that should be between 1 and 28 and returned from a call to NextTask
* the value corresponds to a menu choice and determines which of ARM or C routines
* are used for the encoding and possible decoding
* Return Values
* ------ ------
* TRUE - the transformation process was successful and data written
* FALSE - some error occurred during process (memory problems?)
*
* History (with dates)
* ------- ---- -----
* 1.0.0, 30/06/1998 first release
*
************************************************************************************/
static Boolean Convert( unsigned int option )
{
char *origInputs ;
unsigned int numberBytesIn ;
char *outputs = NULL ;
unsigned int numberBytesOut ;
char *decodedInputs = NULL ;
unsigned int numberBytesDecoded ;
printf( "Perform conversion...\n\n" ) ;
if( ( origInputs = ( char * )GetData( BYTEBYTES, "input", &numberBytesIn ) ) == NULL ) {
return FALSE ;
}
switch( option ) {
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
case 8 :
printf( "Converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option, &numberBytesOut ) ;
break ;
case 9 :
case 10 :
case 13 :
case 14 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 8, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 6, &numberBytesDecoded ) ;
break ;
case 11 :
case 15 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 10, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 7, &numberBytesDecoded ) ;
break ;
case 12 :
case 16 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 10, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 9, &numberBytesDecoded ) ;
break ;
case 17 :
case 18 :
case 19 :
case 20 :
printf( "Converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 8, &numberBytesOut ) ;
break ;
case 21 :
case 22 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 12, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 10, &numberBytesDecoded ) ;
break ;
case 23 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 14, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 11, &numberBytesDecoded ) ;
break ;
case 24 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 14, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 13, &numberBytesDecoded ) ;
break ;
case 25 :
case 26 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 14, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 16, &numberBytesDecoded ) ;
break ;
case 27 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 16, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 17, &numberBytesDecoded ) ;
break ;
case 28 :
printf( "Forward converting...\n\n" ) ;
outputs = ProcessConvert( origInputs, numberBytesIn, option - 16, &numberBytesOut ) ;
printf( "Inverse converting...\n\n" ) ;
decodedInputs = ProcessConvert( outputs, numberBytesOut, option - 19, &numberBytesDecoded ) ;
break ;
case 0 :
default :
free( ( void * ) origInputs ) ;
if( decodedInputs != NULL ) {
free( ( void * ) decodedInputs ) ;
}
return TRUE ;
}
if( !outputs ) {
free( ( void * ) origInputs ) ;
return FALSE ;
}
switch( option ) {
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
case 8 :
case 17 :
case 18 :
case 19 :
case 20 :
SaveData( outputs, numberBytesOut, BYTEBYTES, 0, "converted" ) ;
break ;
case 9 :
case 10 :
case 11 :
case 12 :
case 13 :
case 14 :
case 15 :
case 16 :
case 21 :
case 22 :
case 23 :
case 24 :
case 25 :
case 26 :
case 27 :
case 28 :
if( !decodedInputs ) {
free( ( void * ) origInputs ) ;
if( outputs != NULL ) {
free( ( void * ) outputs ) ;
}
return FALSE ;
}
SaveData( decodedInputs, numberBytesDecoded, BYTEBYTES, 0, "fully converted" ) ;
break ;
case 0 :
default :
break ;
}
free( ( void * ) origInputs ) ;
free( ( void * ) outputs ) ;
if( decodedInputs != NULL ) {
free( ( void * ) decodedInputs ) ;
}
return TRUE ;
}
/**** g711_main *********************************************************************
*
* Version & Date
* ------- ----
* 1.0.0, 30/06/1998
*
* Description
* -----------
* initialise the application then loop whilst the user is still working
*
* Return Values
* ------ ------
* 0 - application terminated correctly
* 1 - some error occurred
*
* History (with dates)
* ------- ---- -----
* 1.0.0, 30/06/1998 first release
*
************************************************************************************/
int g711_main( int argc, char **argv )
{
unsigned int option ;
#ifdef __BIG_ENDIAN
char newStdIn[ ] = "stdinb" ;
char newStdOut[ ] = "stdoutb" ;
char newStdErr[ ] = "stderrb" ;
#else
char newStdIn[ ] = "stdinl" ;
char newStdOut[ ] = "stdoutl" ;
char newStdErr[ ] = "stderrl" ;
#endif
unsigned int stdio = 0 ;
if( ChangeStdIO( &argc, &argv, newStdIn, stdin ) == STDINID ) {
stdio |= ( 1 << STDINID ) ;
}
if( ChangeStdIO( &argc, &argv, newStdOut, stdout ) == STDOUTID ) {
stdio |= ( 1 << STDOUTID ) ;
}
if( ChangeStdIO( &argc, &argv, newStdErr, stderr ) == STDERRID ) {
stdio |= ( 1 << STDERRID ) ;
}
printf( "Program to perform A-law, u-law conversions.\n\n" ) ;
printf( "This application provides access to the conversions with\n" ) ;
printf( "16-bit binary PCM input data or 8-bit A-law or u-law binary input data.\n\n" ) ;
while( 1 ) {
if( ( option = NextTask( G711_OPTIONS, &Menu ) ) == 0 ) {
break ;
}
Convert( option ) ;
}
/* redirection based on trying to open files that don't exist do using defaults */
if( stdio & ( 1 << STDINID ) ) {
ResetStdIO( stdin ) ;
}
if( stdio & ( 1 << STDOUTID ) ) {
ResetStdIO( stdout ) ;
}
if( stdio & ( 1 << STDERRID ) ) {
ResetStdIO( stderr ) ;
}
return 0 ;
}
/**** Menu **************************************************************************
*
* Version & Date
* ------- ----
* 1.0.0, 30/06/1998
*
* Description
* -----------
* print the menu of options to the screen (defined in standard way for NextTask
* function and will be called by NextTask)
*
* Inputs
* ------
* numberOptions
* - the number of menu options that should be printed
*
* History (with dates)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -