+
+ void renderAudio( mlt_frame frame )
+ {
+ mlt_audio_format format = mlt_audio_s16;
+ int frequency = bmdAudioSampleRate48kHz;
+ int samples = mlt_sample_calculator( m_fps, frequency, m_count );
+ int16_t *pcm = 0;
+
+ if ( !mlt_frame_get_audio( frame, (void**) &pcm, &format, &frequency, &m_channels, &samples ) )
+ {
+ int count = samples;
+
+ if ( !m_isPrerolling )
+ {
+ uint32_t audioCount = 0;
+ uint32_t videoCount = 0;
+
+ // Check for resync
+ m_deckLinkOutput->GetBufferedAudioSampleFrameCount( &audioCount );
+ m_deckLinkOutput->GetBufferedVideoFrameCount( &videoCount );
+
+ // Underflow typically occurs during non-normal speed playback.
+ if ( audioCount < 1 || videoCount < 1 )
+ {
+ // Upon switching to normal playback, buffer some frames faster than realtime.
+ mlt_log_info( getConsumer(), "buffer underrun: audio buf %u video buf %u frames\n", audioCount, videoCount );
+ m_prerollCounter = 0;
+ }
+
+ // While rebuffering
+ if ( isBuffering() )
+ {
+ // Only append audio to reach the ideal level and not overbuffer.
+ int ideal = ( m_preroll - 1 ) * bmdAudioSampleRate48kHz / m_fps;
+ int actual = m_fifo->used / m_channels + audioCount;
+ int diff = ideal / 2 - actual;
+ count = diff < 0 ? 0 : diff < count ? diff : count;
+ }
+ }
+ if ( count > 0 )
+ sample_fifo_append( m_fifo, pcm, count * m_channels );
+ }
+ }
+
+ bool createFrame()