Segment Mixer — Stereo Composite from Multiple Sounds

Builds a new stereo composite from multiple selected Sounds. Every source is converted to mono and brought to one working sample rate; the left channel takes a segment from the beginning of each file, while the right channel takes a segment from the end, a fixed offset, or a random legal position. The file sequence can be repeated for multiple cycles.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 0.4.4 (2026) License: MIT License Repo: GitHub
Contents:

What this does

Segment Mixer creates two parallel mono montages from the same selected source set and then combines them into a stereo Sound:

LEFT: beginning segment of file 1 → beginning segment of file 2 → ... RIGHT: End / Offset / Random segment of file 1 → corresponding strategy for file 2 → ... repeat both sequences for Repeat_cycles → combine L + R to stereo → attenuate only if final peak exceeds 0.99
The original spatial image is not preserved. Every selected source is converted to mono before segment extraction. The output is a newly constructed stereo relationship between two different excerpts from each mono source.

Quick start

  1. Select at least two Sound objects.
  2. Run Segment_Mixer.praat.
  3. Choose Custom or one of the five named presets.
  4. Set segment duration, fade time, attenuation divisor and repeat cycles.
  5. Choose the right-channel strategy: End of file, Fixed offset, or Random.
  6. For Fixed offset, set the requested start position in seconds.
  7. Run the script. The result is a new stereo Sound.
Named presets overwrite segment duration, fade time, attenuation divisor, repeat cycles, right-channel strategy and fixed-offset value. They do not overwrite Draw_visualization or Play_result.

Source preparation

Selection and processing order

The script stores the selected Sounds in Praat's selected#("Sound") array and processes that array from index 1 to N. Each repeat cycle traverses the same array in the same order.

Mono working copies

Every selected Sound is copied. Sources with more than one channel are converted to mono; mono sources remain mono working copies.

Common sample rate

The working sample rate is the sampling frequency of the first Sound in the stored selection array:

targetSR = sampling frequency of monoSounds[1]

Every other working Sound whose sample rate differs is resampled to targetSR with Praat precision 50.

The script does not choose the highest sample rate. It uses the first working Sound's rate as the project rate.

Zero-based internal domains

After mono conversion/resampling, every private working Sound is shifted so its start time is 0. This makes all extraction coordinates literal 0…duration seconds even when an original Sound had a non-zero xmin.

Left and right extraction

For each file and each cycle, the effective extracted duration is:

extractDuration = min(Segment_duration_s, sourceDuration)

A source shorter than the requested segment therefore contributes its entire duration.

Left channel

leftStart = 0 leftEnd = extractDuration

The left channel always uses the beginning of each source.

Right strategy 1 — End of file

rightEnd = sourceDuration rightStart = sourceDuration - extractDuration

Because extractDuration never exceeds the file duration, this is the final legal segment of the source.

Right strategy 2 — Fixed offset

The requested offset is used when the full segment fits. Otherwise it is moved backward to the final legal start position:

rightStart = min(requestedOffset, sourceDuration - extractDuration) then clamp to >= 0

This means a fixed offset beyond the usable range does not shorten the segment; it becomes the last full legal segment instead.

Right strategy 3 — Random

usableWindow = sourceDuration - extractDuration if usableWindow > 0: rightStart ~ Uniform(0, usableWindow) else: rightStart = 0
There is no random-seed control. With Random strategy, a new right-channel position is drawn independently for each file occurrence in every cycle, so repeated runs can differ.

Attenuation & segment-edge fades

Attenuation divisor

Both left and right excerpts first receive:

segment = segment / Attenuation_divisor

The form requires only a positive divisor:

Effective fade duration

The public Fade_time_s must be positive and cannot exceed half the requested Segment_duration_s. A shorter source can still produce a shorter extracted segment, so the script applies a second per-segment clamp:

effectiveFade = min(Fade_time_s, extractDuration / 2)

The fade is linear, not cosine

Each extracted segment receives two multiplicative ramps:

fade-in gain = min(1, x / effectiveFade) fade-out gain = min(1, (xmax - x) / effectiveFade)

They are linear amplitude ramps. The segment begins at zero, reaches unity after the effective fade-in, and falls to zero over the final effective fade.

These are not crossfades. Adjacent segments do not overlap. Each segment fades down to zero and the next segment begins from zero at a hard concatenation boundary. The fades reduce discontinuity, but there is no overlapping equal-power or cosine crossfade.

Repeat cycles & ordering

The main renderer is nested:

for cycle = 1 ... Repeat_cycles: for file = 1 ... numberOfSelectedSounds: render one L segment render one R segment

Total segment positions per channel are therefore:

totalSegments = numberOfSelectedSounds × Repeat_cycles

The source-file order itself is not shuffled between cycles. The sequence repeats exactly; only Random right-channel extraction can choose different source positions on later cycles.

Five named presets + Custom

PresetSegmentFadeDivisorCyclesRight strategyFixed offset
Quick Collage150 ms30 ms1.24Random0.10 s
Slow Morph500 ms100 ms1.02End0.10 s
Random Scatter200 ms40 ms1.35Random0.10 s
Stereo Spread300 ms50 ms1.13End0.10 s
Dense Layers100 ms20 ms1.58Random0.10 s
Custom defaults250 ms50 ms1.13End0.10 s
“Dense Layers” is a historical preset name. The engine does not layer segments simultaneously; it concatenates more segment cycles sequentially.

Parameters & limits

ParameterDefaultExact behavior
PresetCustomCustom plus five named configurations.
Segment_duration_s0.25Positive requested segment duration. Shorter files contribute their whole duration.
Fade_time_s0.05Must be >0 and <= requested segment duration / 2; further clamped to half the actual extracted duration.
Attenuation_divisor1.1Any positive value. Divides every L/R segment before fades.
Repeat_cycles3Integer >=1.
Right_part_strategyEnd of fileEnd, Fixed offset, or Random.
Right_fixed_offset_s0.10Must be >=0 only when Fixed offset is active.
Draw_visualizationOnDraw L/R segment maps, stereo output waveform, file legend and summary.
Play_resultOnPlay the final stereo Sound.

Output duration

Left and right always use the same extractDuration for a given file occurrence, so their assembled durations match.

finalDuration = Repeat_cycles × sum over selected files of min(Segment_duration_s, sourceDuration[file])

This is the intended temporal construction, subject only to sample-grid rounding in extraction/concatenation.

v0.4 no longer prepends the 10 ms dummy-silence buffers used by v0.3. The delivered output begins with the first faded segment and is not artificially lengthened by a seed buffer.

Final peak safety

After the two complete mono sequences are combined into stereo, the script measures the Sinc70 absolute extremum across the result.

if stereoPeak > 0.99: Scale peak: 0.99 else: leave gain unchanged

This is an attenuate-only safety ceiling, not target normalization. A mix peaking at 0.40 remains at 0.40. A mix peaking above 0.99 is globally attenuated to the 0.99 target.

Because L and R are scaled together only when the combined stereo ceiling is exceeded, the requested Attenuation_divisor and the relative L/R level relationship are preserved unless safety attenuation is necessary.

Visualization

The v0.4.4 Picture view contains five functional regions:

  1. Left segment map: one colored bar per rendered segment occurrence; file identity determines the bar color.
  2. Right segment map: same file identity colors, with the actual chosen R strategy positions.
  3. Output stereo waveform: L and R are extracted and drawn explicitly as separate mono plots on one shared amplitude scale.
  4. File legend: color swatches with display-sanitized source names.
  5. Summary: preset, file/cycle/segment counts, right strategy, segment/fade settings, attenuation divisor, target sample rate, output duration and RMS.

Reading the segment maps

Color identifies the source file. Inside every colored segment bar, a neutral horizontal tick shows the normalized midpoint of the extracted source region:

0 = beginning of that source file 1 = end of that source file

The left map therefore places all ticks near the file starts; the right map reveals End, Offset, or the actual Random positions selected during rendering. Light vertical dividers mark cycle boundaries.

Waveform scale

The final L and R waveform panels share the same amplitude range, derived from the larger of their two sample peaks with 8% headroom. Their displayed levels are directly comparable.

Output behavior