mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-02-07 01:11:22 +08:00
js : decode now returns typed array and cannot be null
If no data is decoded, then the returned array is empty.
This commit is contained in:
@@ -61,9 +61,7 @@ EMSCRIPTEN_BINDINGS(ggwave) {
|
||||
result.resize(n);
|
||||
ggwave_encode(instance, data.data(), data.size(), txProtocolId, volume, result.data(), 0);
|
||||
|
||||
return emscripten::val(
|
||||
emscripten::typed_memory_view(result.size(),
|
||||
result.data()));
|
||||
return emscripten::val(emscripten::typed_memory_view(result.size(), result.data()));
|
||||
}));
|
||||
|
||||
emscripten::function("decode", emscripten::optional_override(
|
||||
@@ -73,10 +71,10 @@ EMSCRIPTEN_BINDINGS(ggwave) {
|
||||
auto n = ggwave_decode(instance, data.data(), data.size(), output);
|
||||
|
||||
if (n > 0) {
|
||||
return std::string(output, n);
|
||||
return emscripten::val(emscripten::typed_memory_view(n, output));
|
||||
}
|
||||
|
||||
return std::string();
|
||||
return emscripten::val(emscripten::typed_memory_view(0, output));
|
||||
}));
|
||||
|
||||
emscripten::function("disableLog", emscripten::optional_override(
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -118,7 +118,7 @@
|
||||
navigator.mediaDevices.getUserMedia(constraints).then(function (e) {
|
||||
mediaStream = context.createMediaStreamSource(e);
|
||||
|
||||
var bufferSize = 16*1024;
|
||||
var bufferSize = 1024;
|
||||
var numberOfInputChannels = 1;
|
||||
var numberOfOutputChannels = 1;
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
recorder.onaudioprocess = function (e) {
|
||||
var source = e.inputBuffer;
|
||||
var res = ggwave.decode(instance, convertTypedArray(new Float32Array(source.getChannelData(0)), Int8Array));
|
||||
if (res) {
|
||||
if (res && res.length > 0) {
|
||||
rxData.value = res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user