If I use my routine to play an 8svx file from disk it works but I can't get it working with audio decoding of ffmpeg lib. I found some routine to convert float to int16 but it doesn't help.
if (packet.stream_index==AudStreamNum) { totalDecoded=0; AudBuffI=0; lastDecoded=avcodec_decode_audio4(AudCodecCtx,VidFrame,(int *)&got_sndframe_ptr,&packet); totalDecoded+=lastDecoded; if ((VidFrame!=NULL) && (VidFrame->data[0]!=NULL) && (got_sndframe_ptr!=0)) { if (lastDecoded==VidFrame->nb_samples) { AudBuff16=(int16 *)VidFrame->nb_samples; } else { if (AudBuff16==0) { AudBuffSize=VidFrame->nb_samples; AudBuff16=(int16 *)IExec->AllocVecTags(AudBuffSize*sizeof(int16), AVT_Alignment,4, //4 AVT_ClearWithValue,0, TAG_DONE); } else if (AudBuffSize!=VidFrame->nb_samples) { IExec->FreeVec(AudBuff16); AudBuffSize=VidFrame->nb_samples; AudBuff16=(int16 *)IExec->AllocVecTags(AudBuffSize*sizeof(int16), AVT_Alignment,4, //4 AVT_ClearWithValue,0, TAG_DONE); } if (AudBuff16!=0) { if ((AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLT) || (AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLTP)) { for (r=0; r<lastDecoded; r++) { AudBuff16[AudBuffI+r]=(int8)((float32)VidFrame->data[0][r]*(32767.0f)); } } AudBuffI+=lastDecoded; while (totalDecoded<AudBuffSize) { lastDecoded=avcodec_decode_audio4(AudCodecCtx,VidFrame,(int *)&got_sndframe_ptr,&packet); totalDecoded+=lastDecoded; if ((VidFrame!=NULL) && (VidFrame->data[0]!=NULL) && (got_sndframe_ptr!=0)) { if (totalDecoded<=AudBuffSize) { if ((AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLT) || (AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLTP)) { for (r=0; r<lastDecoded; r++) { AudBuff16[AudBuffI+r]=(int8)((float32)VidFrame->data[0][r]*(32767.0f)); } } AudBuffI+=lastDecoded; } else { if ((AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLT) || (AudCodecCtx->sample_fmt==AV_SAMPLE_FMT_FLTP)) { for (r=0; r<(AudBuffSize-(totalDecoded-lastDecoded)); r++) { AudBuff16[AudBuffI+r]=(int16)((float32)VidFrame->data[0][r]*(32767.0f)); } } AudBuffI+=lastDecoded; } } } // while (totalDecoded<AudBuffSize) if ((AHIAudType!=-1) && (AudBuff16!=0)) { AHIio->ahir_Std.io_Command=CMD_WRITE; AHIio->ahir_Std.io_Data=AudBuff16; AHIio->ahir_Std.io_Length=AudBuffSize; AHIio->ahir_Std.io_Offset=0; AHIio->ahir_Type=AHIST_M16S; //AHIAudType; AHIio->ahir_Frequency=AudCodecCtx->sample_rate; AHIio->ahir_Volume=0x10000; // full volume = 0x10000 AHIio->ahir_Position=0x8000; //stereopos AHIio->ahir_Link=NULL; IExec->DoIO((struct IORequest*)AHIio); ioreq_sent=TRUE; } else { ioreq_sent=FALSE; if (AHIAudType==-1) { IExec->DebugPrintF("Audio type not recognized, type=%ld, buff_ptr=%lu\n",AHIAudType,(uint32)AudBuff16); } } } } } } // audio frame
Any ideas what I'm doing wrong ?
AVFrame.data is an uint8 pointer. So what you are doing is to read a byte from the ffmpeg buffer, convert it to float, convert it back to int (wrongly casted to int8) and store it in your AHI buffer. Effectively you are converting uint8 to int8. That's not what you want.
Try this instead: