Skip to content

Commit

Permalink
BOING!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMcClernan committed Jul 3, 2024
1 parent fed6f76 commit 3b11641
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Binary file added docs/Boing.wav
Binary file not shown.
28 changes: 28 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
<a id='saveData'></a>
</div>
<script>

function readFile() {
var inputData = document.getElementById('inputData');
var reader = new FileReader();
Expand All @@ -336,11 +337,38 @@
};
reader.readAsDataURL(inputData.files[0]);
};

function saveFile(txt, data) {
var saveData = document.getElementById('saveData');
saveData.setAttribute('download', txt);
saveData.setAttribute('href', data);
};

const context = new AudioContext();

function loadSample(url) {
return fetch(url)
.then(response => response.arrayBuffer())
.then(buffer => context.decodeAudioData(buffer));
}

function playSample(sample) {
const source = context.createBufferSource();
source.buffer = sample;
source.connect(context.destination);
source.start(0);
}
function playSampleRate(sample, rate) {
const source = context.createBufferSource();
source.buffer = sample;
source.playbackRate.value = rate;
source.connect(context.destination);
source.start(0);
}

loadSample('boing.wav')
.then(sample => playSample(sample));

</script>

</body>
Expand Down

0 comments on commit 3b11641

Please sign in to comment.