Home > other >  How to 16 48000 sampling rate stereo PCM file by hisi into aac audio encoder code
How to 16 48000 sampling rate stereo PCM file by hisi into aac audio encoder code

Time:09-20

Open a 16-bit sampling rate of 48000 stereo PCM file, how to configure
Typedef struct hiAUDIO_FRAME_S
{
AUDIO_BIT_WIDTH_E enBitwidth;/* audio frame bitwidth */
AUDIO_SOUND_MODE_E enSoundmode;/* audio frame momo or stereo mode */
HI_U8 * u64VirAddr [2];
HI_U64 u64PhyAddr [2].
HI_U64 u64TimeStamp;/* audio frame timestamp */
HI_U32 u32Seq;/* audio frame seq */
HI_U32 u32Len;/* data lenth per channel frame in */
HI_U32 u32PoolId [2].
} AUDIO_FRAME_S;

Then call HI_S32 HI_MPI_AENC_SendFrame (AENC_CHN AeChn, const AUDIO_FRAME_S * pstFrm, const AEC_FRAME_S * pstAecFrm); Encoded into aac, the following code should be how to configure the audio data structure

If # 1
AIO_ATTR_S stAioAttr;
HI_S32 s32AencChnCnt;
# ifdef HI_ACODEC_TYPE_TLV320AIC31
AUDIO_DEV AiDev=SAMPLE_AUDIO_EXTERN_AI_DEV;
AUDIO_DEV AoDev=SAMPLE_AUDIO_EXTERN_AO_DEV;
StAioAttr. EnSamplerate=AUDIO_SAMPLE_RATE_48000;
StAioAttr. EnBitwidth=AUDIO_BIT_WIDTH_16;
StAioAttr. EnWorkmode=AIO_MODE_I2S_MASTER;
StAioAttr. EnSoundmode=AUDIO_SOUND_MODE_STEREO;
StAioAttr. U32EXFlag=0;
StAioAttr. U32FrmNum=30;
StAioAttr. U32PtNumPerFrm=AACLC_SAMPLES_PER_FRAME;
StAioAttr. U32ChnCnt=2;
StAioAttr. U32ClkSel=1;
StAioAttr. EnI2sType=AIO_I2STYPE_EXTERN;
# the else
AUDIO_DEV AiDev=SAMPLE_AUDIO_INNER_AI_DEV;
AUDIO_DEV AoDev=SAMPLE_AUDIO_INNER_AO_DEV;
StAioAttr. EnSamplerate=AUDIO_SAMPLE_RATE_48000;
StAioAttr. EnBitwidth=AUDIO_BIT_WIDTH_16;
StAioAttr. EnWorkmode=AIO_MODE_I2S_MASTER;
StAioAttr. EnSoundmode=AUDIO_SOUND_MODE_STEREO;
StAioAttr. U32EXFlag=0;
StAioAttr. U32FrmNum=30;
StAioAttr. U32PtNumPerFrm=AACLC_SAMPLES_PER_FRAME;
StAioAttr. U32ChnCnt=2;
StAioAttr. U32ClkSel=0;
StAioAttr. EnI2sType=AIO_I2STYPE_INNERCODEC;
# endif
Gs_bAioReSample=HI_FALSE;
EnInSampleRate=AUDIO_SAMPLE_RATE_BUTT;
EnOutSampleRate=AUDIO_SAMPLE_RATE_BUTT;


S32AencChnCnt=stAioAttr. U32ChnCnt & gt;> StAioAttr. EnSoundmode;//1
S32Ret=SAMPLE_COMM_AUDIO_StartAenc (s32AencChnCnt, & amp; StAioAttr gs_enPayloadType);
If (s32Ret! HI_SUCCESS=)
{
SAMPLE_DBG (s32Ret);

}

AUDIO_FRAME_S stFrame;
AEC_FRAME_S stAecFrm;
AUDIO_STREAM_S stStream;
FILE * fp=fopen ("/MNT/playout_t. PCM ", "rb +");
The FILE * fp_down=fopen ("/MNT/audio. Aac, "" wb +");
Int nBytesRead=0;
Int s32GetRet=1;
Unsigned char * pbPCMBuffer=(unsigned char *) malloc (960);
StFrame. U64VirAddr [0]=(unsigned char *) malloc (960);
StFrame. EnBitwidth=1;
StFrame. EnSoundmode=1;

StFrame. U64TimeStamp=0;
While (1)
{
NBytesRead=fread (pbPCMBuffer, 1, 960, fp);
Printf (" nBytesRead=% d \ n ", nBytesRead);
StFrame. U32Len=nBytesRead;
Memcpy (stFrame u64VirAddr [0], pbPCMBuffer, nBytesRead);
StFrame. U32Len=nBytesRead;

Memset (& amp; StAecFrm, 0, sizeof (AEC_FRAME_S));
S32Ret=HI_MPI_AENC_SendFrame (0, & amp; StFrame, & amp; StAecFrm);
If (HI_SUCCESS!=s32Ret)
{
Printf (" % s: HI_MPI_AENC_SendFrame, failed with % # x! \ n ", \
__FUNCTION__ s32Ret);

break;

}

S32GetRet=HI_MPI_AENC_GetStream (0, & amp; StStream HI_FALSE);
If (HI_SUCCESS!=s32GetRet)
{
Printf (" % s: HI_MPI_AENC_GetStream, failed with % # x! \ n ", \
__FUNCTION__ s32GetRet);
}

Fwrite (stStream. PStream, 1, stStream u32Len, fp_down);

If (nBytesRead & lt;=0)
{
break;
}

}
# endif
break;
}
  • Related