代码拉取完成,页面将自动刷新
同步操作将从 Vanishi/BXC_AudioDemo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//
// Created by sun on 2022/12/10.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "Adts.h"
#include "fdk-aac/aacdecoder_lib.h"
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
//Buffer:
//|-----------|-------------|
//chunk-------pos---len-----|
static Uint8* audio_chunk;
static Uint32 audio_len;
static Uint8* audio_pos;
/* Audio Callback
* The audio function callback takes the following parameters:
* stream: A pointer to the audio buffer to be filled
* len: The length (in bytes) of the audio buffer
*
*/
void fill_audio(void* data, Uint8* stream, int len) {
//SDL 2.0
//printf("fill_audio\n");
SDL_memset(stream, 0, len);
if (audio_len == 0)
return;
len = (len > audio_len ? audio_len : len);
SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
audio_pos += len;
audio_len -= len;
}
int main() {
const char* in_name = "data/test.aac";
//SDL2 start
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
printf("Could not initialize SDL - %s\n", SDL_GetError());
return -1;
}
SDL_AudioSpec wanted_spec;
wanted_spec.freq = 44100;
wanted_spec.format = AUDIO_S16SYS;
wanted_spec.channels = 2;
wanted_spec.silence = 0;
wanted_spec.samples = 1024;
wanted_spec.callback = fill_audio;
if (SDL_OpenAudio(&wanted_spec, NULL) < 0) {
printf("SDL_OpenAudio err \n");
return -1;
}
SDL_PauseAudio(0);
//SDL2 end
FILE* infile = fopen(in_name, "rb");
if (!infile) {
printf("failed to open %s\n", in_name);
return -1;
}
printf("-----+- ADTS Frame Table -+------+\n");
printf(" NUM | Profile | Frequency| Size | Decode Size |\n");
printf("-----+---------+----------+------+\n");
HANDLE_AACDECODER aacCoder;
aacCoder = aacDecoder_Open(TT_MP4_ADTS, 1);
AAC_DECODER_ERROR aacError;
int cnt = 0;
struct AdtsHeader adtsHeader;
int adtsHeaderLen;
int adtsContentLen;
unsigned int valid = 0;
uint8_t* frame = (uint8_t*)malloc(2000);
unsigned int decFrameSize = 2 * 1024 * sizeof(INT_PCM);
unsigned char* decFrame = (unsigned char*)malloc(decFrameSize);
while (true) {
adtsHeaderLen = fread(frame, 1, 7, infile);
// printf("adtsHeaderLen = %d \n",adtsHeaderLen);
if (adtsHeaderLen <= 0) {
printf("read adtsHeaderLen err\n");
break;
}
if (parseAdtsHeader(frame, &adtsHeader) < 0) {
printf("parseAdtsHeader err\n");
break;
}
adtsContentLen = fread(frame + 7, 1, adtsHeader.aacFrameLength - 7, infile);
// printf("adtsContentLen = %d \n",adtsContentLen);
if (adtsContentLen < 0) {
printf("read adtsContentLen err\n");
break;
}
valid = adtsHeader.aacFrameLength;
aacError = aacDecoder_Fill(aacCoder, &frame, &adtsHeader.aacFrameLength, &valid);
if (aacError > 0) {
printf("aacDecoder_Fill err\n");
break;
}
aacError = aacDecoder_DecodeFrame(aacCoder, (INT_PCM*)decFrame, decFrameSize / sizeof(INT_PCM), 0);
if (aacError > 0) {
printf("aacDecoder_DecodeFrame err\n");
break;
}
//Set audio buffer (PCM data)
audio_chunk = (Uint8*)decFrame;
//Audio buffer length
audio_len = decFrameSize;
audio_pos = audio_chunk;
while (audio_len > 0) {
// SDL_Delay(23);
SDL_Delay(1);
}
printf("cnt=%d,aacFrameLength=%d,decFrameSize=%d \n",cnt, adtsHeader.aacFrameLength, decFrameSize);
cnt++;
}
free(frame);
free(decFrame);
fclose(infile);
SDL_Quit();
printf("end\n");
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。