📄 main.c
字号:
#ifdef PRIO
else if( strstr( arg+1, "PRIO=" ) == arg+1 )
{
strcpy( prioString, arg+6 );
pPrioString = prioString;
}
#endif
else if( !strcmp( arg+1, "BR" ) )
{
ofs++;
if( ofs == argc )
return ofs;
wantedBitrate = atoi( argv[ofs] );
if( wantedBitrate > 1000 )
wantedBitrate /= 1000;
}
else
{
y = 0;
for( x = 1 ; arg[x] >= '0' && arg[x] <= '9' ; x++ )
y = y * 10 + (arg[x] - '0');
if( arg[x] == 0 )
{
wantedBitrate = y;
if( wantedBitrate > 1000 )
wantedBitrate /= 1000;
}
else
return ofs;
}
}
return ofs;
}
/*____ readLocalSwitches() ___________________________________________________*/
int readLocalSwitches( int argc, char * argv[], Job * psJob )
{
int ofs;
char arg[256];
int x, y;
for( ofs = 0 ; ofs < argc ; ofs++ )
{
strcpy( arg, argv[ofs] );
mystrupr( arg );
if( arg[0] != '-' )
return ofs;
if( !strcmp( arg+1, "MONO" ) || !strcmp( arg+1, "DM" ) )
{
psJob->sInput.outputType = DOWNMIX_MONO;
psJob->sCodec.mode = 3;
}
else if( !strcmp( arg+1, "CRC" ) )
psJob->sCodec.fCRC = TRUE;
else if( !strcmp( arg+1, "PRIVATE" ) || !strcmp( arg+1, "P" ) )
psJob->sCodec.fPrivate = TRUE;
else if( !strcmp( arg+1, "COPYRIGHT" ) || !strcmp( arg+1, "C" ) )
psJob->sCodec.fCopyright = TRUE;
else if( !strcmp( arg+1, "ORIGINAL" ) )
psJob->sCodec.fOriginal = TRUE;
else if( !strcmp( arg+1, "COPY" ) )
psJob->sCodec.fOriginal = FALSE;
else if( !strcmp( arg+1, "DELETE" ) || !strcmp( arg+1, "DEL" ) )
psJob->fDeleteSource = TRUE;
else if( !strcmp( arg+1, "SWAP" ) )
{
if( psJob->sInput.fReadStereo == TRUE )
{
psJob->sInput.outputType = INVERSE_STEREO;
psJob->sCodec.mode = 3;
}
}
else if( !strcmp( arg+1, "LEFTMONO" ) || !strcmp( arg+1, "LM" ))
{
if( psJob->sInput.fReadStereo == TRUE )
{
psJob->sInput.outputType = LEFT_CHANNEL_MONO;
psJob->sCodec.mode = 3;
}
}
else if( !strcmp( arg+1, "RIGHTMONO" ) || !strcmp( arg+1, "RM" ))
{
if( psJob->sInput.fReadStereo == TRUE )
{
psJob->sInput.outputType = RIGHT_CHANNEL_MONO;
psJob->sCodec.mode = 3;
}
}
else if( !strcmp( arg+1, "BR" ) )
{
ofs++;
if( ofs == argc )
return ofs;
psJob->sCodec.bitrate = atoi( argv[ofs] );
if( psJob->sCodec.bitrate > 1000 )
{
psJob->sCodec.bitrate /= 1000;
wantedQuit = TRUE;
}
}
else if( !strcmp( arg+1, "HQ" ) )
{
wantedQuit = TRUE; /* Dummy for l3enc support */
}
else
{
y = 0;
for( x = 1 ; arg[x] >= '0' && arg[x] <= '9' ; x++ )
y = y * 10 + (arg[x] - '0');
if( arg[x] == 0 )
{
psJob->sCodec.bitrate = y;
if( psJob->sCodec.bitrate > 1000 )
psJob->sCodec.bitrate /= 1000;
}
else
return ofs;
}
}
return ofs;
}
/*____ validateJobs() _________________________________________________________*/
int validateJobs( Job * psJob )
{
static int aValidBitrates[14] = { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 };
int i;
int fOk = TRUE;
while( psJob != NULL && fOk )
{
fOk = FALSE;
for( i = 0 ; i < 14 ; i++ )
if( wantedBitrate == aValidBitrates[i] )
fOk = TRUE;
psJob = psJob->psNext;
}
if( fOk )
return TRUE;
fprintf( textout, "ERROR: %d is not a valid bitrate!\n\n", wantedBitrate );
fprintf( textout, "Valid bitrates are:\n\n" );
for( i = 0 ; i < 13 ; i++ )
fprintf( textout, "%d, ", aValidBitrates[i] );
fprintf( textout, "and %d kBit.\n", aValidBitrates[13] );
return FALSE;
}
/*____ printUsage() ___________________________________________________________*/
int printUsage( void )
{
fprintf( textout, "Usage: bladeenc [global switches] input1 [output1 [switches]] input2 ...\n" );
fprintf( textout, "\n" );
fprintf( textout, "General switches:\n" );
fprintf( textout, " -[kbit], -br [kbit] Set MP3 bitrate. Default is 128 (64 for mono output).\n" );
fprintf( textout, " -crc Include checksum data in MP3 file.\n" );
fprintf( textout, " -delete, -del Delete sample after successful encoding.\n" );
fprintf( textout, " -private, -p Set the private-flag in the output file.\n" );
fprintf( textout, " -copyright, -c Set the copyright-flag in the output file.\n" );
fprintf( textout, " -copy Clears the original-flag in the output file.\n" );
fprintf( textout, " -mono, -dm Produce mono MP3 files by combining stereo channels.\n" );
fprintf( textout, " -leftmono, -lm Produce mono MP3 files from left stereo channel only.\n" );
fprintf( textout, " -rightmono, -rm Produce mono MP3 files from right stereo channel only.\n" );
fprintf( textout, " -swap Swap left and right stereo channels.\n" );
fprintf( textout, "\n" );
fprintf( textout, "Global only switches:\n" );
fprintf( textout, " -quit, -q Quit without waiting for keypress when finished.\n" );
fprintf( textout, " -outdir=[dir] Save MP3 files in specified directory.\n" );
fprintf( textout, " -quiet Disable screen output.\n" );
#ifdef PRIO
fprintf( textout, " -prio=[prio] Sets the task priority for BladeEnc. Valid settings are\n" );
fprintf( textout, " HIGHEST, HIGHER, NORMAL, LOWER, LOWEST(default) and IDLE\n" );
#endif
fprintf( textout, "\n" );
fprintf( textout, "Input/output files can be replaced with STDIN and STDOUT respectively.\n" );
#ifdef DRAG_DROP
fprintf( textout, "To make a normal 128kBit MP3, just drag-n-drop your WAV onto the BladeEnc icon.\n" );
#endif
fprintf( textout, "\n" );
return TRUE;
}
/*____ addCommandlineJob() ____________________________________________________*/
int addCommandlineJob( int argc, char * argv[] )
{
int argOfs;
char temp[256];
Job * psOp, * psTemp;
int x;
psOp = (Job *) malloc( sizeof( Job ) );
psOp->psNext = NULL;
/* Open Input File */
strcpy( temp, argv[0] );
mystrupr( temp );
if( strcmp( temp, "STDIN" ) == 0 )
{
if( !fPreparedSTDIN )
{
prepStdin();
fPreparedSTDIN = TRUE;
}
strcpy( psOp->sourceFilename, "Standard input stream" );
x = openInput( &psOp->sInput, NULL );
}
else
{
strcpy( psOp->sourceFilename, argv[0] );
x = openInput( &psOp->sInput, argv[0] );
}
if( x != TRUE )
{
switch( psOp->sInput.errcode )
{
case -1:
fprintf( textout, "ERROR: '%s' is not a WAV or AIFF file!\n", psOp->sourceFilename );
break;
case -2:
fprintf( textout, "ERROR: Couldn't open '%s'!\n", psOp->sourceFilename );
break;
case -3:
fprintf( textout, "ERROR: Unexpected end of file '%s'!\n", psOp->sourceFilename );
break;
case -5:
fprintf( textout, "ERROR: Necessary chunk missing in '%s'!\n", psOp->sourceFilename );
break;
case -6:
fprintf( textout, "ERROR: Sample '%s' is of an unknown subtype!\n", psOp->sourceFilename );
break;
default:
fprintf( textout, "ERROR: Unknown error while opening '%s'!\n", psOp->sourceFilename );
}
free( psOp );
return FALSE;
}
if( !psOp->sInput.fReadStereo && (wantedInputType == STEREO || wantedInputType == INVERSE_STEREO) )
psOp->sInput.outputType = DOWNMIX_MONO;
else
psOp->sInput.outputType = wantedInputType;
/* Set sCodec.mode (MONO or STEREO) */
if( psOp->sInput.outputType == DOWNMIX_MONO || psOp->sInput.outputType == LEFT_CHANNEL_MONO
|| psOp->sInput.outputType == RIGHT_CHANNEL_MONO )
psOp->sCodec.mode = 3; /* Force to mono... */
else
{
psOp->sCodec.mode = 0;
}
/* Set frequency */
if( psOp->sInput.freq != 44100 && psOp->sInput.freq != 48000
&& psOp->sInput.freq != 32000 )
{
fprintf( textout, "ERROR: Sample '%s' is not in 32, 44.1 or 48 kHz!\n", psOp->sourceFilename );
closeInput( &(psOp->sInput) );
free( psOp );
return FALSE;
}
psOp->sCodec.frequency = psOp->sInput.freq;
/* Set bitrate */
if( wantedBitrate == -1 )
{
if( psOp->sCodec.mode == 3 )
wantedBitrate = 64;
else
wantedBitrate = 128;
}
else
psOp->sCodec.bitrate = wantedBitrate;
/* Set other parameters */
psOp->sCodec.bitrate = wantedBitrate;
psOp->sCodec.fPrivate = wantedPrivate;
psOp->sCodec.fCRC = wantedCRC;
psOp->sCodec.fCopyright = wantedCopyright;
psOp->sCodec.fOriginal = wantedOriginal;
psOp->fDeleteSource = wantedDeleteSource;
/* Set unsupported parameters */
psOp->sCodec.emphasis = 0;
argOfs = 1;
/* Check for output specification and set output name */
psOp->outputFilename[0] = 0;
if( argc > 1 )
{
strcpy( temp, argv[1] );
mystrupr( temp );
if( !strcmp( temp, "STDOUT" ) )
{
wantedSTDOUT = TRUE;
strcpy( psOp->outputFilename, "STDOUT" );
argOfs++;
}
else if( strstr( temp, ".MP3" ) != NULL )
{
strcpy( psOp->outputFilename, argv[1] );
argOfs++;
}
}
/* Generate output name if not allready set */
if( psOp->outputFilename[0] == 0 )
{
if( outputDir[0] != 0 )
{
strcpy( psOp->outputFilename, outputDir );
strcpy( temp, psOp->sourceFilename );
x = strlen( temp );
while( temp[x] != '.' && x >=0 )
x--;
if( x >= 0 )
strcpy( temp + x, ".mp3" );
else
{
x = strlen( temp );
strcat( temp, ".mp3" );
}
while( x >= 0 && temp[x] != '\\' && temp[x] != '/' && temp[x] != ':' )
x--;
x++;
strcat( psOp->outputFilename, temp + x );
}
else
{
strcpy( temp, psOp->sourceFilename );
x = strlen( temp );
while( temp[x] != '.' && x >=0 )
x--;
if( x >= 0 )
strcpy( temp + x, ".mp3" );
else
strcat( temp, ".mp3" );
strcpy( psOp->outputFilename, temp );
}
}
/* Read local switches */
argOfs += readLocalSwitches( argc - argOfs, argv + argOfs, psOp );
/* Put this Job in the batch */
if( psJobQueue == NULL )
psJobQueue = psOp;
else
{
psTemp = psJobQueue;
while( psTemp->psNext != NULL )
psTemp = psTemp->psNext;
psTemp->psNext = psOp;
}
return argOfs;
}
/*____ clearJobQueue() ________________________________________________________*/
int clearJobQueue( void )
{
while( psJobQueue != NULL )
removeJobQueueEntry( psJobQueue );
return TRUE;
}
/*____ removeQueueEntry() _____________________________________________________*/
int removeJobQueueEntry( Job * psJob )
{
Job * psPrev;
/* Unlink specified entry */
if( psJob == psJobQueue )
psJobQueue = psJob->psNext;
else
{
psPrev = psJobQueue;
while( psPrev->psNext != psJobQueue && psPrev->psNext != NULL )
psPrev = psPrev->psNext;
if( psPrev->psNext == NULL )
return FALSE;
psPrev->psNext = psJob->psNext;
}
/* Close open file, free the entry and return. */
closeInput( &psJob->sInput );
free( psJob );
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -