Skip to content

Add feature to pad or trim audio sources#22

Open
Curucail wants to merge 1 commit intoaudiolabs:masterfrom
Curucail:pad_trim_audio_sources
Open

Add feature to pad or trim audio sources#22
Curucail wants to merge 1 commit intoaudiolabs:masterfrom
Curucail:pad_trim_audio_sources

Conversation

@Curucail
Copy link

@Curucail Curucail commented Feb 14, 2026

Add support for padding or trimming of audio source clips (ts-source elements), allowing more flexible playback alignment as propsed in #21 .

Changes

Audio track timing and scheduling:

  • Added a new trackTiming array to store timing metadata (trims, pads, effective duration) for each track, using the new calculateTrackTiming method to parse optional start-offset-ms and end-offset-ms attributes from source elements. [1] [2] [3]
  • Updated the startAudio method to use the timing metadata for each track when scheduling playback, ensuring correct alignment with trims, pads, and offsets. This includes calculating when to start each track, how much to play, and handling edge cases where the position is outside the effective audio region.
  • Modified the findLongest method to use the effective duration from trackTiming if available, ensuring accurate determination of the longest track for synchronization.

Audio source management and robustness:

  • Improved the stopAudio method to safely stop only initialized audio sources, preventing errors if a source is missing.
  • Refactored ramping variable initialization and clarified comments in startAudio for better readability and maintainability.

Usage Example

You can now add optional start and end offsets on each ts-source using the attributes start-offset-ms and end-offset-ms (values in milliseconds). Positive values trim audio (cut from start/end), while negative values add padding (silence before/after), so you can align tracks without re-exporting files. The player automatically includes these offsets when calculating the overall multitrack duration.

Example:

<ts-track title="Guitar">
  <ts-source src="guitar.wav" start-offset-ms="-120" end-offset-ms="250"></ts-source>
</ts-track>

This starts the guitar 120 ms later (padded at start) and cuts 250 ms from its end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments