--- frontend/main.c.orig Sat Nov 23 18:34:59 2002 +++ frontend/main.c Fri Dec 13 14:48:55 2002 @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) { int frames, currentFrame; faacEncHandle hEncoder; - pcmfile_t *infile; + pcmfile_t *infile = NULL; unsigned int sr, chan; unsigned long samplesInput, maxBytesOutput; @@ -95,6 +95,8 @@ int main(int argc, char *argv[]) unsigned char *bitbuf; int bytesInput = 0; + int rawInput = 0; + int dieUsage = 0; FILE *outfile; @@ -112,10 +114,15 @@ int main(int argc, char *argv[]) { "nomidside", 0, 0, 'n' }, { "usetns", 0, 0, 't' }, { "cutoff", 1, 0, 'c' }, - { "bitrate", 1, 0, 'b' } + { "bitrate", 1, 0, 'b' }, + { "acousticmodel", 1, 0, 'p'}, + { "pcmraw", 0, 0, 'P'}, + { "pcmsamplerate", 1, 0, 'R'}, + { "pcmsamplebits", 1, 0, 'B'}, + { "pcmchannels", 1, 0, 'C'} }; - c = getopt_long(argc, argv, "m:o:rntc:b:p:", + c = getopt_long(argc, argv, "m:o:rntc:b:p:PR:B:C:", long_options, &option_index); if (c == -1) @@ -192,6 +199,60 @@ int main(int argc, char *argv[]) psymodelidx = i; break; } + case 'P': + { + rawInput = 1; + infile = malloc(sizeof(*infile)); + if (infile == NULL) { + fprintf(stderr, "%s: unable to allocate memory\n", progName); + return 1; + } + infile->f = NULL; + infile->channels = 2; + infile->samplerate = 44100; + infile->samplebits = 16; + infile->samples = 0; + break; + } + case 'R': + { + unsigned int i; + if (rawInput != 1) { + fprintf(stderr, "%s: for raw pcm input -P needs to be specified first\n", + progName); + dieUsage = 1; + break; + } + if (sscanf(optarg, "%u", &i) > 0) + infile->samplerate = i; + break; + } + case 'B': + { + unsigned int i; + if (rawInput != 1) { + fprintf(stderr, "%s: for raw pcm input -P needs to be specified first\n", + progName); + dieUsage = 1; + break; + } + if (sscanf(optarg, "%u", &i) > 0) + infile->samplebits = i; + break; + } + case 'C': + { + unsigned int i; + if (rawInput != 1) { + fprintf(stderr, "%s: for raw pcm input -P needs to be specified first\n", + progName); + dieUsage = 1; + break; + } + if (sscanf(optarg, "%u", &i) > 0) + infile->channels = i; + break; + } case '?': break; default: @@ -201,7 +262,7 @@ int main(int argc, char *argv[]) } /* check that we have at least two non-option arguments */ - if ((argc - optind) < 2) + if ((argc - optind) < 2 || dieUsage == 1) { int i; @@ -222,12 +283,16 @@ int main(int argc, char *argv[]) fprintf(stderr, " -n Don\'t use mid/side coding.\n"); fprintf(stderr, " -r RAW AAC output file.\n"); fprintf(stderr, " -t Use TNS coding.\n"); - fprintf(stderr, + fprintf(stderr, " -c X Set the bandwidth, X in Hz. (default=automatic)\n"); - fprintf(stderr, " -b X Set the bitrate per channel, X in kbps." - " (default is auto)\n\n"); - - faacEncClose(hEncoder); + fprintf(stderr, " -b X Set the bitrate per channel, X in kbps." + " (default is auto)\n"); + fprintf(stderr, " -P Raw PCM input mode (default 44100Hz 16bit stereo).\n"); + fprintf(stderr, " -R Raw PCM input rate.\n"); + fprintf(stderr, " -B Raw PCM input sample size (16 default or 8bits).\n"); + fprintf(stderr, " -C Raw PCM input channels.\n\n"); + + faacEncClose(hEncoder); return 1; } @@ -237,7 +302,29 @@ int main(int argc, char *argv[]) aacFileName = argv[optind++]; /* open the audio input file */ - infile = wav_open_read(audioFileName); + if (rawInput == 1) { + if (!strcmp(audioFileName, "-")) { +#ifdef WIN32 + setmode(fileno(stdin), O_BINARY); +#endif + infile->f = stdin; + infile->samples = 0; + } + else { + if (!(infile->f = fopen(audioFileName, "rb"))) + { + fprintf(stderr, "Couldn't open input file %s\n", audioFileName); + perror("Reason"); + return 1; + } + fseek(infile->f, 0 , SEEK_END); + infile->samples = ftell(infile->f) / + (((infile->samplebits > 8) ? 2 : 1) * infile->channels); + rewind(infile->f); + } + } else { + infile = wav_open_read(audioFileName); + } if (infile == NULL) { fprintf(stderr, "Couldn't open input file %s\n", audioFileName); @@ -307,12 +394,19 @@ int main(int argc, char *argv[]) #ifdef _WIN32 long begin = GetTickCount(); #endif - frames = (int)infile->samples / 1024 + 2; + if (infile->samples) + frames = (int)infile->samples / 1024 + 2; + else + frames = 0; currentFrame = 0; fprintf(stderr, "Encoding %s\n", audioFileName); - fprintf(stderr, + if (frames != 0) + fprintf(stderr, " frame | elapsed/estim | play/CPU | ETA\n"); + else + fprintf(stderr, + " frame | elapsed | play/CPU\n"); /* encoding loop */ for ( ;; ) { @@ -359,16 +453,24 @@ int main(int argc, char *argv[]) showcnt += 50; - fprintf(stderr, + if (frames != 0) + fprintf(stderr, "\r%5d/%-5d (%3d%%)| %6.1f/%-6.1f | %8.3f | %.1f ", currentFrame, frames, currentFrame*100/frames, timeused, timeused * frames / currentFrame, (1024.0 * currentFrame / sr) / timeused, timeused * (frames - currentFrame) / currentFrame); + else + fprintf(stderr, + "\r %5d | %6.1f | %8.3f ", + currentFrame, + timeused, + (1024.0 * currentFrame / sr) / timeused); fflush(stderr); #ifdef _WIN32 - sprintf(percent, "%.2f%% encoding %s", + if (frames != 0) + sprintf(percent, "%.2f%% encoding %s", 100.0 * currentFrame / frames, audioFileName); SetConsoleTitle(percent); #endif