LiVES  3.2.0
Macros | Functions
resample.c File Reference
#include "main.h"
#include "resample.h"
#include "callbacks.h"
#include "effects.h"
#include "audio.h"
#include "events.h"
#include "cvirtual.h"

Go to the source code of this file.

Macros

#define READJ_MAX   2.
 
#define READJ_MIN   0.1
 
#define SMTH_FRAME_LIM   8
 
#define SMTH_TC_LIM   (0.5 * TICKS_PER_SECOND_DBL)
 

Functions

void reorder_leave_back_set (boolean val)
 
LIVES_GLOBAL_INLINE ticks_t q_gint64 (ticks_t in, double fps)
 
LIVES_GLOBAL_INLINE ticks_t q_gint64_floor (ticks_t in, double fps)
 
LIVES_GLOBAL_INLINE ticks_t q_dbl (double in, double fps)
 
LIVES_GLOBAL_INLINE size_t quant_asamps (double seek, int arate)
 convert seek time to an integer number of samples More...
 
LIVES_GLOBAL_INLINE double quant_aseek (double seek, int arate)
 convert seek time (secs) to an (almost) integer number of samples More...
 
LIVES_GLOBAL_INLINE off_t quant_abytes (double seek, int arate, int achans, int asampsize)
 
LIVES_GLOBAL_INLINE int count_resampled_frames (int in_frames, double orig_fps, double resampled_fps)
 
boolean auto_resample_resize (int width, int height, double fps, int fps_num, int fps_denom, int arate, int asigned, boolean swap_endian)
 
void pre_analyse (weed_plant_t *elist)
 
weed_plant_t * quantise_events (weed_plant_t *in_list, double qfps, boolean allow_gap)
 quantise from event_list_t *in_list to *out_list at the new rate of qfps More...
 
void on_resample_audio_activate (LiVESMenuItem *menuitem, livespointer user_data)
 
void on_resaudio_ok_clicked (LiVESButton *button, LiVESEntry *entry)
 
void on_resaudw_asamps_changed (LiVESWidget *irrelevant, livespointer rubbish)
 
void on_resample_video_activate (LiVESMenuItem *menuitem, livespointer user_data)
 
void on_resample_vid_ok (LiVESButton *button, LiVESEntry *entry)
 
_resaudwcreate_resaudw (short type, render_details *rdet, LiVESWidget *top_vbox)
 resample audio window More...
 
void on_change_speed_activate (LiVESMenuItem *menuitem, livespointer user_data)
 
void on_change_speed_ok_clicked (LiVESButton *button, livespointer user_data)
 
int reorder_frames (int rwidth, int rheight)
 
int deorder_frames (int old_frames, boolean leave_bak)
 leave_bak is a special mode for the clipboard More...
 
boolean resample_clipboard (double new_fps)
 call this to resample clipboard video More...
 

Macro Definition Documentation

◆ READJ_MAX

#define READJ_MAX   2.

Definition at line 301 of file resample.c.

◆ READJ_MIN

#define READJ_MIN   0.1

Definition at line 302 of file resample.c.

◆ SMTH_FRAME_LIM

#define SMTH_FRAME_LIM   8

Definition at line 304 of file resample.c.

◆ SMTH_TC_LIM

#define SMTH_TC_LIM   (0.5 * TICKS_PER_SECOND_DBL)

Definition at line 305 of file resample.c.

Function Documentation

◆ auto_resample_resize()

boolean auto_resample_resize ( int  width,
int  height,
double  fps,
int  fps_num,
int  fps_denom,
int  arate,
int  asigned,
boolean  swap_endian 
)

Definition at line 80 of file resample.c.

◆ count_resampled_frames()

LIVES_GLOBAL_INLINE int count_resampled_frames ( int  in_frames,
double  orig_fps,
double  resampled_fps 
)

Definition at line 72 of file resample.c.

Referenced by add_lmap_error(), resample_clipboard(), and setmergealign().

◆ create_resaudw()

_resaudw* create_resaudw ( short  type,
render_details ,
LiVESWidget *  top_vbox 
)

resample audio window

type 1 : show current and new, type 2 : show new

Definition at line 1521 of file resample.c.

Referenced by on_capture_activate(), on_recaudclip_activate(), and on_resample_audio_activate().

◆ deorder_frames()

int deorder_frames ( int  old_frames,
boolean  leave_bak 
)

leave_bak is a special mode for the clipboard

Definition at line 2208 of file resample.c.

◆ on_change_speed_activate()

void on_change_speed_activate ( LiVESMenuItem *  menuitem,
livespointer  user_data 
)

Definition at line 2017 of file resample.c.

◆ on_change_speed_ok_clicked()

void on_change_speed_ok_clicked ( LiVESButton *  button,
livespointer  user_data 
)

Definition at line 2025 of file resample.c.

Referenced by create_new_pb_speed(), and on_redo_activate().

◆ on_resample_audio_activate()

void on_resample_audio_activate ( LiVESMenuItem *  menuitem,
livespointer  user_data 
)

Definition at line 1148 of file resample.c.

◆ on_resample_vid_ok()

void on_resample_vid_ok ( LiVESButton *  button,
LiVESEntry *  entry 
)

◆ on_resample_video_activate()

void on_resample_video_activate ( LiVESMenuItem *  menuitem,
livespointer  user_data 
)

Definition at line 1372 of file resample.c.

◆ on_resaudio_ok_clicked()

void on_resaudio_ok_clicked ( LiVESButton *  button,
LiVESEntry *  entry 
)

Definition at line 1159 of file resample.c.

Referenced by create_resaudw(), and on_redo_activate().

◆ on_resaudw_asamps_changed()

void on_resaudw_asamps_changed ( LiVESWidget *  irrelevant,
livespointer  rubbish 
)

Definition at line 1353 of file resample.c.

Referenced by create_resaudw().

◆ pre_analyse()

void pre_analyse ( weed_plant_t *  elist)

for older lists we didnt set the seek point at audio off, so ignore those

offs is what we will add to remianing events when we hit the end

Definition at line 307 of file resample.c.

◆ q_dbl()

LIVES_GLOBAL_INLINE ticks_t q_dbl ( double  in,
double  fps 
)

◆ q_gint64()

LIVES_GLOBAL_INLINE ticks_t q_gint64 ( ticks_t  in,
double  fps 
)

◆ q_gint64_floor()

LIVES_GLOBAL_INLINE ticks_t q_gint64_floor ( ticks_t  in,
double  fps 
)

Definition at line 35 of file resample.c.

Referenced by calc_new_playback_position().

◆ quant_abytes()

LIVES_GLOBAL_INLINE off_t quant_abytes ( double  seek,
int  arate,
int  achans,
int  asampsize 
)

Definition at line 66 of file resample.c.

◆ quant_asamps()

LIVES_GLOBAL_INLINE size_t quant_asamps ( double  seek,
int  arate 
)

convert seek time to an integer number of samples

Definition at line 52 of file resample.c.

Referenced by quant_abytes(), and quant_aseek().

◆ quant_aseek()

LIVES_GLOBAL_INLINE double quant_aseek ( double  seek,
int  arate 
)

convert seek time (secs) to an (almost) integer number of samples

Definition at line 58 of file resample.c.

◆ quantise_events()

weed_plant_t* quantise_events ( weed_plant_t *  in_list,
double  qfps,
boolean  allow_gap 
)

quantise from event_list_t *in_list to *out_list at the new rate of qfps

quantise frame events for a single clip

This is called from 3 functions:

  • before rendering a recorded event_list
  • when entering multitrack, if the fps is mismatched
  • when resampling a clip (only frame events)
Returns
new event list, or old event list if no changes are needed (i.e fps is already correct), or NULL on error

if old_list has no frames then we just return an empty list otherwise returned list will always have at least one event (a frame at timecode 0).

if there is a timecode gap at the start of the old_list (i.e frame 1 has a non-zero timecode) then this well be eliminated in the out iist; i.e. frame 1 in out_list always has a timecode of 0.

if the old event_list has a fixed fps, then we try to keep the duration as near as possible, so:

nframes_new = MAX(nframes_old / old_fps * new_fps , 1) the value is rounded DOWN in the case that qfps < old_fps and rounded to the nearest integer in the case that qfps > old_fps

e.g 210 frames @ 20.0 fps -> 157 frames @ 15.0 fps -> 410 frames @ 39.0 fps

See also
count_resmpled_frames()

i.e when the duration of the final frame is added, the total will always be >= duration of the old list

if old_list has no fixed fps, then new_frames = (timecode of last frame - timecode of first frame) * qfps rounded UP.

/ algorithm: / - get tc of 1st frame event in in_list / tc of out_list starts at zero. If allow_gap is FALSE we add an offset_tc / so out_list 0 coincides with tc of 1st frame in in_list. / loop: / - advance in_list until either we hit a frame event, or tc of NEXT event > out_tc / – if tc of next frame is <= out_tc, we continue / – update the state to current event / / - apply in_list state at out_tc, interpolating between last (current) in frame and next in frame / - advance out_tc by 1. / out_fps / - goto loop

/ inserting from scrap_file, we cannot interpolate frame numbers. So we just insert nearest frame

copy metadata; we will change PREV, NEXT and FPS

in pre-analysis, we will look at the audio frames, and instead of correcting the audio veloicity, we will attempt to slightly modify (scale) the frame timings such that the audio hits the precise seek point

in this mode we walk the event_list until we pass the output time, keeping track of state - frame and clip numbers, audio positions, param values, then insert everything at the output slot

  • we also look at the next frame to decide how to proceed
  • for normal clips and audio, we can interpolate between the two
  • for the scrap file, we cannot interpolate, so we insert whichever frame is nearest, unless we already inserted the last frame and the next frame would be dropped

values which we maintain: current init_events (cancelled by a deinit) current filter map (cancelled by a new filter_map) current deinits (cancelled by cancelling an init_event) current param changes (cancelled by another pchange for same fx / param or a deinit) audio seeks

events are added in the standard ordering, i.e filter_inits, param changes, filter map, frame, filter_deinits

update the state until we pass out_tc

now we have a choice: we can either insert this frame at out_tc with the current fx state, or with the state at out_tc the difference is: either we force insertion of this frame now, with the current filter state, or we wait until we pass the slot and insert with the filter inits at that time

force insertion by setting stop_tc to -1, thus all events will have a timecode

laud_tc is last frame in_tc, frame_event is last frame

if init_event is in list, discard it + this event

param changes just get inserted at whatever timcode, as long as their init_event isnt in the "to be added" list

replace current filter map

probably a marker; ignore

insert the state

INSERT A FRAME AT OUT_TC

interpolate frames if possible

now we insert the frame

insert the audio state

if there is still audio to be added, update the seek posn to out_tc laud_tc is last frame in_tc

the timecode of each audio frame is adjusted to the quantised time, and we update the seek position accordingly however, when playing back, any velocity change will come slightly later than when recorded; thus the player seek pos will be slightly off. To remedy this we can very slightly adjust the velocity at the prior frame, so that the seek is correct when arriving at the current audio frame

< audio was off, older lists didnt store the offset

find the prior audio frame for the track

what we will do here is insert an extra audio event at the previous out_frame. the seek will be calculated from old_val, and we will adjust the velocity so we hit the seek value at this frame adjust velocity by seek_delta / frame_duration

merge natracks with xatracks

frame insertion done

increase out_tc

end of the in_list

end of out_list

for completeness we should add closers for all active audio tracks, however this will be done in event_list_rectify() when necessary (or ideally, the player would add the closers and record the offsets)

Definition at line 456 of file resample.c.

Referenced by on_resample_vid_ok(), and render_to_clip().

◆ reorder_frames()

int reorder_frames ( int  rwidth,
int  rheight 
)

Definition at line 2106 of file resample.c.

◆ reorder_leave_back_set()

void reorder_leave_back_set ( boolean  val)

Definition at line 21 of file resample.c.

Referenced by create_new_pb_speed().

◆ resample_clipboard()

boolean resample_clipboard ( double  new_fps)

call this to resample clipboard video

Definition at line 2250 of file resample.c.