Plugin Directory

Changeset 3693876


Ignore:
Timestamp:
09/13/2026 03:49:32 PM (2 months ago)
Author:
smorenno
Message:

Fix: Clicks and track desynchronization during playback (v1.0.1)

Location:
studiolite/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • studiolite/trunk/assets/studio-lite.js

    r3639744 r3693876  
    11// ============================================================
    2 // Studio Lite v1.0 — WordPress Plugin (Free)
     2// Studio Lite v1.0.1 — WordPress Plugin (Free)
    33// © 2025 Bloco do Moreno — Todos os direitos reservados.
    44// contato: oficina@blocodomoreno.com.br
    … …  
    4141  let soloTrackId     = null;
    4242  let isSeeking       = false;
    43 
     43  let playAnchorCtx   = 0;   // audioCtx.currentTime no instante do start agendado
     44  let playAnchorPos   = 0;   // posição (s) correspondente a esse instante
     45
     46  // Velocidade fixa nesta versão — sem controle de tempo na UI.
     47  // Sempre que PLAYBACK_SPEED === 1.0, usamos o motor direto (sample-accurate,
     48  // sem ScriptProcessor) em vez do pipeline SoundTouch, evitando cliques e
     49  // dessincronismo entre trilhas.
     50  const PLAYBACK_SPEED = 1.0;
    4451
    4552  function initCtx() {
    … …  
    113120  }
    114121
     122  // ── Motor direto (sem time-stretch) ────────────────────────
     123  // Agenda todas as trilhas para iniciar no MESMO instante do relógio do
     124  // AudioContext (sample-accurate). Isso elimina o dessincronismo entre
     125  // trilhas e os cliques causados pelo ScriptProcessorNode, que dependiam
     126  // da thread principal do navegador para cada trilha individualmente.
     127  function playDirect(offsetSeconds) {
     128    const LOOKAHEAD = 0.06; // margem p/ o navegador agendar sem estalos
     129    const startAt   = audioCtx.currentTime + LOOKAHEAD;
     130    playAnchorCtx = startAt;
     131    playAnchorPos = offsetSeconds;
     132
     133    tracks.forEach(function (t) {
     134      if (!t.buffer) return;
     135      const source = audioCtx.createBufferSource();
     136      source.buffer = t.buffer;
     137      const gain = audioCtx.createGain();
     138      gain.gain.value = soloTrackId ? (t.id === soloTrackId ? 1 : 0) : (t.muted ? 0 : 1);
     139      source.connect(gain);
     140      gain.connect(audioCtx.destination);
     141      source.start(startAt, Math.min(offsetSeconds, t.buffer.duration));
     142      t.gain   = gain;
     143      t.source = source;
     144    });
     145  }
     146
     147  function currentDirectPosition() {
     148    return Math.max(0, audioCtx.currentTime - playAnchorCtx) + playAnchorPos;
     149  }
     150
    115151  // ── Carregar arquivos ─────────────────────────────────────
    116152  btnLoad.addEventListener('click', function () { fileInput.click(); });
    … …  
    235271    if (!isPlaying || isPaused) return;
    236272    isPaused    = true;
    237     pauseOffset = Math.min(stPosition, totalDuration);
     273    pauseOffset = Math.min(PLAYBACK_SPEED === 1.0 ? currentDirectPosition() : stPosition, totalDuration);
    238274    tracks.forEach(function (t) { try { if (t.source) t.source.stop(); } catch (_) {} });
    239275    teardownStNodes();
    … …  
    272308    tempoTot.textContent = formatTime(totalDuration);
    273309
    274     // Sempre modo SoundTouch — fluido em qualquer velocidade
    275     stPosition = pauseOffset;
    276     tracks.forEach(function (t, i) {
    277       if (!t.buffer) return;
    278       const offsetSamples = Math.floor(pauseOffset * t.buffer.sampleRate);
    279       const node = buildStNode(t, offsetSamples, 1.0, i === 0);
    280       node.gain.gain.value = soloTrackId ? (t.id === soloTrackId ? 1 : 0) : (t.muted ? 0 : 1);
    281       t.gain   = node.gain;
    282       t.source = null;
    283       stNodes.push(node);
    284     });
     310    if (PLAYBACK_SPEED === 1.0) {
     311      stPosition = pauseOffset;
     312      playDirect(pauseOffset);
     313    } else {
     314      // Modo SoundTouch — reservado para troca de velocidade (não usado nesta versão)
     315      stPosition = pauseOffset;
     316      tracks.forEach(function (t, i) {
     317        if (!t.buffer) return;
     318        const offsetSamples = Math.floor(pauseOffset * t.buffer.sampleRate);
     319        const node = buildStNode(t, offsetSamples, PLAYBACK_SPEED, i === 0);
     320        node.gain.gain.value = soloTrackId ? (t.id === soloTrackId ? 1 : 0) : (t.muted ? 0 : 1);
     321        t.gain   = node.gain;
     322        t.source = null;
     323        stNodes.push(node);
     324      });
     325    }
    285326
    286327    clearInterval(progressInterval);
    287328    progressInterval = setInterval(function () {
     329      if (PLAYBACK_SPEED === 1.0) stPosition = currentDirectPosition();
    288330      const cur = Math.min(stPosition, totalDuration);
    289331      const pct = totalDuration > 0 ? Math.min((cur / totalDuration) * 100, 100) : 0;
    … …  
    320362      teardownStNodes();
    321363      stPosition = newTime;
    322       tracks.forEach(function (t, i) {
    323         if (!t.buffer) return;
    324         const offsetSamples = Math.floor(newTime * t.buffer.sampleRate);
    325         const node = buildStNode(t, offsetSamples, 1.0, i === 0);
    326         node.gain.gain.value = soloTrackId ? (t.id === soloTrackId ? 1 : 0) : (t.muted ? 0 : 1);
    327         t.gain   = node.gain;
    328         t.source = null;
    329         stNodes.push(node);
    330       });
     364      if (PLAYBACK_SPEED === 1.0) {
     365        playDirect(newTime);
     366      } else {
     367        tracks.forEach(function (t, i) {
     368          if (!t.buffer) return;
     369          const offsetSamples = Math.floor(newTime * t.buffer.sampleRate);
     370          const node = buildStNode(t, offsetSamples, PLAYBACK_SPEED, i === 0);
     371          node.gain.gain.value = soloTrackId ? (t.id === soloTrackId ? 1 : 0) : (t.muted ? 0 : 1);
     372          t.gain   = node.gain;
     373          t.source = null;
     374          stNodes.push(node);
     375        });
     376      }
    331377    } else {
    332378      pauseOffset = newTime;
  • studiolite/trunk/readme.txt

    r3647929 r3693876  
    44Requires at least: 5.0
    55Tested up to:      7.0.4
    6 Stable tag:        1.0.0
     6Stable tag:        1.0.1
    77Requires PHP:      7.4
    88License:           GPL-2.0+
    … …  
    7474== Changelog ==
    7575
     76= 1.0.1 =
     77* Corrigido: cliques e dessincronismo entre trilhas durante a reprodução simultânea de múltiplos arquivos de áudio
     78
    7679= 1.0.0 =
    7780* Initial release
    … …  
    7982== Upgrade Notice ==
    8083
     84= 1.0.1 =
     85Corrige um bug de áudio (cliques/dessincronia entre trilhas). Atualização recomendada para todos os usuários.
     86
    8187= 1.0.0 =
    8288Initial release of Studiolite.
  • studiolite/trunk/studio-lite.php

    r3639744 r3693876  
    44 * Plugin URI:        https://blocodomoreno.com.br/studiolite
    55 * Description:       Multitrack audio mixer for WordPress. Load tracks, adjust volumes, use Mute — all in the browser, no installation needed.
    6  * Version:           1.0.0
     6 * Version:           1.0.1
    77 * Author:            Bloco do Moreno
    88 * Author URI:        https://blocodomoreno.com.br
    … …  
    1515if ( ! defined( 'ABSPATH' ) ) exit;
    1616
    17 define( 'STUDIO_LITE_VERSION', '1.0.0' );
     17define( 'STUDIO_LITE_VERSION', '1.0.1' );
    1818define( 'STUDIO_LITE_URL',     plugin_dir_url( __FILE__ ) );
    1919define( 'STUDIO_LITE_PATH',    plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.