LiVES  3.2.0
Data Structures | Macros | Functions | Variables
resample.h File Reference

Go to the source code of this file.

Data Structures

struct  _resaudw
 resample audio window More...
 

Macros

#define RESIZE_ALL_NEEDS_CONVERT   0
 
#define LETTERBOX_NEEDS_COMPOSITE   1
 
#define LETTERBOX_NEEDS_CONVERT   1
 
#define SKJUMP_THRESH_RATIO   1.025
 
#define SKJUMP_THRESH_SECS   0.25
 

Functions

ticks_t q_gint64 (ticks_t in, double fps)
 
ticks_t q_gint64_floor (ticks_t in, double fps)
 
ticks_t q_dbl (double in, double fps)
 
void reorder_leave_back_set (boolean val)
 
size_t quant_asamps (double seek, int arate)
 convert seek time to an integer number of samples More...
 
double quant_aseek (double seek, int arate)
 convert seek time (secs) to an (almost) integer number of samples More...
 
off_t quant_abytes (double seek, int arate, int achans, int asampsize)
 
weed_plant_t * quantise_events (weed_plant_t *in_list, double new_fps, boolean allow_gap) WARN_UNUSED
 quantise frame events for a single clip More...
 
int count_resampled_frames (int in_frames, double orig_fps, double resampled_fps)
 
_resaudwcreate_resaudw (short type, render_details *, LiVESWidget *top_vbox)
 resample audio window More...
 
void on_change_speed_activate (LiVESMenuItem *, livespointer)
 
void on_change_speed_ok_clicked (LiVESButton *, livespointer)
 
boolean auto_resample_resize (int width, int height, double fps, int fps_num, int fps_denom, int arate, int asigned, boolean swap_endian)
 
int reorder_frames (int rwidth, int rheight)
 
int deorder_frames (int old_framecount, 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...
 

Variables

_resaudwresaudw
 

Macro Definition Documentation

◆ LETTERBOX_NEEDS_COMPOSITE

#define LETTERBOX_NEEDS_COMPOSITE   1

Definition at line 14 of file resample.h.

◆ LETTERBOX_NEEDS_CONVERT

#define LETTERBOX_NEEDS_CONVERT   1

Definition at line 15 of file resample.h.

◆ RESIZE_ALL_NEEDS_CONVERT

#define RESIZE_ALL_NEEDS_CONVERT   0

Definition at line 13 of file resample.h.

◆ SKJUMP_THRESH_RATIO

#define SKJUMP_THRESH_RATIO   1.025

Definition at line 50 of file resample.h.

◆ SKJUMP_THRESH_SECS

#define SKJUMP_THRESH_SECS   0.25

Definition at line 51 of file resample.h.

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()

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

Definition at line 72 of file resample.c.

Referenced by resample_clipboard().

◆ 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_framecount,
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 *  ,
livespointer   
)

Definition at line 2017 of file resample.c.

◆ on_change_speed_ok_clicked()

void on_change_speed_ok_clicked ( LiVESButton *  ,
livespointer   
)

Definition at line 2025 of file resample.c.

Referenced by create_new_pb_speed(), and on_redo_activate().

◆ q_dbl()

ticks_t q_dbl ( double  in,
double  fps 
)

◆ q_gint64()

ticks_t q_gint64 ( ticks_t  in,
double  fps 
)

◆ q_gint64_floor()

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()

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

Definition at line 66 of file resample.c.

◆ quant_asamps()

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()

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 frame events for a single clip

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.

Variable Documentation

◆ resaudw

_resaudw* resaudw