Skip to content

Commit

Permalink
Fixed some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Sep 2, 2024
1 parent 55aa948 commit 3f8fd53
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/audio/source/common/PortAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace l::audio {
return false;
}

auto bufferSize = GetPartTotalSize();
auto bufferSize = static_cast<size_t>(GetPartTotalSize());
if (mWriteBuffer.size() != bufferSize) {
mWriteBuffer.resize(bufferSize);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/audio/tests/common/PortAudioTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(PortAudio, Setup) {

auto stream = manager.GetStream("speaker");

if (!stream->OpenStream(2048, 20.0f)) {
if (!stream->OpenStream(2048, 20.0f, l::audio::BufferingMode::TRIPLE_BUFFERING)) {
return 0;
}
if (!stream->StartStream()) {
Expand Down
7 changes: 6 additions & 1 deletion packages/nodegraph/include/nodegraph/NodeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ namespace l::nodegraph {
for (int8_t i = mInputCount; i < mInputCount + mConstantCount; i++) {
SetInput(i, 0.0f);
}
ProcessSubGraph();
}

virtual bool IsDataVisible(int8_t num) override {
Expand All @@ -207,8 +206,14 @@ namespace l::nodegraph {
}

virtual void ProcessOperation() override {
if (mProcessUpdateHasRun) {
return;
}

NodeGraphBase::ProcessOperation();
mOperation.ProcessSubGraph(mInputs, mOutputs);

mProcessUpdateHasRun = true;
}

virtual void Tick(float time, float elapsed) override {
Expand Down
1 change: 0 additions & 1 deletion packages/nodegraph/include/nodegraph/NodeGraphOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ namespace l::nodegraph {

protected:
float mPhase = 0.0f;
float mPrevTime = 0.0f;
};

class GraphSourceKeyboard : public NodeGraphOp, public l::hid::INoteProcessor {
Expand Down
20 changes: 7 additions & 13 deletions packages/nodegraph/source/common/NodeGraphOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,22 @@ namespace l::nodegraph {
}

void GraphSourceSine::ProcessSubGraph(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) {
float time = inputs.at(0).Get();
//float time = inputs.at(0).Get();
float freq = inputs.at(1).Get();
float fMod = 1.0f + inputs.at(2).Get();
float pMod = inputs.at(3).Get();
float reset = inputs.at(4).Get();

if (reset > 0.5f) {
if (freq == 0.0f) {
Reset();
outputs.at(0).mOutput = 0.0f;
return;
}

float deltaTime = time - mPrevTime;
if (mPrevTime == 0.0f) {
mPrevTime = time;
deltaTime = time - mPrevTime;
if (reset > 0.5f) {
Reset();
}

mPrevTime = time;

float deltaTime = 1.0f / 44100.0f;
float phaseDelta = deltaTime * freq;

mPhase += phaseDelta * fMod;
Expand All @@ -104,7 +102,6 @@ namespace l::nodegraph {

void GraphSourceSine::Reset() {
mPhase = 0.0f;
mPrevTime = 0.0f;
}

std::string_view GraphSourceSine::GetInputName(int8_t inputChannel) {
Expand Down Expand Up @@ -133,7 +130,6 @@ namespace l::nodegraph {
for (int8_t i = 0; i < GetNumInputs(); i++) {
mNode->SetInput(i, 0.0f);
}
mNode->ProcessSubGraph();
}

std::string_view GraphSourceKeyboard::GetOutputName(int8_t outputChannel) {
Expand All @@ -152,7 +148,6 @@ namespace l::nodegraph {
float frequency = l::audio::GetFrequencyFromNote(static_cast<float>(note));
int8_t channel = GetNextNoteChannel(note);
mNode->SetInput(static_cast<int8_t>(channel), frequency);
mNode->ProcessSubGraph();
}
void GraphSourceKeyboard::NoteOff() {
Reset();
Expand All @@ -162,7 +157,6 @@ namespace l::nodegraph {
int8_t channel = ResetNoteChannel(note);
if (channel >= 0) {
mNode->SetInput(channel, 0.0f);
mNode->ProcessSubGraph();
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/nodegraph/source/common/NodeGraphSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace l::nodegraph {
node = mMainNodeGraph.NewNode<l::nodegraph::GraphSourceConstants>(false, 3);
break;
case 4:
node = mMainNodeGraph.NewNode<l::nodegraph::GraphSourceKeyboard, l::hid::KeyState>(false, 4, mKeyState);
node = mMainNodeGraph.NewNode<l::nodegraph::GraphSourceKeyboard, l::hid::KeyState>(false, 1, mKeyState);
break;
case 5:
node = mMainNodeGraph.NewNode<l::nodegraph::GraphSourceTime>(false);
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace l::nodegraph {
node = mMainNodeGraph.NewNode<l::nodegraph::GraphFilterLowpass>(false);
break;
case 200:
node = mMainNodeGraph.NewNode<l::nodegraph::GraphOutputDebug>(true, 4);
node = mMainNodeGraph.NewNode<l::nodegraph::GraphOutputDebug>(true, 1);
break;
case 201:
node = mMainNodeGraph.NewNode<l::nodegraph::GraphOutputSpeaker>(true, mAudioOutput);
Expand Down

0 comments on commit 3f8fd53

Please sign in to comment.