FAAC is an open-source project that provides source code in C (with Visual C headers and project files) for a DLL and various sample Windows applications designed to encode AAC (or MP4) audio files (attached or available here: [url removed, login to view]).
This project involves using the available source code to create a Win32 COM object (OCX) that exposes the following properties and methods (the project deliverable is a Visual C project file and all files necessary to compile the OCX using Visual C):
1) Properties to allow the host application to set the various values in the FAAC encoder configuration structure, information about the format of the source file, and sampling information for the peak file (all held until the "encode" method is called).
2) A single "encode" method that takes an input path/filename of an audio file to encode and an output path/filename to write the encoded files.
The functionality of the OCX is to encode the source file and produce two output files: the AAC-encoded audio file and a "peak" file that contains a stream of bytes that represent a sampling of the peak audio levels of the input file.
The AAC encoder is provided as the FAAC source code (and works as-is, as a DLL or part of a Win32 GUI, both provided as source code samples).
The peak file algorithm will be provided as Delphi source and/or pseudo-code (and is very simple--less than a dozen lines of code, performing a simple threshold sampling of the input file and writing out the resulting scaled value).
The input audio file will be in one of three formats: raw uLaw PCM, uLaw PCM with a WAV header, or raw n-bit PCM. The FAAC encoder requires raw PCM in either 8, 16, or 32 bits. Conversion from uLaw PCM to 16-bit PCM is performed by a simple, industry-standard algorithm, which will also be provided (a simple function implemented in less than a dozen lines of code). When the input file is a WAV file, the bits/sample and sample rate will be read from the WAV header, after which the process is identical to processing raw PCM files (the example Win32 GUI includes the code to extract these parameters from the WAV header).
The basic process of how the OCX will be used is:
1) Host creates the COM object
2) Host sets various properties in the COM object that override built-in defaults, as set in the OCX source code
3) Host calls "encode" method with source and destination path/filenames
4) OCX opens FAAC encoder and gets/sets configuration structure from internal properties
5) OCX opens input file and loops through input file, reading a block of audio data and feeding it to the FAAC encoder (converting uLaw PCM to raw 16-bit PCM, if needed), then writing out the output of the FAAC encoder (as *.m4p); while simultaneously sampling the input data to create the peak file (as *.peak, and writing it out as well
6) OCX closes the FAAC encoder and all files, upon reaching the end of the input file
7) OCX "encode" method returns "true" status to host (if any error occurs, "error" property of OCX is set to descriptive error message and "false" status is returned to host
Note that multiple instances of the OCX will be created at the same time on the same host (by multiple instances of Windows Scripting Host), so the OCX must be thread safe to run in this environment.
PS - The Attached "exe" ZIP file contains a DOS command line version of the FAAC encoder (source not provided/available) that performs all of the functions described above (and more); run the exe by itself to see help info.