Переглянути джерело

Began work on the audio framework

tags/v0.1.0
Fen Dweller 7 роки тому
коміт
1f5d09247c
3 змінених файлів з 84 додано та 0 видалено
  1. +49
    -0
      audio.js
  2. +20
    -0
      satiate.html
  3. +15
    -0
      satiate.js

+ 49
- 0
audio.js Переглянути файл

@@ -0,0 +1,49 @@
let audioDict = {};

// play some sound

function playAudio(name) {
if (audioDict[name] == undefined) {
console.log(name + " is not loaded yet, dingus");
return;
}

let src = audioContext.createBufferSource();

src.buffer = audioDict[name];

src.connect(audioContext.destination);

src.start(0);
}

// asynchronously load an audio file

function loadAudio(name) {
let xhr = new XMLHttpRequest();

xhr.open("GET", audioBaseUrl + name, true);

console.log(audioBaseUrl + name);
xhr.responseType = "arraybuffer";
console.log("a");

xhr.onload = function() {
let data = xhr.response;
console.log("FDSEW");

audioContext.decodeAudioData(data, function(buffer) {
console.log("SADFDS");
audioDict[name] = buffer;
}, function(e){ console.log("Error with decoding audio data" + e.err);});

}

xhr.send();
}

function initAudio() {
audioContext = new (window.AudioContext || window.webkitAudioContext)();

console.log(audioContext);
}

+ 20
- 0
satiate.html Переглянути файл

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Satiate</title>
<link rel="stylesheet" href="satiate.css">
<script src="audio.js"></script>
<script src="satiate.js"></script>
<meta name="theme-color" content="#000000" />
<meta name="description" content="A game where you get eaten" />
<meta property="og:title" content="Satiate" />
<meta property="og:description" content="A game where you get eate" />
<meta property="og:image" content="https://chemicalcrux.org/satiate.png" />
<link rel="shortcut icon" href="https://chemicalcrux.org/favicon.ico" type="image/x-icon" />
</head>

<body>
<div>hewwo?</div>
</body>

+ 15
- 0
satiate.js Переглянути файл

@@ -0,0 +1,15 @@
"use strict"

let audioBaseUrl = "http://localhost:8000/media/audio/";

let audioContext;

// setup the game

function init() {
initAudio();


}

document.addEventListener("load", init);

Завантаження…
Відмінити
Зберегти