Skip to content

fix: output silence when graph is disconnected#334

Merged
sudip-mondal-2002 merged 8 commits into
sudip-mondal-2002:mainfrom
MohitBareja16:fix/disconnected-graph-silence
Jun 3, 2026
Merged

fix: output silence when graph is disconnected#334
sudip-mondal-2002 merged 8 commits into
sudip-mondal-2002:mainfrom
MohitBareja16:fix/disconnected-graph-silence

Conversation

@MohitBareja16

@MohitBareja16 MohitBareja16 commented May 30, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR fixes a bug in the DSP pipeline where an empty or completely disconnected audio graph would inadvertently bypass the dry input signal to the output instead of correctly muting it.

Specifically, in AudioGraphExecutor::process, when the execution_plan_ was empty (no connected pedals) or an oversized block was received, it copied the input buffer to the output using std::memcpy. This has been updated to output absolute silence using std::memset (zeroing the buffer) instead. It also updates the respective integration tests to assert for silence instead of passthrough.

Related Issue

Fixes #273

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor / code cleanup
  • 📝 Documentation
  • ✅ Tests
  • 🔧 Build / CI / Configuration

How Was This Tested?

  • Platform(s) tested on: Linux (Ubuntu)
  • Test command run: ./build/tests/integration/integration_tests
  • Manual test steps (if applicable):
    1. Boot up the Amplitron UI.
    2. Disconnect all cables between the graph's main Input and Output.
    3. Play audio into the interface and verify that no dry signal leaks through (100% silent).

Checklist

  • Code compiles and builds successfully on my platform
  • All existing tests pass (./amplitron-tests)
  • New tests added for new functionality (if applicable)
  • Documentation updated (README, code comments) if applicable
  • No blocking calls on the audio thread (no std::mutex::lock() on the hot path)
  • Tested on: Linux

Screenshots / Demo

N/A - purely backend DSP logic fix (no visual changes).

Summary by CodeRabbit

  • Bug Fixes

    • Audio processing now outputs silence for oversized buffers and when no execution plan exists, avoiding unintended passthrough.
    • Cabinet simulation high-pass filter coefficients adjusted for improved low-end behavior.
  • Tests

    • Integration tests updated to expect silence in edge cases and add split/merge disconnection coverage.
    • Engine tests install then disable an effect to ensure consistent test conditions.
  • Chores

    • Build configuration properly closes a top-level conditional.

@github-actions github-actions Bot added good first issue Good for newcomers level:intermediate Intermediate task · 25 GSSoC points type:bug Something isn't working type:testing Unit tests, integration tests, or test coverage labels May 30, 2026
@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

AudioGraphExecutor now zeroes output and returns for oversized blocks or empty execution plans. Integration tests updated to expect silence in those cases and new split/merge disconnect tests added. Several audio-engine tests prepend a disabled Distortion. CMake gets a missing endif(); CabinetSim HPF coefficients adjusted.

Changes

Disconnected Graph Silence Behavior

Layer / File(s) Summary
Silent output implementation
src/audio/engine/audio_graph_executor.cpp
AudioGraphExecutor::process zeroes output and returns when num_samples > max_block_size_ or when execution_plan_ is empty; removes prior passthrough behavior.
AudioGraph integration tests updated to expect silence
tests/integration/test_audio_graph.cpp
Updated assertions to expect 0.0f output for no-compile, oversized-block, implicit input fallback, implicit sink detection cases; added audio_graph_split_merge_disconnects verifying silence when routes are disconnected.
Audio engine tests: prepend disabled Distortion
tests/integration/test_audio_engine.cpp
Several tests now add a disabled Distortion effect (set_enabled(false)) before running existing assertions (InputGainScalesOutput, OutputGainScalesOutput, OutputIsClampedToSafetyLimit, RMSCalculationSilenceVsTone, FullCoverageSweep).

CMake fix

Layer / File(s) Summary
Terminate platform conditional
CMakeLists.txt
Add missing closing endif() at end of CMakeLists.txt for the top-level platform conditional.

CabinetSim HPF update

Layer / File(s) Summary
High-pass filter coefficients
src/audio/effects/amp_cab/cabinet_sim.cpp
Replace two HPF biquad coefficient values in the CabinetSim constructor initialization.

Sequence Diagram

sequenceDiagram
  participant Tests
  participant AudioGraphExecutor
  participant ExecutionPlan
  participant OutputBuffer
  Tests->>AudioGraphExecutor: call process(input, output, num_samples)
  AudioGraphExecutor->>ExecutionPlan: check execution_plan_
  alt execution_plan_ empty
    AudioGraphExecutor->>OutputBuffer: zero(num_samples)
    AudioGraphExecutor->>Tests: return
  else
    AudioGraphExecutor->>AudioGraphExecutor: compare num_samples to max_block_size_
    alt num_samples > max_block_size_
      AudioGraphExecutor->>OutputBuffer: zero(num_samples)
      AudioGraphExecutor->>Tests: return
    else
      AudioGraphExecutor->>ExecutionPlan: execute plan (normal processing)
      AudioGraphExecutor->>OutputBuffer: write processed samples
      AudioGraphExecutor->>Tests: return
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Audio Processing, DAG, platform: linux, quality:clean, level:advanced

Suggested reviewers

  • sudip-mondal-2002

Poem

🐰 I tap the buffer with a twitch and a whisker,
When wires go quiet, I hush every whisper.
Zeroes in rows where stray echoes once played,
A tidy silence the graph's now made.
Hopping off, content — the signals obey.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The cabinet_sim.cpp filter coefficient changes appear unrelated to the disconnected graph silence fix, introducing out-of-scope modifications to high-pass filter tuning. Remove the cabinet_sim.cpp coefficient changes as they are not related to fixing disconnected graph silence output. Create a separate PR for audio filter tuning adjustments.
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: output silence when graph is disconnected' accurately and concisely describes the main change: addressing a bug where disconnected audio graphs incorrectly output audio instead of silence.
Linked Issues check ✅ Passed The PR directly addresses issue #273 by modifying AudioGraphExecutor::process to output silence instead of passing through input when the graph is disconnected, and adds comprehensive test coverage for this scenario.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/audio/engine/audio_graph_executor.cpp`:
- Around line 109-111: The oversized-block branch in audio_graph_executor.cpp
only zeros max_block_size_ samples leaving the rest of the caller's output
buffer with stale data; update the branch that checks if (num_samples >
max_block_size_) to clear all num_samples floats in output (use a size-safe cast
to size_t and multiply by sizeof(float) or std::fill_n) before returning so the
entire provided buffer is silent; refer to variables/functions num_samples,
max_block_size_, and output when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd4c1897-c923-4661-8284-112671ed2447

📥 Commits

Reviewing files that changed from the base of the PR and between a4ecce3 and 1f9712a.

📒 Files selected for processing (2)
  • src/audio/engine/audio_graph_executor.cpp
  • tests/integration/test_audio_graph.cpp

Comment thread src/audio/engine/audio_graph_executor.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/integration/test_audio_engine.cpp (1)

26-28: 💤 Low value

Consider extracting the disabled-effect pattern to a test fixture helper.

The 3-line pattern for adding a disabled Distortion effect is repeated identically across 5 tests. While acceptable for test clarity, extracting this to AudioEngineTest as a helper method (e.g., add_bypass_effect()) would reduce duplication and make the intent clearer.

♻️ Example refactor

Add to AudioEngineTest fixture (likely in tests/integration/test_fixtures.h):

void add_bypass_effect() {
    auto bypass = std::make_shared<Distortion>();
    bypass->set_enabled(false);
    engine.add_effect(bypass);
}

Then replace the 3-line blocks with:

-    auto bypass = std::make_shared<Distortion>();
-    bypass->set_enabled(false);
-    engine.add_effect(bypass);
+    add_bypass_effect();

Also applies to: 37-39, 49-51, 66-68, 297-299

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_audio_engine.cpp` around lines 26 - 28, Duplicate
3-line pattern creating a disabled Distortion and adding it to the engine
appears in multiple tests; extract this into a fixture helper to reduce
duplication. Add a method on the AudioEngineTest fixture (e.g.,
add_bypass_effect()) that constructs a std::shared_ptr<Distortion>, calls
set_enabled(false) on it, and calls engine.add_effect(...) with that pointer,
then replace each repeated block (the pattern using Distortion, set_enabled,
engine.add_effect) in tests with a call to add_bypass_effect().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/integration/test_audio_engine.cpp`:
- Around line 26-28: Duplicate 3-line pattern creating a disabled Distortion and
adding it to the engine appears in multiple tests; extract this into a fixture
helper to reduce duplication. Add a method on the AudioEngineTest fixture (e.g.,
add_bypass_effect()) that constructs a std::shared_ptr<Distortion>, calls
set_enabled(false) on it, and calls engine.add_effect(...) with that pointer,
then replace each repeated block (the pattern using Distortion, set_enabled,
engine.add_effect) in tests with a call to add_bypass_effect().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87eaebfd-e7fb-49aa-999f-5bcf1de3ea35

📥 Commits

Reviewing files that changed from the base of the PR and between 1f9712a and 24dab4f.

📒 Files selected for processing (2)
  • tests/integration/test_audio_engine.cpp
  • tests/integration/test_audio_graph.cpp

@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

🌍 Cross-Platform Coverage Report

Platforms: Linux + macOS + Windows
Merged Line Coverage: 76.7%

✅ Coverage meets threshold: 76.7% >= 60%

Full Merged Coverage Summary
Summary coverage rate:
  lines......: 76.7% (8828 of 11515 lines)
  functions..: 85.3% (984 of 1154 functions)
  branches...: no data found

@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

PR Preview Removed

The GitHub Pages preview for this PR has been removed because the PR was closed.

@sudip-mondal-2002

Copy link
Copy Markdown
Owner

Add few new clean tests

The original graph looks like

input ->> splitter ->> A ->> Merge ->> Amp
| |
--->> B -------->

If we pass input to original, it should produce output
If we break splitter to A, but keep splitter to B connected, it should create output
If we break splitter to B, but keep splitter to A connected, it should create output
If we break both splitter to A and splitter to B, it should NOT create output
If we break A-> merge, splitter -> B, it should NOT create output

@MohitBareja16

@sudip-mondal-2002 sudip-mondal-2002 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests missing

@github-actions github-actions Bot added the Medium label Jun 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/integration/test_audio_graph.cpp (1)

1116-1142: ⚡ Quick win

Assert the exact branch sums, not just “non-zero”.

These three cases are deterministic with the current executor contract: full split/merge should produce 2.0f, and the single-branch cases should produce 1.0f. Using > 0.0f will still pass if a stale route leaks extra signal or a disconnected branch is accidentally still accumulated. src/audio/engine/audio_graph_executor.cpp:128-173 makes the expected values exact here.

Suggested assertion tightening
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 2.0f);
...
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 1.0f);
...
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 1.0f);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_audio_graph.cpp` around lines 1116 - 1142, The tests
currently assert only that output_audio[0] > 0.0f; change these to assert exact
expected branch sums per the executor contract: when both branches are active
expect 2.0f and when only a single branch is active expect 1.0f. Update the
three ASSERT_TRUE checks after executor.process(...) to use precise float
comparisons (e.g., ASSERT_FLOAT_EQ or ASSERT_NEAR with a tiny epsilon) against
2.0f or 1.0f respectively, keeping references to the same topology changes
(graph.rebuild_topology(), executor.compile(graph), executor.process(...), and
the link variables l_split_a / l_split_b) so the assertions map to the correct
cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CMakeLists.txt`:
- Around line 103-125: The config-based find_package(portaudio CONFIG QUIET)
branch sets PORTAUDIO_FOUND when TARGET portaudio exists but the subsequent
PkgConfig/pk_check_modules and manual find_path/find_library logic can overwrite
those variables; modify the fallback so the pkg_check_modules(PORTAUDIO ...) and
the manual find_path/find_library steps (and the
link_directories(${PORTAUDIO_LIBRARY_DIRS}) call) only run when the CONFIG
target was not found (e.g., wrap them in an if(NOT TARGET portaudio) or if(NOT
PORTAUDIO_FOUND) guard), preventing the CONFIG-selected target and its
PORTAUDIO_* values from being clobbered.

In `@tests/integration/test_audio_graph.cpp`:
- Around line 1099-1114: The test currently calls graph.add_link and
graph.remove_link (e.g., when creating l_in_split, l_split_a, l_split_b,
l_a_merge, l_b_merge, l_merge_amp and other link/remove calls) without checking
the return values; add assertions immediately after each mutation that validate
the operation succeeded (for example assert/EXPECT that add_link returned a
valid id and remove_link returned success/true) so the test fails fast if any
topology mutation fails and subsequent silence checks aren't masking a bad graph
shape. Ensure you add these guard assertions for every add_link/remove_link
usage in this block and the other mentioned ranges (1126-1127, 1135-1138,
1145-1147, 1155-1163).

---

Nitpick comments:
In `@tests/integration/test_audio_graph.cpp`:
- Around line 1116-1142: The tests currently assert only that output_audio[0] >
0.0f; change these to assert exact expected branch sums per the executor
contract: when both branches are active expect 2.0f and when only a single
branch is active expect 1.0f. Update the three ASSERT_TRUE checks after
executor.process(...) to use precise float comparisons (e.g., ASSERT_FLOAT_EQ or
ASSERT_NEAR with a tiny epsilon) against 2.0f or 1.0f respectively, keeping
references to the same topology changes (graph.rebuild_topology(),
executor.compile(graph), executor.process(...), and the link variables l_split_a
/ l_split_b) so the assertions map to the correct cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 092a9022-278a-426c-b0d3-3d8f986ff4ad

📥 Commits

Reviewing files that changed from the base of the PR and between 24dab4f and ab9c573.

⛔ Files ignored due to path filters (2)
  • short.wav is excluded by !**/*.wav
  • very_long_ir_file_name_that_should_be_truncated.wav is excluded by !**/*.wav
📒 Files selected for processing (3)
  • CMakeLists.txt
  • src/audio/engine/audio_graph_executor.cpp
  • tests/integration/test_audio_graph.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/audio/engine/audio_graph_executor.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/integration/test_audio_graph.cpp (1)

1116-1142: ⚡ Quick win

Assert the exact branch sums, not just “non-zero”.

These three cases are deterministic with the current executor contract: full split/merge should produce 2.0f, and the single-branch cases should produce 1.0f. Using > 0.0f will still pass if a stale route leaks extra signal or a disconnected branch is accidentally still accumulated. src/audio/engine/audio_graph_executor.cpp:128-173 makes the expected values exact here.

Suggested assertion tightening
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 2.0f);
...
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 1.0f);
...
-  ASSERT_TRUE(output_audio[0] > 0.0f);
+  ASSERT_TRUE(output_audio[0] == 1.0f);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_audio_graph.cpp` around lines 1116 - 1142, The tests
currently assert only that output_audio[0] > 0.0f; change these to assert exact
expected branch sums per the executor contract: when both branches are active
expect 2.0f and when only a single branch is active expect 1.0f. Update the
three ASSERT_TRUE checks after executor.process(...) to use precise float
comparisons (e.g., ASSERT_FLOAT_EQ or ASSERT_NEAR with a tiny epsilon) against
2.0f or 1.0f respectively, keeping references to the same topology changes
(graph.rebuild_topology(), executor.compile(graph), executor.process(...), and
the link variables l_split_a / l_split_b) so the assertions map to the correct
cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CMakeLists.txt`:
- Around line 103-125: The config-based find_package(portaudio CONFIG QUIET)
branch sets PORTAUDIO_FOUND when TARGET portaudio exists but the subsequent
PkgConfig/pk_check_modules and manual find_path/find_library logic can overwrite
those variables; modify the fallback so the pkg_check_modules(PORTAUDIO ...) and
the manual find_path/find_library steps (and the
link_directories(${PORTAUDIO_LIBRARY_DIRS}) call) only run when the CONFIG
target was not found (e.g., wrap them in an if(NOT TARGET portaudio) or if(NOT
PORTAUDIO_FOUND) guard), preventing the CONFIG-selected target and its
PORTAUDIO_* values from being clobbered.

In `@tests/integration/test_audio_graph.cpp`:
- Around line 1099-1114: The test currently calls graph.add_link and
graph.remove_link (e.g., when creating l_in_split, l_split_a, l_split_b,
l_a_merge, l_b_merge, l_merge_amp and other link/remove calls) without checking
the return values; add assertions immediately after each mutation that validate
the operation succeeded (for example assert/EXPECT that add_link returned a
valid id and remove_link returned success/true) so the test fails fast if any
topology mutation fails and subsequent silence checks aren't masking a bad graph
shape. Ensure you add these guard assertions for every add_link/remove_link
usage in this block and the other mentioned ranges (1126-1127, 1135-1138,
1145-1147, 1155-1163).

---

Nitpick comments:
In `@tests/integration/test_audio_graph.cpp`:
- Around line 1116-1142: The tests currently assert only that output_audio[0] >
0.0f; change these to assert exact expected branch sums per the executor
contract: when both branches are active expect 2.0f and when only a single
branch is active expect 1.0f. Update the three ASSERT_TRUE checks after
executor.process(...) to use precise float comparisons (e.g., ASSERT_FLOAT_EQ or
ASSERT_NEAR with a tiny epsilon) against 2.0f or 1.0f respectively, keeping
references to the same topology changes (graph.rebuild_topology(),
executor.compile(graph), executor.process(...), and the link variables l_split_a
/ l_split_b) so the assertions map to the correct cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 092a9022-278a-426c-b0d3-3d8f986ff4ad

📥 Commits

Reviewing files that changed from the base of the PR and between 24dab4f and ab9c573.

⛔ Files ignored due to path filters (2)
  • short.wav is excluded by !**/*.wav
  • very_long_ir_file_name_that_should_be_truncated.wav is excluded by !**/*.wav
📒 Files selected for processing (3)
  • CMakeLists.txt
  • src/audio/engine/audio_graph_executor.cpp
  • tests/integration/test_audio_graph.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/audio/engine/audio_graph_executor.cpp
🛑 Comments failed to post (2)
CMakeLists.txt (1)

103-125: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- PortAudio block ---\n'
sed -n '100,145p' CMakeLists.txt

printf '\n--- PortAudio discovery statements ---\n'
rg -n 'find_package\(portaudio|pkg_check_modules\(PORTAUDIO|find_path\(PORTAUDIO_INCLUDE_DIRS|find_library\(PORTAUDIO_LIBRARIES|link_directories\(\$\{PORTAUDIO_LIBRARY_DIRS\}\)' CMakeLists.txt

Repository: sudip-mondal-2002/Amplitron

Length of output: 2499


Guard PortAudio fallback so config-target selection isn’t overwritten

The find_package(portaudio CONFIG QUIET) branch sets PORTAUDIO_FOUND when TARGET portaudio exists, but the subsequent find_package(PkgConfig QUIET) + pkg_check_modules(PORTAUDIO portaudio-2.0) runs unconditionally and can overwrite PORTAUDIO_* (libs/include dirs/library dirs), plus repeats link_directories().

Suggested fix
 find_package(portaudio CONFIG QUIET)
 if(TARGET portaudio)
     set(PORTAUDIO_FOUND TRUE)
     set(PORTAUDIO_LIBRARIES portaudio)
 else()
     find_package(PkgConfig QUIET)
     if(PkgConfig_FOUND)
         pkg_check_modules(PORTAUDIO portaudio-2.0)
     endif()
     if(NOT PORTAUDIO_FOUND)
         find_path(PORTAUDIO_INCLUDE_DIRS portaudio.h
             PATHS /usr/include /usr/local/include /opt/homebrew/include
                   "C:/ Program Files/portaudio/include"
                   "${CMAKE_SOURCE_DIR}/external/portaudio/include")
         find_library(PORTAUDIO_LIBRARIES NAMES portaudio portaudio_x64
             PATHS /usr/lib /usr/local/lib /opt/homebrew/lib
                   "C:/ Program Files/portaudio/lib"
                   "${CMAKE_SOURCE_DIR}/external/portaudio/lib")
     endif()
     if(PORTAUDIO_LIBRARY_DIRS)
         link_directories(${PORTAUDIO_LIBRARY_DIRS})
     endif()
 endif()
-
-find_package(PkgConfig QUIET)
-if(PkgConfig_FOUND)
-    pkg_check_modules(PORTAUDIO portaudio-2.0)
-endif()
-if(NOT PORTAUDIO_FOUND)
-    find_path(PORTAUDIO_INCLUDE_DIRS portaudio.h
-        PATHS /usr/include /usr/local/include /opt/homebrew/include
-              "C:/ Program Files/portaudio/include"
-              "${CMAKE_SOURCE_DIR}/external/portaudio/include")
-    find_library(PORTAUDIO_LIBRARIES NAMES portaudio portaudio_x64
-        PATHS /usr/lib /usr/local/lib /opt/homebrew/lib
-              "C:/ Program Files/portaudio/lib"
-              "${CMAKE_SOURCE_DIR}/external/portaudio/lib")
-endif()
-if(PORTAUDIO_LIBRARY_DIRS)
-    link_directories(${PORTAUDIO_LIBRARY_DIRS})
-endif()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CMakeLists.txt` around lines 103 - 125, The config-based
find_package(portaudio CONFIG QUIET) branch sets PORTAUDIO_FOUND when TARGET
portaudio exists but the subsequent PkgConfig/pk_check_modules and manual
find_path/find_library logic can overwrite those variables; modify the fallback
so the pkg_check_modules(PORTAUDIO ...) and the manual find_path/find_library
steps (and the link_directories(${PORTAUDIO_LIBRARY_DIRS}) call) only run when
the CONFIG target was not found (e.g., wrap them in an if(NOT TARGET portaudio)
or if(NOT PORTAUDIO_FOUND) guard), preventing the CONFIG-selected target and its
PORTAUDIO_* values from being clobbered.
tests/integration/test_audio_graph.cpp (1)

1099-1114: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Check every topology mutation in the test setup.

Several add_link/remove_link calls here are unchecked. If one of those mutations fails, the later silence assertions can still pass against the wrong graph shape, which makes this test a false positive.

Suggested guard assertions
-  int l_in_split = graph.add_link(nodes[0].output_pin_ids[0], nodes[1].input_pin_ids[0]);
+  int l_in_split = graph.add_link(nodes[0].output_pin_ids[0], nodes[1].input_pin_ids[0]);
+  ASSERT_TRUE(l_in_split != -1);
...
-  int l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
+  int l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
+  ASSERT_TRUE(l_split_a != -1);
...
-  int l_split_b = graph.add_link(nodes[1].output_pin_ids[1], nodes[3].input_pin_ids[0]);
+  int l_split_b = graph.add_link(nodes[1].output_pin_ids[1], nodes[3].input_pin_ids[0]);
+  ASSERT_TRUE(l_split_b != -1);
...
-  int l_a_merge = graph.add_link(nodes[2].output_pin_ids[0], nodes[4].input_pin_ids[0]);
+  int l_a_merge = graph.add_link(nodes[2].output_pin_ids[0], nodes[4].input_pin_ids[0]);
+  ASSERT_TRUE(l_a_merge != -1);
...
-  int l_b_merge = graph.add_link(nodes[3].output_pin_ids[0], nodes[4].input_pin_ids[1]);
+  int l_b_merge = graph.add_link(nodes[3].output_pin_ids[0], nodes[4].input_pin_ids[1]);
+  ASSERT_TRUE(l_b_merge != -1);
...
-  int l_merge_amp = graph.add_link(nodes[4].output_pin_ids[0], nodes[5].input_pin_ids[0]);
+  int l_merge_amp = graph.add_link(nodes[4].output_pin_ids[0], nodes[5].input_pin_ids[0]);
+  ASSERT_TRUE(l_merge_amp != -1);
...
-  graph.remove_link(l_split_a);
+  ASSERT_TRUE(graph.remove_link(l_split_a));
...
-  l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
-  graph.remove_link(l_split_b);
+  l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
+  ASSERT_TRUE(l_split_a != -1);
+  ASSERT_TRUE(graph.remove_link(l_split_b));
...
-  graph.remove_link(l_split_a);
+  ASSERT_TRUE(graph.remove_link(l_split_a));
...
-  l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
-  l_split_b = graph.add_link(nodes[1].output_pin_ids[1], nodes[3].input_pin_ids[0]);
+  l_split_a = graph.add_link(nodes[1].output_pin_ids[0], nodes[2].input_pin_ids[0]);
+  l_split_b = graph.add_link(nodes[1].output_pin_ids[1], nodes[3].input_pin_ids[0]);
+  ASSERT_TRUE(l_split_a != -1);
+  ASSERT_TRUE(l_split_b != -1);
...
-  graph.remove_link(l_a_merge);
-  graph.remove_link(l_split_b);
+  ASSERT_TRUE(graph.remove_link(l_a_merge));
+  ASSERT_TRUE(graph.remove_link(l_split_b));

Also applies to: 1126-1127, 1135-1138, 1145-1147, 1155-1163

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_audio_graph.cpp` around lines 1099 - 1114, The test
currently calls graph.add_link and graph.remove_link (e.g., when creating
l_in_split, l_split_a, l_split_b, l_a_merge, l_b_merge, l_merge_amp and other
link/remove calls) without checking the return values; add assertions
immediately after each mutation that validate the operation succeeded (for
example assert/EXPECT that add_link returned a valid id and remove_link returned
success/true) so the test fails fast if any topology mutation fails and
subsequent silence checks aren't masking a bad graph shape. Ensure you add these
guard assertions for every add_link/remove_link usage in this block and the
other mentioned ranges (1126-1127, 1135-1138, 1145-1147, 1155-1163).

@sudip-mondal-2002 sudip-mondal-2002 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohitBareja16
The starting item in the preview

Input -> cabinet sim -> amp

without any changes doesn't create outputs

please check. Please fix

Also I would prefer the starting preset to be

Input->reverb->amp

@MohitBareja16

Copy link
Copy Markdown
Collaborator Author

Check preview pr, I changed the starting preset to reverb @sudip-mondal-2002

@sudip-mondal-2002 sudip-mondal-2002 added the gssoc:approved GSSoC 2026 contribution label Jun 3, 2026
@sudip-mondal-2002 sudip-mondal-2002 merged commit d791309 into sudip-mondal-2002:main Jun 3, 2026
9 checks passed
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers gssoc:approved GSSoC 2026 contribution level:intermediate Intermediate task · 25 GSSoC points Medium mentor:sudip-mondal-2002 SSoC26 type:bug Something isn't working type:testing Unit tests, integration tests, or test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disconnected graph also creating outputs

2 participants