Browse Source

nearly done adding sample rate detection but ran out of time before going to pub

dds
Matt Bradshaw 6 years ago
parent
commit
666fbaea32
2 changed files with 25 additions and 3 deletions
  1. +9
    -2
      extras/wav2sketch/wav2sketch.html
  2. +16
    -1
      extras/wav2sketch/wav2sketch.js

+ 9
- 2
extras/wav2sketch/wav2sketch.html View File

@@ -6,9 +6,16 @@
<h1>Teensy Audio Wav2Sketch Utility</h1>
<p>Upload an audio file to convert it into Teensy audio format.</p>
<form>
<label>Sample rate</label>
<label>Input sample rate</label>
<select>
<option>Auto</option>
<option>Auto-detect</option>
<option>44100</option>
<option>22050</option>
<option>11025</option>
</select><br/><br/>
<label>Output sample rate</label>
<select>
<option>Use input sample rate</option>
<option>44100</option>
<option>22050</option>
<option>11025</option>

+ 16
- 1
extras/wav2sketch/wav2sketch.js View File

@@ -19,7 +19,22 @@ function readFile() {
}

function processFile(file, fileName) {
var context = new OfflineAudioContext(1,100*44100,44100); // 100 seconds for now
// determine sample rate
// ideas borrowed from https://github.com/ffdead/wav.js
var sampleRate = 0;
try {
var sampleRateBytes = new Uint8Array(file, 24, 4);
for(var i = 0; i < sampleRateBytes.length; i ++) {
sampleRate |= a[i] << (i*8);
}
if([44100, 22050, 11025].indexOf(sampleRate) == -1) {
sampleRate = 44100;
}
} catch(err) {
sampleRate = 44100;
}

var context = new OfflineAudioContext(1, 100*sampleRate, sampleRate); // 100 seconds for now
context.decodeAudioData(file, function(buffer) {
console.log(buffer.sampleRate);
var monoData = [];

Loading…
Cancel
Save