soiz1 commited on
Commit
ea2b8f1
·
1 Parent(s): fac064e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +48 -39
index.html CHANGED
@@ -415,10 +415,10 @@
415
  </div>
416
  <script type="module">
417
  // SoundTouchJSを正しくインポート
418
- import { SoundTouch, SimpleFilter, WebAudioBufferSource } from 'https://cdn.jsdelivr.net/npm/soundtouchjs@0.2.1/dist/soundtouch.min.js';
419
 
420
  // グローバルにsoundtouchを設定
421
- window.soundtouch = { SoundTouch, SimpleFilter, WebAudioBufferSource };
422
  document.addEventListener('DOMContentLoaded', function() {
423
  // 要素を取得
424
  const video = document.getElementById('video');
@@ -697,49 +697,58 @@
697
  });
698
  }
699
 
700
- function playAudio(file, startTime) {
701
- if (!audioBuffers[file]) return;
702
 
703
- if (audioSources[file]) {
704
- try {
705
- audioSources[file].stop();
706
- } catch(e) {
707
- console.log("Audio source already stopped");
708
- }
709
- }
710
-
711
- const source = audioContext.createBufferSource();
712
- source.buffer = audioBuffers[file];
713
 
714
- // PitchShifter を使用
715
- const pitchShifter = new window.soundtouch.PitchShifter(
716
- audioContext,
717
- audioBuffers[file],
718
- 4096
719
- );
720
- pitchShifter.tempo = currentPlaybackRate;
721
- pitchShifter.pitch = 1.0;
 
722
 
723
- // ボリュームコントロール
724
- const volumeSlider = document.querySelector(`.audio-slider[data-audio="${file}"]`);
725
- const volume = parseFloat(volumeSlider.value) * parseFloat(globalVolumeSlider.value);
726
- pitchShifter.connect(gainNodes[file]);
727
- gainNodes[file].gain.value = volume;
728
- gainNodes[file].connect(audioContext.destination);
 
 
 
729
 
730
- // 再生時間計算
731
- const duration = video.duration || videoDuration;
732
- const endTime = parseFloat(endTimeInput.value) || duration;
733
- const playStartTime = Math.max(startTime, parseFloat(startTimeInput.value) || 0);
734
- const playEndTime = Math.min(endTime, duration);
735
- const playDuration = playEndTime - playStartTime;
736
 
737
- if (playDuration > 0) {
738
- pitchShifter.start(startTime);
739
- }
 
 
 
 
 
 
 
740
 
741
- audioSources[file] = pitchShifter;
742
- }
743
 
744
  // 一時停止関数も修正
745
  function pauseMedia() {
 
415
  </div>
416
  <script type="module">
417
  // SoundTouchJSを正しくインポート
418
+ import { SoundTouch, SimpleFilter, PitchShifter } from 'https://cdn.jsdelivr.net/npm/soundtouchjs@0.3.0/dist/soundtouch.min.js';
419
 
420
  // グローバルにsoundtouchを設定
421
+ window.soundtouch = { SoundTouch, SimpleFilter, PitchShifter };
422
  document.addEventListener('DOMContentLoaded', function() {
423
  // 要素を取得
424
  const video = document.getElementById('video');
 
697
  });
698
  }
699
 
700
+ function playAudio(file, startTime) {
701
+ if (!audioBuffers[file]) return;
702
 
703
+ // 既存のソースがあれば停止
704
+ if (audioSources[file]) {
705
+ try {
706
+ audioSources[file].disconnect();
707
+ } catch(e) {
708
+ console.log("Audio source already stopped");
709
+ }
710
+ }
 
 
711
 
712
+ // PitchShifterを作成
713
+ const pitchShifter = new window.soundtouch.PitchShifter(
714
+ audioContext,
715
+ audioBuffers[file],
716
+ 4096 // バッファサイズ
717
+ );
718
+
719
+ pitchShifter.tempo = currentPlaybackRate;
720
+ pitchShifter.pitch = 1.0;
721
 
722
+ // ボリュームコントロール
723
+ const volumeSlider = document.querySelector(`.audio-slider[data-audio="${file}"]`);
724
+ const volume = parseFloat(volumeSlider.value) * parseFloat(globalVolumeSlider.value);
725
+
726
+ gainNodes[file] = audioContext.createGain();
727
+ gainNodes[file].gain.value = volume;
728
+
729
+ pitchShifter.connect(gainNodes[file]);
730
+ gainNodes[file].connect(audioContext.destination);
731
 
732
+ // 再生時間計算
733
+ const duration = video.duration || videoDuration;
734
+ const endTime = parseFloat(endTimeInput.value) || duration;
735
+ const playStartTime = Math.max(startTime, parseFloat(startTimeInput.value) || 0);
736
+ const playEndTime = Math.min(endTime, duration);
737
+ const playDuration = playEndTime - playStartTime;
738
 
739
+ if (playDuration > 0) {
740
+ pitchShifter.start(playStartTime);
741
+
742
+ // 終了時間に達したら停止
743
+ if (!loopCheckbox.checked) {
744
+ setTimeout(() => {
745
+ pitchShifter.disconnect();
746
+ }, (playEndTime - playStartTime) * 1000);
747
+ }
748
+ }
749
 
750
+ audioSources[file] = pitchShifter;
751
+ }
752
 
753
  // 一時停止関数も修正
754
  function pauseMedia() {