-
Notifications
You must be signed in to change notification settings - Fork 234
/
main.js
79 lines (73 loc) · 1.54 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (c) 2022 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import AudioOut from "pins/audioout"
import WavStreamer from "wavstreamer";
import SBCStreamer from "sbcstreamer";
function calculatePower(samplea) @ "xs_calculatePower";
const audio = new AudioOut({});
function streamWav() {
new WavStreamer({
http: device.network.http,
host: "test.moddable.com",
path: "/audio/ChristmasMusic/jingle.wav",
audio: {
out: audio,
stream: 0
},
onPlayed(buffer) {
const power = calculatePower(buffer);
trace(`WAV power ${Math.round(power)}\n`);
},
onReady(state) {
trace(`WAV Ready: ${state}\n`);
if (state)
audio.start();
else
audio.stop();
},
onError(e) {
trace("WAV ERROR: ", e, "\n");
},
onDone() {
trace("WAV Done\n");
streamSBC();
}
});
}
function streamSBC() {
new SBCStreamer({
http: device.network.http,
host: "test.moddable.com",
path: "/audio/ChristmasMusic/jesu.sbc",
audio: {
out: audio,
stream: 0
},
onReady(state) {
trace(`SBC Ready: ${state}\n`);
if (state)
audio.start();
else
audio.stop();
},
onError(e) {
trace("SBC ERROR: ", e, "\n");
},
onDone() {
trace("SBC Done\n");
streamWav();
}
});
}
streamWav();