handled audio playback with aurora library
This commit is contained in:
parent
9b5198a6ce
commit
22323b504f
@ -59,21 +59,13 @@ void M::Audio::h_requestFrames(const W::Event& ev)
|
|||||||
evc->insert(u"result", new W::Uint64(1));
|
evc->insert(u"result", new W::Uint64(1));
|
||||||
} else {
|
} else {
|
||||||
evc->insert(u"result", new W::Uint64(0));
|
evc->insert(u"result", new W::Uint64(0));
|
||||||
uint64_t start = 0;
|
W::Vector* vframes = new W::Vector();
|
||||||
uint64_t size = 0;
|
|
||||||
bool first = true;
|
|
||||||
for (int i = 0; i < amount; ++i) {
|
for (int i = 0; i < amount; ++i) {
|
||||||
const std::pair<uint64_t, uint64_t>& pair = frames[index + i];
|
const std::pair<uint64_t, uint64_t>& pair = frames[index + i]; //TODO optimize?
|
||||||
if (first) {
|
vframes->push(file->slice(pair.first, pair.second));
|
||||||
start = pair.first;
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
size += pair.second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
evc->insert(u"data", file->slice(start, size));
|
evc->insert(u"frames", vframes);
|
||||||
evc->insert(u"amount", new W::Uint64(amount));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response(evc, W::Address{u"responseFrames"}, ev);
|
response(evc, W::Address{u"responseFrames"}, ev);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var File = require("./file");
|
var File = require("./file");
|
||||||
var Vocabulary = require("../../wType/vocabulary");
|
var Vocabulary = require("../../wType/vocabulary");
|
||||||
|
var Vector = require("../../wType/vector");
|
||||||
var Uint64 = require("../../wType/uint64");
|
var Uint64 = require("../../wType/uint64");
|
||||||
|
|
||||||
var Audio = File.inherit({
|
var Audio = File.inherit({
|
||||||
@ -12,10 +13,15 @@ var Audio = File.inherit({
|
|||||||
this._loadedFrames = 0;
|
this._loadedFrames = 0;
|
||||||
this._totalFrames = 0;
|
this._totalFrames = 0;
|
||||||
this._waitingForFrames = false;
|
this._waitingForFrames = false;
|
||||||
this._portions = [];
|
this._frames = new Vector();
|
||||||
|
|
||||||
this.addHandler("responseFrames");
|
this.addHandler("responseFrames");
|
||||||
},
|
},
|
||||||
|
destructor: function() {
|
||||||
|
this._frames.destructor();
|
||||||
|
|
||||||
|
File.fn.destructor.call(this);
|
||||||
|
},
|
||||||
hasMore: function() {
|
hasMore: function() {
|
||||||
return this._totalFrames > this._loadedFrames;
|
return this._totalFrames > this._loadedFrames;
|
||||||
},
|
},
|
||||||
@ -37,12 +43,25 @@ var Audio = File.inherit({
|
|||||||
|
|
||||||
var success = data.at("result").valueOf();
|
var success = data.at("result").valueOf();
|
||||||
if (success === 0) {
|
if (success === 0) {
|
||||||
var amount = data.at("amount").valueOf();
|
var frames = data.at("frames");
|
||||||
var blob = data.at("data").clone();
|
var amount = frames.length();
|
||||||
|
var buffer = new ArrayBuffer(0);
|
||||||
|
|
||||||
|
for (var i = 0; i < amount; ++i) {
|
||||||
|
var blob = frames.at(i).clone();
|
||||||
|
this._frames.push(blob);
|
||||||
|
var frame = blob.valueOf();
|
||||||
|
|
||||||
|
var newArr = new Uint8Array(buffer.byteLength + frame.byteLength);
|
||||||
|
newArr.set(new Uint8Array(buffer), 0);
|
||||||
|
newArr.set(new Uint8Array(frame), buffer.byteLength);
|
||||||
|
buffer = newArr.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this._loadedFrames += amount;
|
this._loadedFrames += amount;
|
||||||
this._waitingForFrames = false;
|
this._waitingForFrames = false;
|
||||||
this._portions.push(blob);
|
this.trigger("newFrames", buffer);
|
||||||
this.trigger("newFrames", blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -12,6 +12,12 @@ var Audio = require("./file/audio");
|
|||||||
var Enum = require("../utils/enum");
|
var Enum = require("../utils/enum");
|
||||||
var StateMachine = require("../utils/stateMachine");
|
var StateMachine = require("../utils/stateMachine");
|
||||||
|
|
||||||
|
var Source = AV.EventEmitter.extend(function() {
|
||||||
|
this.prototype.start = function(){}
|
||||||
|
this.prototype.pause = function(){}
|
||||||
|
this.prototype.reset = function(){}
|
||||||
|
});
|
||||||
|
|
||||||
var Player = Controller.inherit({
|
var Player = Controller.inherit({
|
||||||
className: "Player",
|
className: "Player",
|
||||||
constructor: function(addr) {
|
constructor: function(addr) {
|
||||||
@ -21,11 +27,11 @@ var Player = Controller.inherit({
|
|||||||
this.views = Object.create(null);
|
this.views = Object.create(null);
|
||||||
this.mode = PlayerMode.straight.playback;
|
this.mode = PlayerMode.straight.playback;
|
||||||
this._audio = null;
|
this._audio = null;
|
||||||
this._sound = new window.Audio();
|
this._source = new Source();
|
||||||
this._ctx = new AudioContext();
|
this._asset = new AV.Asset(this._source);
|
||||||
this._currentTime = 0;
|
this._player = new AV.Player(this._asset);
|
||||||
|
this._player.play();
|
||||||
this._createStateMachine();
|
this._createStateMachine();
|
||||||
this._proxySchedule = this._schedule.bind(this);
|
|
||||||
|
|
||||||
this.addHandler("get");
|
this.addHandler("get");
|
||||||
this.addHandler("viewsChange");
|
this.addHandler("viewsChange");
|
||||||
@ -34,8 +40,7 @@ var Player = Controller.inherit({
|
|||||||
},
|
},
|
||||||
destructor: function() {
|
destructor: function() {
|
||||||
this._fsm.destructor();
|
this._fsm.destructor();
|
||||||
this._sound.pause();
|
this._player.stop();
|
||||||
this._ctx.close();
|
|
||||||
|
|
||||||
Controller.fn.destructor.call(this);
|
Controller.fn.destructor.call(this);
|
||||||
},
|
},
|
||||||
@ -140,7 +145,7 @@ var Player = Controller.inherit({
|
|||||||
this.trigger("data");
|
this.trigger("data");
|
||||||
},
|
},
|
||||||
_h_pause: function(ev) {
|
_h_pause: function(ev) {
|
||||||
this._fsm.manipulation("plause");
|
this._fsm.manipulation("pause");
|
||||||
},
|
},
|
||||||
_h_play: function(ev) {
|
_h_play: function(ev) {
|
||||||
this._fsm.manipulation("play");
|
this._fsm.manipulation("play");
|
||||||
@ -164,7 +169,9 @@ var Player = Controller.inherit({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_onAudioNewFrames: function(frames) {
|
_onAudioNewFrames: function(frames) {
|
||||||
this._ctx.decodeAudioData(frames.valueOf(), this._proxySchedule);
|
var data = new Uint8Array(frames);
|
||||||
|
this._source.emit("data", new AV.Buffer(data));
|
||||||
|
|
||||||
this._fsm.manipulation("newFrames");
|
this._fsm.manipulation("newFrames");
|
||||||
if (this._audio.hasMore()) {
|
if (this._audio.hasMore()) {
|
||||||
this._audio.requestMore();
|
this._audio.requestMore();
|
||||||
@ -218,24 +225,24 @@ var Player = Controller.inherit({
|
|||||||
case "paused":
|
case "paused":
|
||||||
switch (e.oldState) {
|
switch (e.oldState) {
|
||||||
case "playing":
|
case "playing":
|
||||||
this._sound.pause();
|
this._player.pause();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "pausedAllLoaded":
|
case "pausedAllLoaded":
|
||||||
switch (e.oldState) {
|
switch (e.oldState) {
|
||||||
case "playingAllLoaded":
|
case "playingAllLoaded":
|
||||||
this._sound.pause();
|
this._player.pause();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "playing":
|
case "playing":
|
||||||
this._sound.play();
|
this._player.play();
|
||||||
break;
|
break;
|
||||||
case "playingAllLoaded":
|
case "playingAllLoaded":
|
||||||
switch (e.oldState) {
|
switch (e.oldState) {
|
||||||
case "pausedAllLoaded":
|
case "pausedAllLoaded":
|
||||||
this._sound.play();
|
this._player.play();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -246,14 +253,6 @@ var Player = Controller.inherit({
|
|||||||
},
|
},
|
||||||
_removeView: function(type) {
|
_removeView: function(type) {
|
||||||
//TODO
|
//TODO
|
||||||
},
|
|
||||||
_schedule: function(buffer) {
|
|
||||||
var source = this._ctx.createBufferSource();
|
|
||||||
source.buffer = buffer;
|
|
||||||
source.connect(this._ctx.destination);
|
|
||||||
|
|
||||||
source.start(this._currentTime);
|
|
||||||
this._currentTime += buffer.duration;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -294,7 +293,7 @@ graphs[PlayerMode.straight.playback] = {
|
|||||||
play: "playingAllLoaded"
|
play: "playingAllLoaded"
|
||||||
},
|
},
|
||||||
"playing": {
|
"playing": {
|
||||||
pause: "pause",
|
pause: "paused",
|
||||||
noMoreFrames: "playingAllLoaded"
|
noMoreFrames: "playingAllLoaded"
|
||||||
},
|
},
|
||||||
"playingAllLoaded": {
|
"playingAllLoaded": {
|
||||||
|
@ -45,7 +45,7 @@ var Vocabulary = Controller.inherit({
|
|||||||
|
|
||||||
var keys = insert.getKeys();
|
var keys = insert.getKeys();
|
||||||
for (var j = 0; j < keys.length; ++j) {
|
for (var j = 0; j < keys.length; ++j) {
|
||||||
key = keys[i];
|
key = keys[j];
|
||||||
this.addElement(key, insert.at(key).clone());
|
this.addElement(key, insert.at(key).clone());
|
||||||
}
|
}
|
||||||
this.trigger("change", data.clone());
|
this.trigger("change", data.clone());
|
||||||
|
@ -10,4 +10,4 @@
|
|||||||
<body>
|
<body>
|
||||||
<p>I am</p>
|
<p>I am</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.8.12)
|
|||||||
add_subdirectory(requirejs)
|
add_subdirectory(requirejs)
|
||||||
add_subdirectory(wSocket)
|
add_subdirectory(wSocket)
|
||||||
add_subdirectory(bintrees)
|
add_subdirectory(bintrees)
|
||||||
|
add_subdirectory(mp3)
|
||||||
|
add_subdirectory(aurora)
|
||||||
add_subdirectory(wContainer)
|
add_subdirectory(wContainer)
|
||||||
add_subdirectory(utils)
|
add_subdirectory(utils)
|
||||||
add_subdirectory(wType)
|
add_subdirectory(wType)
|
||||||
|
3
lorgar/lib/aurora/CMakeLists.txt
Normal file
3
lorgar/lib/aurora/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
|
configure_file(aurora.js aurora.js)
|
3938
lorgar/lib/aurora/aurora.js
Normal file
3938
lorgar/lib/aurora/aurora.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
configure_file(index.js index.js)
|
configure_file(index.js index.js)
|
||||||
|
3
lorgar/lib/mp3/CMakeLists.txt
Normal file
3
lorgar/lib/mp3/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
|
configure_file(mp3.js mp3.js)
|
7706
lorgar/lib/mp3/mp3.js
Normal file
7706
lorgar/lib/mp3/mp3.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
(function main_js() {
|
(function main_js() {
|
||||||
|
requirejs.config({
|
||||||
|
"baseUrl": "/",
|
||||||
|
"shim": {
|
||||||
|
"lib/mp3/mp3": ["lib/aurora/aurora"]
|
||||||
|
}
|
||||||
|
});
|
||||||
requirejs.onError = function(e) {
|
requirejs.onError = function(e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -8,6 +14,7 @@
|
|||||||
defineArray.push("test/test");
|
defineArray.push("test/test");
|
||||||
defineArray.push("core/lorgar");
|
defineArray.push("core/lorgar");
|
||||||
defineArray.push("lib/utils/globalMethods");
|
defineArray.push("lib/utils/globalMethods");
|
||||||
|
defineArray.push("lib/mp3/mp3");
|
||||||
|
|
||||||
require(defineArray, function main_module() {
|
require(defineArray, function main_module() {
|
||||||
require("lib/utils/globalMethods");
|
require("lib/utils/globalMethods");
|
||||||
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
|
|||||||
project(test)
|
project(test)
|
||||||
|
|
||||||
find_package(CxxTest)
|
find_package(CxxTest)
|
||||||
|
cmake_policy(SET CMP0071 NEW)
|
||||||
if(CXXTEST_FOUND)
|
if(CXXTEST_FOUND)
|
||||||
include_directories(${CXXTEST_INCLUDE_DIR})
|
include_directories(${CXXTEST_INCLUDE_DIR})
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
Loading…
Reference in New Issue
Block a user