forked from sharpie7/circuitjs1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class AudioInputElm extends RailElm { | |
|
||
static int lastSamplingRate; | ||
|
||
// cache to preserve audio data when doing cut/paste, or undo/redo | ||
static int fileNumCounter = 1; | ||
static HashMap<Integer, AudioFileEntry> audioFileMap = new HashMap<Integer, AudioFileEntry>(); | ||
|
||
|
@@ -96,7 +97,7 @@ String getRailText() { | |
return fileName == null ? "No file" : fileName; | ||
} | ||
|
||
void setSampleRate(int sr) { | ||
void setSamplingRate(int sr) { | ||
samplingRate = sr; | ||
} | ||
|
||
|
@@ -129,7 +130,6 @@ public EditInfo getEditInfo(int n) { | |
file.addChangeHandler(new ChangeHandler() { | ||
public void onChange(ChangeEvent event) { | ||
fileName = file.getFilename().replaceAll("^.*\\\\", "").replaceAll("\\.[^.]*$", ""); | ||
// AudioInputElm.fetchAudio(thisElm, file.getFilename()); | ||
AudioInputElm.fetchLoadFileData(thisElm, file.getElement()); | ||
} | ||
}); | ||
|
@@ -149,31 +149,11 @@ public void setEditValue(int n, EditInfo ei) { | |
startPosition = ei.value; | ||
} | ||
|
||
static native boolean oldfetchAudio(AudioInputElm elm, String file) /*-{ | ||
var context = new (window.AudioContext || window.webkitAudioContext)(); | ||
var url = file; | ||
var request = new XMLHttpRequest(); | ||
request.open("GET", url, true); | ||
request.responseType = "arraybuffer"; | ||
var loader = this; | ||
request.onload = function() { | ||
// Asynchronously decode the audio file data in request.response | ||
var audioData = request.response; | ||
context.decodeAudioData(audioData, function(buffer) { | ||
var data = buffer.getChannelData(0); | ||
[email protected]::gotAudioData(*)(data); | ||
}, | ||
function(e){ console.log("Error with decoding audio data" + e.err); }); | ||
} | ||
request.send(); | ||
}-*/; | ||
|
||
|
||
static native String fetchLoadFileData(AudioInputElm elm, Element element) /*-{ | ||
var oFiles = element.files; | ||
// fetch audio data for a selected file | ||
static native String fetchLoadFileData(AudioInputElm elm, Element uploadElement) /*-{ | ||
var oFiles = uploadElement.files; | ||
var context = new (window.AudioContext || window.webkitAudioContext)(); | ||
[email protected]::setSampleRate(I)(context.sampleRate); | ||
[email protected]::setSamplingRate(I)(context.sampleRate); | ||
if (oFiles.length >= 1) { | ||
var reader = new FileReader(); | ||
reader.onload = function(e) { | ||
|
@@ -188,16 +168,6 @@ static native String fetchLoadFileData(AudioInputElm elm, Element element) /*-{ | |
} | ||
}-*/; | ||
|
||
static native boolean fetchAudio(AudioInputElm elm, String audioData) /*-{ | ||
var context = new (window.AudioContext || window.webkitAudioContext)(); | ||
var url = file; | ||
context.decodeAudioData(audioData, function(buffer) { | ||
var data = buffer.getChannelData(0); | ||
[email protected]::gotAudioData(*)(data); | ||
}, | ||
function(e){ console.log("Error with decoding audio data" + e.err); }); | ||
}-*/; | ||
|
||
void gotAudioData(JsArrayNumber d) { | ||
data = d; | ||
lastSamplingRate = samplingRate; | ||
|