WriteAudioSamplesSync outputs distorted sound.

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Dario Maljur

  • Posts: 4
  • Joined: Thu Jun 18, 2020 7:01 am
  • Real Name: Dario Maljur

WriteAudioSamplesSync outputs distorted sound.

PostThu Jun 18, 2020 7:35 am

Hi.

I made a video player using FFMPEG libraries and for each frame I covert it to IDeckLinkMutableVideoFrame that I then output to Ninja2 with DisplayVideoFrameSync. All that is working perfectly.
But I'm having trouble outputting Audio frames.

I get raw audio from FFMPEG AVFrame audio frame which I then send to SDL's audio_callback function. Basically at this point I have a raw uint8_t buffer containing samples.

I then enabled audio output to Ninja with

Code: Select all
EnableAudioOutput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger,2,bmdAudioOutputStreamContinuous);


And from my audio_callback function I send the sample buffer to DeckLink using

Code: Select all
WriteAudioSamplesSync(buffer,count,&written);


This gives me output of slightly higher pitch than it should and I get a lot of noise.
The pitch is probably because the file contains 44Khz audio but the only enumeration for opening audio on DeckLink is 48Khz?

And noise is probably because not all bytes in the buffer are written. I get any number from 2000 to 6000 bytes written.
I tried to make sure that entire buffer is written by using

Code: Select all
 while (written < count)
       {
    unsigned int len = 0;
         deckLinkOutput->WriteAudioSamplesSync(&buffer[written],count_left,&len);
    written += len;
    count_left-=len;
       }


But this just output loud noise and completely slows my video player.

My question is. Is there a way to change sample rate to other that 48Kkz? If not, how can I output audio of different frequencies to DeckLink and how do I make sure that all the buffer is written?

Thanks,
Dario

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests