@@ -831,6 +831,14 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t orig
831831 // Recalculate mappings
832832 Init ();
833833
834+ // Determine direction of parent clip at this frame (forward or reverse direction)
835+ // This is important for reversing audio in our resampler, for smooth reversed audio.
836+ Clip *parent = (Clip *) ParentClip ();
837+ bool is_increasing = true ;
838+ if (parent) {
839+ is_increasing = parent->time .IsIncreasing (original_frame_number);
840+ }
841+
834842 // Init audio buffers / variables
835843 int total_frame_samples = 0 ;
836844 int channels_in_frame = frame->GetAudioChannelsCount ();
@@ -849,7 +857,7 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t orig
849857 // Get audio sample array
850858 float * frame_samples_float = NULL ;
851859 // Get samples interleaved together (c1 c2 c1 c2 c1 c2)
852- frame_samples_float = frame->GetInterleavedAudioSamples (sample_rate_in_frame, NULL , &samples_in_frame);
860+ frame_samples_float = frame->GetInterleavedAudioSamples (sample_rate_in_frame, NULL , &samples_in_frame, !is_increasing );
853861
854862 // Calculate total samples
855863 total_frame_samples = samples_in_frame * channels_in_frame;
@@ -875,21 +883,10 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t orig
875883 frame_samples[s] = conv;
876884 }
877885
878-
879886 // Deallocate float array
880887 delete[] frame_samples_float;
881888 frame_samples_float = NULL ;
882889
883- ZmqLogger::Instance ()->AppendDebugMethod (
884- " FrameMapper::ResampleMappedAudio (got sample data from frame)" ,
885- " frame->number" , frame->number ,
886- " total_frame_samples" , total_frame_samples,
887- " target channels" , info.channels ,
888- " channels_in_frame" , channels_in_frame,
889- " target sample_rate" , info.sample_rate ,
890- " samples_in_frame" , samples_in_frame);
891-
892-
893890 // Create input frame (and allocate arrays)
894891 AVFrame *audio_frame = AV_ALLOCATE_FRAME ();
895892 AV_RESET_FRAME (audio_frame);
@@ -911,30 +908,12 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t orig
911908 // Update total samples & input frame size (due to bigger or smaller data types)
912909 total_frame_samples = Frame::GetSamplesPerFrame (AdjustFrameNumber (frame->number ), target, info.sample_rate , info.channels );
913910
914- ZmqLogger::Instance ()->AppendDebugMethod (
915- " FrameMapper::ResampleMappedAudio (adjust # of samples)" ,
916- " total_frame_samples" , total_frame_samples,
917- " info.sample_rate" , info.sample_rate ,
918- " sample_rate_in_frame" , sample_rate_in_frame,
919- " info.channels" , info.channels ,
920- " channels_in_frame" , channels_in_frame,
921- " original_frame_number" , original_frame_number);
922-
923911 // Create output frame (and allocate arrays)
924912 AVFrame *audio_converted = AV_ALLOCATE_FRAME ();
925913 AV_RESET_FRAME (audio_converted);
926914 audio_converted->nb_samples = total_frame_samples;
927915 av_samples_alloc (audio_converted->data , audio_converted->linesize , info.channels , total_frame_samples, AV_SAMPLE_FMT_S16, 0 );
928916
929- ZmqLogger::Instance ()->AppendDebugMethod (
930- " FrameMapper::ResampleMappedAudio (preparing for resample)" ,
931- " in_sample_fmt" , AV_SAMPLE_FMT_S16,
932- " out_sample_fmt" , AV_SAMPLE_FMT_S16,
933- " in_sample_rate" , sample_rate_in_frame,
934- " out_sample_rate" , info.sample_rate ,
935- " in_channels" , channels_in_frame,
936- " out_channels" , info.channels );
937-
938917 int nb_samples = 0 ;
939918
940919 // setup resample context
@@ -1023,11 +1002,6 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t orig
10231002
10241003 // Add samples to frame for this channel
10251004 frame->AddAudio (true , channel_filter, 0 , channel_buffer, position, 1 .0f );
1026-
1027- ZmqLogger::Instance ()->AppendDebugMethod (
1028- " FrameMapper::ResampleMappedAudio (Add audio to channel)" ,
1029- " number of samples" , position,
1030- " channel_filter" , channel_filter);
10311005 }
10321006
10331007 // Update frame's audio meta data
0 commit comments