Function ATrim(Clip A, Float T1, Float T2) {
# Function to trim based on Audio times
#
# A  : Input clip, must have Audio, video optional
# T1 : Start time in seconds
# T2 : End time in seconds. Zero represents the end of the clip.
#      Negative values represent a duration

# Examples
# Cut 1.2 seconds starting at 1.4 seconds
#    ATrim(1.4, 2.6)
# or ATrim(1.4, -1.2)
#
# Cut from 10.5 seconds to the end
#      ATrim(10.5, 0)

# Written by IanB (http://forum.doom9.org/showthread.php?p=1065329)

  Assert(HasAudio(A), "ATrim: clip must have audio")
  Assert(T1 >= 0.0, "ATrim: starting time must be >= 0")

# Interpret T2!
  T2 = (T2 == 0.0) ? AudioLengthF(A)/AudioRate(A) : T2 # 0 -> End
  T2 = (T2 < 0.0) ? T1-T2 : T2 # -ve -> delta

  Assert(T2 >= T1, "ATrim: ending time must be >= starting time")

# Get a framerate
  Fr=HasVideo(A) ? FrameRate(A) : 100.0
  N=Ceil(Fr*T2)

# Make sure clip has video to Trim
  HasVideo(A) ? A : AudioDub(BlankCLip(N, 16, 16, FPS=100.0), A)

  Assert(N <= FrameCount(), "ATrim: ending time must be <= clip length")

# Chop off end exactly
  F2 = Ceil(T2 * Fr)
  DelayAudio(F2/Fr - T2) # align audio end with frames
  Trim(0, F2, False) # Do not pad audio

# Chop off start exactly
  F1 = Floor(T1 * Fr)
  DelayAudio(F1/Fr - T1 + T2 - F2/Fr) # alight audio start with frames
  Trim(F1, 0, False) # Do not pad audio

  Return HasVideo(A) ? Last : KillVideo(Last)
}