Просмотр исходного кода

Обновить 'docs/file.md'

u23-27dybenko 2 недель назад
Родитель
Сommit
a20180f0c8
1 измененных файлов с 24 добавлено и 7 удалено
  1. 24 7
      docs/file.md

+ 24 - 7
docs/file.md

@@ -183,7 +183,7 @@
         <input type="range" id="freqSlider" min="1" max="10" value="3">
       </div>
       <div class="slider-box">
-        <label>Амплитуда: <span id="ampVal">25</span> px</label>
+                <label>Амплитуда: <span id="ampVal">25</span> px · 🔊 <span id="ampVol">21</span>%</label>
         <input type="range" id="ampSlider" min="5" max="40" value="25">
       </div>
       <button class="btn green" id="btnPush" type="button">Толкнуть</button>
@@ -415,7 +415,7 @@ document.getElementById('btnWhat').addEventListener('click', function(){
 
   // 🔊 Обновление звука при движении бегунка частоты:
   // 1 Гц → 440 Гц, 10 Гц → 4400 Гц (линейно: 440 × freq)
-  function playFreqTone(){
+    function playFreqTone(){
     if(!soundOn) return;
     ensureAudio();
     if(!audioCtx) return;
@@ -425,14 +425,15 @@ document.getElementById('btnWhat').addEventListener('click', function(){
       freqTone = null;
     }
     var soundFreq = 440 * freq;
+    var vol = ampToVolume();          // 🔊 громкость по амплитуде
     var o = audioCtx.createOscillator();
     var g = audioCtx.createGain();
     o.type = 'sine';
     o.frequency.value = soundFreq;
     var now = audioCtx.currentTime;
     g.gain.setValueAtTime(0, now);
-    g.gain.linearRampToValueAtTime(0.12, now + 0.02);
-    g.gain.setValueAtTime(0.12, now + 0.20);
+    g.gain.linearRampToValueAtTime(vol, now + 0.02);
+    g.gain.setValueAtTime(vol, now + 0.20);
     g.gain.exponentialRampToValueAtTime(0.001, now + 0.35);
     o.connect(g); g.connect(audioCtx.destination);
     o.start(now);
@@ -447,17 +448,33 @@ document.getElementById('btnWhat').addEventListener('click', function(){
     playFreqTone();
   });
 
+   // 🔊 Громкость зависит от амплитуды: 5 px → 0.02, 40 px → 0.35
+  function ampToVolume(){
+    var minA = 5, maxA = 40;
+    var minV = 0.02, maxV = 0.35;
+    var k = (amp - minA) / (maxA - minA);
+    if(k < 0) k = 0;
+    if(k > 1) k = 1;
+    return minV + k * (maxV - minV);
+  }
+
   document.getElementById('ampSlider').addEventListener('input', function(e){
     amp = +e.target.value;
     document.getElementById('ampVal').textContent = amp;
+    document.getElementById('ampVol').textContent = Math.round(ampToVolume() / 0.35 * 100);
+    // 🔊 короткий пробный тон с новой громкостью
+    if(soundOn){
+      ensureAudio();
+      beep(440 * freq, 0.25, 'sine', ampToVolume());
+    }
   });
 
-  document.getElementById('btnPush').addEventListener('click', function(){
+    document.getElementById('btnPush').addEventListener('click', function(){
     pushTime = t; pushes++;
     document.getElementById('scene2Hint').textContent = 'Толчков: ' + pushes + ' / 3';
 
-    // 🔊 Звук толчка тоже привязан к бегунку: 440 × freq
-    beep(440 * freq, 0.35, 'sine', 0.18);
+    // 🔊 Частота — по бегунку частоты, громкость — по бегунку амплитуды
+    beep(440 * freq, 0.35, 'sine', ampToVolume());
 
     if(pushes >= 3){
       document.getElementById('btnNext2').disabled = false;