1 Star 0 Fork 8

白世祎/faac内存优化

forked from dma/faac内存优化 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test.c 2.36 KB
一键复制 编辑 原始数据 按行查看 历史
dma 提交于 2021-10-04 17:39 . 完善测试程序
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "faac.h"
int main()
{
int i;
faacEncHandle hEncoder;
uint64_t inputSamples = 0;
uint64_t maxOutputBytes = 0;
int32_t enc_out_len = 0;
int32_t read_len = 0;
FILE *fpr;
FILE *fpw;
uint8_t *in_buf;
uint8_t *out_buf;
fpr = fopen("in.pcm", "rb");
if (fpr == NULL)
{
printf("open input file error\n");
goto exit1;
}
fpw = fopen("out.aac", "wb");
if (fpw == NULL)
{
printf("open output file error\n");
goto exit2;
}
hEncoder = faacEncOpen(44100, 2, &inputSamples, &maxOutputBytes);
in_buf = (uint8_t *)malloc(sizeof(int16_t) * inputSamples);
if (in_buf == NULL)
{
printf("malloc in_buf error\n");
goto exit3;
}
out_buf = (uint8_t *)malloc(maxOutputBytes);
if (out_buf == NULL)
{
printf("malloc out_buf error\n");
goto exit4;
}
printf("in_buf size %d, out_buf size %d\n", (int32_t)(sizeof(int16_t) * inputSamples), (int32_t)maxOutputBytes);
faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(hEncoder);
config->mpegVersion = MPEG4;
config->aacObjectType = LOW;
// config->jointmode = JOINT_NONE;
// config->useLfe = 0;
// config->useTns = 0;
config->bitRate = 128000;
config->bandWidth = 16000;
// config->quantqual = 0;
config->outputFormat = ADTS_STREAM;
config->inputFormat = FAAC_INPUT_16BIT;
// config->pnslevel = 0;
if (!faacEncSetConfiguration(hEncoder, config))
{
printf("unsupported output format!\n");
goto exit5;
}
printf("---- start ----\n");
i = 0;
while (i++ < 1000)
{
read_len = fread(in_buf, 1, sizeof(int16_t) * inputSamples, fpr);
if (read_len != sizeof(int16_t) * inputSamples)
{
fseek(fpr, 0, SEEK_SET);
continue;
}
enc_out_len = faacEncEncode(hEncoder, (int32_t *)in_buf, inputSamples, out_buf, maxOutputBytes);
fwrite(out_buf, 1, enc_out_len, fpw);
}
faacEncClose(hEncoder);
printf("---- finish ----\n");
exit5:
free(out_buf);
exit4:
free(in_buf);
exit3:
fclose(fpw);
exit2:
fclose(fpr);
exit1:
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/baishiyi/faac-memory-optimization.git
git@gitee.com:baishiyi/faac-memory-optimization.git
baishiyi
faac-memory-optimization
faac内存优化
master

搜索帮助