Home Why I can't listen to my .aac file encoded using faac lib?
Reply: 0

Why I can't listen to my .aac file encoded using faac lib?

PorkPiePie
1#
PorkPiePie Published in 2017-12-05 21:27:51Z

I'm trying to write on disk a .aac file which the sound I capture from a process like Windows Media Player using hooking/injection . The hook/injection works ok, then I write the .aac file on disk, but I can listen to nothing. The file header as follow bellow:

FILE * out = fopen("out.aac", "wb");
if (out == NULL)
{   printf("Error to open file!\n");
        return -1;
}
faacEncConfigurationPtr myFormat;
unsigned int sampleRate = 48000;
unsigned int nChannels = 2;  
unsigned int mpegVersion = MPEG2;
unsigned int objectType = LOW;
unsigned int useMidSide = 1;
unsigned int useTns = 0;
unsigned int useLfe = 0;
unsigned int bitRate = 0;
unsigned int bandWidth = 16000;
unsigned int quantqual = 100;
unsigned int outputFormat = 1; //ADTS
unsigned int inputFormat = FAAC_INPUT_16BIT;
unsigned int shortctl = SHORTCTL_NORMAL;
sndf.bigendian = 0;
sndf.channels = 2;
sndf.samplebytes = 4;
sndf.isfloat = 1;
sndf.samplerate = 48000;
sndf.in = read_buffer;d

if ((hEncoder = faacEncOpen(sampleRate, nChannels, &samplesInput, &maxBytesOutput)) == NULL)
 printf("faacEncOpen Failed!");

if ((myFormat = faacEncGetCurrentConfiguration(hEncoder)) == NULL)
    printf("faacEncGetCurrentConfiguration Failed!");

myFormat->mpegVersion = mpegVersion;
myFormat->aacObjectType = objectType;
myFormat->allowMidside = useMidSide;
myFormat->useTns = useTns;
myFormat->useLfe = useLfe;
myFormat->bitRate = bitRate;
myFormat->bandWidth = bandWidth;
myFormat->quantqual = quantqual;
myFormat->outputFormat = outputFormat;
myFormat->inputFormat = inputFormat;
myFormat->shortctl = shortctl;

if (!faacEncSetConfiguration(hEncoder, myFormat)) {
    printf("Unsupported output format!\n");
}

Then I start encoding it:

int numGet, iResult = 0;
int samplesRead, bytesEncode = 0, numFromCir;
int send_offset;
while (1) {
    do {
        numGet = 0;
        numGet = getAudio(get_buffer);
        fillbuffer(get_buffer, numGet);

        while ( getDataSize() >= 8192){
            numFromCir = getframe(read_buffer);
            samplesRead = wav_read_float32(&sndf, encoder_buffer, numFromCir / 4);
            if (samplesRead > 0){
                        if ((bytesEncode = faacEncEncode(hEncoder, (int32_t *)encoder_buffer, samplesRead, buffer , maxBytesOutput)) < 0)
                            printf("faacEncEncode Failed!\n");  



                    }
                }
                if (bytesEncode > 0){
                    iResult = fwrite(buffer, 1, bytesEncode, out);


                }
                Sleep(80);
            } while (iResult >= 0);

            printf("recv failed: %d\n", WSAGetLastError());

            fclose(out);
            closesocket(ClientSocket);
            faacEncClose(hEncoder);
            WSACleanup();

The audio output details are:

Format : ADTS Format/Info : Audio Data Transport Stream File size : 251 KiB

Audio Format : AAC Format/Info : Advanced Audio Codec Format version : Version 2 Format profile : LC Channel(s) : 2 channels Channel positions : Front: L R Sampling rate : 48.0 kHz Frame rate : 46.875 FPS (1024 SPF) Compression mode : Lossy Stream size : 251 KiB (100%)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.29962 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO