Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Nov 21, 2023
1 parent 5413015 commit 502b99f
Show file tree
Hide file tree
Showing 30 changed files with 37 additions and 229 deletions.
3 changes: 2 additions & 1 deletion examples/_crash.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const context = new AudioContext();
source.buffer = buffer;
source.playbackRate.setValueAtTime(audio.playbackRate, audio.startTime);
audio.startTime = context.currentTime;
console.log(context.currentTime);
source.start(audio.startTime, 0);
};

Expand All @@ -72,7 +73,7 @@ const context = new AudioContext();
const previousHeight = ball.y;
const al = i * offset + ( time * speed );

ball.y = Math.abs(Math.sin(al) * height);
ball.y = Math.abs(Math.sin(0.5 * al) * height);

if (ball.y === previousHeight) {
continue;
Expand Down
1 change: 0 additions & 1 deletion src/cpp/analyser-node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ DECLARE_ES5_CLASS(AnalyserNode, AnalyserNode);
double _smoothingTimeConstant;

JS_DECLARE_METHOD(AnalyserNode, destroy);

JS_DECLARE_METHOD(AnalyserNode, getFloatFrequencyData);
JS_DECLARE_METHOD(AnalyserNode, getByteFrequencyData);
JS_DECLARE_METHOD(AnalyserNode, getFloatTimeDomainData);
Expand Down
21 changes: 21 additions & 0 deletions src/cpp/audio-buffer-source-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ JS_IMPLEMENT_METHOD(AudioBufferSourceNode, start) { THIS_CHECK;
_impl.get()
);

if (_isLooping) {
if (_loopEnd > _loopStart) {
node->start(when, _loopStart, _loopEnd - _loopStart, -1);
} else {
node->start(when, _loopStart, -1);
}
} else {
node->start(when);
}

RET_UNDEFINED;
}


JS_IMPLEMENT_METHOD(AudioBufferSourceNode, schedule) { THIS_CHECK;
LET_DOUBLE_ARG(0, when);

lab::SampledAudioNode *node = static_cast<lab::SampledAudioNode*>(
_impl.get()
);

if (_isLooping) {
if (_loopEnd > _loopStart) {
node->schedule(when, _loopStart, _loopEnd - _loopStart, -1);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/audio-buffer-source-node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _AUDIO_BUFFER_SOURCE_NODE_HPP_

#include "common.hpp"

#include "audio-scheduled-source-node.hpp"


Expand All @@ -28,6 +27,7 @@ DECLARE_ES5_CLASS(AudioBufferSourceNode, AudioBufferSourceNode);
JS_DECLARE_METHOD(AudioBufferSourceNode, destroy);

JS_DECLARE_METHOD(AudioBufferSourceNode, start);
JS_DECLARE_METHOD(AudioBufferSourceNode, schedule);

JS_DECLARE_GETTER(AudioBufferSourceNode, buffer);
JS_DECLARE_SETTER(AudioBufferSourceNode, buffer);
Expand Down
26 changes: 0 additions & 26 deletions src/cpp/audio-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
IMPLEMENT_ES5_CLASS(AudioBuffer);

void AudioBuffer::init(Napi::Env env, Napi::Object exports) {

Napi::Function ctor = wrap(env);
JS_ASSIGN_METHOD(copyToChannel);
JS_ASSIGN_METHOD(copyFromChannel);
Expand All @@ -17,31 +16,23 @@ void AudioBuffer::init(Napi::Env env, Napi::Object exports) {
JS_ASSIGN_METHOD(destroy);

exports.Set("AudioBuffer", ctor);

}


AudioBuffer::AudioBuffer(const Napi::CallbackInfo &info):
CommonBus(info.This(), "AudioBuffer") { NAPI_ENV;

super(info);

Napi::Object context = info[0].As<Napi::Object>();

if (info.Length() > 1) {

Napi::External<void> extBus = info[1].As< Napi::External<void> >();

BusPtr *busPtr = reinterpret_cast<BusPtr *>(extBus.Data());
reset(context, *busPtr);

} else {

BusPtr bus = std::make_shared<lab::AudioBus>(1, 1, false);
reset(context, bus);

}

}


Expand All @@ -56,72 +47,55 @@ void AudioBuffer::_destroy() { DES_CHECK;


JS_IMPLEMENT_METHOD(AudioBuffer, getChannelData) { THIS_CHECK;

REQ_UINT32_ARG(0, channelIndex);

// TODO: do something?
RET_UNDEFINED;

}


JS_IMPLEMENT_METHOD(AudioBuffer, copyFromChannel) { THIS_CHECK;

REQ_OBJ_ARG(0, destination);
REQ_INT32_ARG(1, channelNumber);
REQ_UINT32_ARG(2, startInChannel);

// TODO: do something?
RET_UNDEFINED;

}


JS_IMPLEMENT_METHOD(AudioBuffer, copyToChannel) { THIS_CHECK;

REQ_OBJ_ARG(0, source);
REQ_INT32_ARG(1, channelNumber);
REQ_UINT32_ARG(2, startInChannel);

// TODO: do something?
RET_UNDEFINED;

}


JS_IMPLEMENT_GETTER(AudioBuffer, length) { THIS_CHECK;

RET_NUM(_length);

}


JS_IMPLEMENT_GETTER(AudioBuffer, duration) { THIS_CHECK;

RET_NUM(_duration);

}


JS_IMPLEMENT_GETTER(AudioBuffer, sampleRate) { THIS_CHECK;

RET_NUM(_sampleRate);

}


JS_IMPLEMENT_GETTER(AudioBuffer, numberOfChannels) { THIS_CHECK;

RET_NUM(_numberOfChannels);

}


JS_IMPLEMENT_METHOD(AudioBuffer, destroy) { THIS_CHECK;

emit("destroy");

_destroy();
RET_UNDEFINED;

}
8 changes: 0 additions & 8 deletions src/cpp/audio-buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class AudioBuffer : public CommonBus {
DECLARE_ES5_CLASS(AudioBuffer, AudioBuffer);

public:

static void init(Napi::Env env, Napi::Object exports);

explicit AudioBuffer(const Napi::CallbackInfo &info);
Expand All @@ -17,26 +15,20 @@ DECLARE_ES5_CLASS(AudioBuffer, AudioBuffer);
void _destroy();

private:

int _length;
double _duration;
float _sampleRate;
uint32_t _numberOfChannels;

JS_DECLARE_METHOD(AudioBuffer, destroy);

JS_DECLARE_METHOD(AudioBuffer, getChannelData);
JS_DECLARE_METHOD(AudioBuffer, copyFromChannel);
JS_DECLARE_METHOD(AudioBuffer, copyToChannel);

JS_DECLARE_GETTER(AudioBuffer, length);

JS_DECLARE_GETTER(AudioBuffer, duration);

JS_DECLARE_GETTER(AudioBuffer, sampleRate);

JS_DECLARE_GETTER(AudioBuffer, numberOfChannels);

};


Expand Down
1 change: 0 additions & 1 deletion src/cpp/audio-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ JS_IMPLEMENT_GETTER(AudioContext, baseLatency) { THIS_CHECK;

JS_IMPLEMENT_METHOD(AudioContext, destroy) { THIS_CHECK;
emit("destroy");

_destroy();
RET_UNDEFINED;
}
5 changes: 0 additions & 5 deletions src/cpp/audio-context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class AudioContext : public CommonCtx {
DECLARE_ES5_CLASS(AudioContext, AudioContext);

public:

static void init(Napi::Env env, Napi::Object exports);

explicit AudioContext(const Napi::CallbackInfo &info);
Expand All @@ -17,16 +15,13 @@ DECLARE_ES5_CLASS(AudioContext, AudioContext);
void _destroy();

private:

double _baseLatency;

JS_DECLARE_METHOD(AudioContext, destroy);

JS_DECLARE_METHOD(AudioContext, suspend);
JS_DECLARE_METHOD(AudioContext, close);
JS_DECLARE_METHOD(AudioContext, getOutputTimestamp);
JS_DECLARE_GETTER(AudioContext, baseLatency);

};


Expand Down
13 changes: 0 additions & 13 deletions src/cpp/audio-destination-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
IMPLEMENT_ES5_CLASS(AudioDestinationNode);

void AudioDestinationNode::init(Napi::Env env, Napi::Object exports) {

Napi::Function ctor = wrap(env);
JS_ASSIGN_GETTER(maxChannelCount);
JS_ASSIGN_METHOD(destroy);

exports.Set("AudioDestinationNode", ctor);

}


AudioDestinationNode::AudioDestinationNode(const Napi::CallbackInfo &info):
CommonNode(info.This(), "AudioDestinationNode") { NAPI_ENV;

Napi::Object context = info[0].As<Napi::Object>();
Napi::External<void> extNode = info[1].As< Napi::External<void> >();

NodePtr *node = reinterpret_cast<NodePtr *>(extNode.Data());

reset(context, *node);

Napi::Value argv[] = { context, extNode };
super(info, 2, argv);

}


Expand All @@ -36,24 +30,17 @@ AudioDestinationNode::~AudioDestinationNode() {


void AudioDestinationNode::_destroy() { DES_CHECK;

CommonNode::_destroy();

}


JS_IMPLEMENT_GETTER(AudioDestinationNode, maxChannelCount) { THIS_CHECK;

RET_NUM(_maxChannelCount);

}


JS_IMPLEMENT_METHOD(AudioDestinationNode, destroy) { THIS_CHECK;

emit("destroy");

_destroy();
RET_UNDEFINED;

}
4 changes: 0 additions & 4 deletions src/cpp/audio-destination-node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class AudioDestinationNode : public CommonNode {
DECLARE_ES5_CLASS(AudioDestinationNode, AudioDestinationNode);

public:

static void init(Napi::Env env, Napi::Object exports);

explicit AudioDestinationNode(const Napi::CallbackInfo &info);
Expand All @@ -17,13 +15,11 @@ DECLARE_ES5_CLASS(AudioDestinationNode, AudioDestinationNode);
void _destroy();

private:

uint32_t _maxChannelCount;

JS_DECLARE_METHOD(AudioDestinationNode, destroy);

JS_DECLARE_GETTER(AudioDestinationNode, maxChannelCount);

};


Expand Down
11 changes: 0 additions & 11 deletions src/cpp/audio-listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
IMPLEMENT_ES5_CLASS(AudioListener);

void AudioListener::init(Napi::Env env, Napi::Object exports) {

Napi::Function ctor = wrap(env);
JS_ASSIGN_METHOD(setOrientation);
JS_ASSIGN_METHOD(setPosition);
Expand All @@ -22,13 +21,11 @@ void AudioListener::init(Napi::Env env, Napi::Object exports) {
JS_ASSIGN_METHOD(destroy);

exports.Set("AudioListener", ctor);

}


AudioListener::AudioListener(const Napi::CallbackInfo &info):
CommonListener(info.This(), "AudioListener") { NAPI_ENV;

super(info);

Napi::Object context = info[0].As<Napi::Object>();
Expand Down Expand Up @@ -78,7 +75,6 @@ CommonListener(info.This(), "AudioListener") { NAPI_ENV;
ParamPtr upZParam = _impl->upZ();
argv[1] = JS_EXT(&upZParam);
_upZ.Reset(paramCtor.New(2, argv), 1);

}


Expand Down Expand Up @@ -113,19 +109,16 @@ PARAM_GETTER(AudioListener, upZ);


JS_IMPLEMENT_METHOD(AudioListener, setPosition) { THIS_CHECK;

REQ_FLOAT_ARG(0, x);
REQ_FLOAT_ARG(1, y);
REQ_FLOAT_ARG(2, z);

_impl->setPosition(x, y, z);
RET_UNDEFINED;

}


JS_IMPLEMENT_METHOD(AudioListener, setOrientation) { THIS_CHECK;

REQ_FLOAT_ARG(0, x);
REQ_FLOAT_ARG(1, y);
REQ_FLOAT_ARG(2, z);
Expand All @@ -135,14 +128,10 @@ JS_IMPLEMENT_METHOD(AudioListener, setOrientation) { THIS_CHECK;

_impl->setOrientation(x, y, z, xUp, yUp, zUp);
RET_UNDEFINED;

}

JS_IMPLEMENT_METHOD(AudioListener, destroy) { THIS_CHECK;

emit("destroy");

_destroy();
RET_UNDEFINED;

}
Loading

0 comments on commit 502b99f

Please sign in to comment.