Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renderer Flush and BufferFlush methods #284

Merged
merged 11 commits into from
Nov 15, 2023
Merged

Conversation

Raffaello
Copy link
Owner

@Raffaello Raffaello commented Nov 15, 2023

Summary by CodeRabbit

  • New Features

    • Introduced a new audio rendering and flushing mechanism to improve audio processing.
    • Added new test cases to validate audio rendering functionality.
  • Improvements

    • Enhanced audio renderer interface with new capabilities for buffer flushing and track rendering.
    • Updated audio renderer implementation to handle silence detection and stream flushing more efficiently.
  • Refactor

    • Streamlined audio file handling by replacing file output functions for better clarity and performance.
  • Documentation

    • Updated project version and description to reflect new changes.
  • Tests

    • Added new tests for audio rendering to ensure quality and correctness.
  • Chores

    • General codebase maintenance and cleanup for better readability and maintainability.

@Raffaello Raffaello self-assigned this Nov 15, 2023
Copy link

coderabbitai bot commented Nov 15, 2023

The existing content is comprehensive and aligns with the provided instructions. Therefore, no modifications are necessary.


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@Raffaello Raffaello added enhancement New feature or request driver driver related file I/O file related device wrapper around drivers and hardware to represent a sound card labels Nov 15, 2023
@Raffaello Raffaello added this to In progress in OPL via automation Nov 15, 2023
@Raffaello Raffaello added this to In progress in Digital Sound via automation Nov 15, 2023
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 18b0a17 and 84d3ac2.
Files ignored due to filter (2)
  • sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_adlib_mame2.wav
  • sdl2-hyper-sonic-drivers/test/fixtures/test_renderer_sbpro2_dosbox.wav
Files selected for processing (5)
  • sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp (4 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (1 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (3 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1 hunks)
  • sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (2 hunks)
Files skipped from review due to trivial changes (1)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp
Additional comments: 4
sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (1)
  • 25-29: The addition of the renderFlush function to the IAudioRenderer interface is a significant change that will require all concrete implementations of this interface to implement the new method. This change should be communicated clearly to the team to ensure that all implementations are updated accordingly.

The inline functions added for renderBuffer and renderFlush that take a std::shared_ptr<devices::IDevice> are convenient wrappers that allow calling these functions with a device object. However, it's important to ensure that the device->getHardware()->getAudioStream() call is safe and that the device and its hardware and audioStream are guaranteed to be non-null. If there's any chance of null pointers, these calls should be guarded against dereferencing null pointers to prevent runtime crashes.

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (2)
  • 53-55: The removal of the file existence check and the deletion of the output file before the test begins is a change that could potentially affect the test's behavior. This change assumes that the file should not exist before the test starts, which is a reasonable assumption for a clean test environment. However, if the file is meant to be present as a precondition for some tests, this change could introduce issues. It's important to ensure that all tests relying on the presence or absence of this file are updated accordingly.

  • 68-69: The addition of renderFlush before closing the output file is a good practice to ensure that all buffered data is processed before the file is closed. This change aligns with the updates in the renderer implementation and should help in maintaining the consistency of the output file's data.

sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp (1)
  • 294-300: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [272-433]

The removal of the renderMixer function and the commented-out code in the rendererMIDI function indicate a significant change in how audio rendering is handled. Ensure that these changes do not leave any part of the system that depends on renderMixer or the old rendererMIDI functionality in a broken state. The addition of return 0; in the main function is a standard practice for indicating successful execution, which is good.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 84d3ac2 and fed246c.
Files selected for processing (5)
  • CMakeLists.txt (1 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1 hunks)
  • sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (3 hunks)
Files skipped from review due to trivial changes (1)
  • CMakeLists.txt
Additional comments: 7
sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1)
  • 18-25: The Renderer class has been updated to include the new renderFlush function and an overloaded renderBuffer function that accepts an additional track parameter. This change aligns with the pull request's goal to enhance audio rendering capabilities. However, it's important to ensure that all implementations of IRenderer now provide the renderFlush method, as it's a pure virtual function in the base class.

Additionally, the use of using IRenderer::renderBuffer; and using IRenderer::renderFlush; allows the class to inherit overloaded methods from the base class that are not overridden here. This is a good practice to ensure that all overloads are available to users of the Renderer class.

Ensure that the new track parameter in the renderBuffer function is properly documented and that its usage is clear to the developers. Also, verify that the implementations of these new functions are thread-safe if the Renderer class is used in a multi-threaded context.

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (3)
  • 1-5: The inclusion of <algorithm> and <ranges> headers suggests that new standard library algorithms are being used in the code, which is confirmed by the use of std::ranges::all_of in the renderFlush function. This is a good use of the C++ standard library to perform operations on ranges of data.

  • 34-35: The renderBuffer function reads from the audio stream and writes to an output file. It is important to ensure that the read variable accurately reflects the number of bytes read from the stream and that the save_streaming function is designed to handle partial writes if read is less than m_buf.size().

  • 58-66: The renderBuffer function with the track parameter is designed to play a specific track and render the audio buffer accordingly. After playing the track, it calls renderFlush to ensure that all audio data is flushed and then closes the output file. This is a good example of a function that encapsulates a complete process (playing a track, rendering, flushing, and closing the file). However, it's important to ensure that drv.isPlaying() is a reliable way to determine if the track is still playing and that it won't result in an infinite loop if, for some reason, the driver fails to update its playing state.

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (2)
  • 65-69: The loop to render the buffer until the driver is no longer playing, followed by a flush and file closure, is a logical sequence for ensuring that all audio data is processed and written. However, ensure that renderFlush and closeOutputFile are handling any potential exceptions or errors that could arise during the flushing and closing of the output file.

  • 96-129: The new test case render_wav2 is similar to the previous test render_wav but seems to be missing the loop to render the buffer while the driver is playing, which is present in the first test. This could be an oversight or intentional based on the test's purpose, but it should be verified to ensure the test is functioning as intended. Additionally, the test case does not call renderFlush or closeOutputFile, which might be necessary to ensure the rendered audio is properly finalized and written to the file.

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (1)
  • 8-12: The inclusion of new headers suggests that the interface now depends on additional components like IAudioStream, OPL, IDevice, and IAudioDriver. Ensure that these dependencies are necessary and properly managed to avoid tight coupling.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fed246c and 2563cab.
Files selected for processing (4)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1 hunks)
  • sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (3 hunks)
Additional comments: 10
sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1)
  • 15-26: The use of using declarations for renderBuffer, renderFlush, and renderBufferFlush is redundant since these functions are being overridden in this class. The using keyword is typically used to introduce a name into the current declarative region, but here, the functions are already being declared with their respective overrides. It would be best to remove these to avoid confusion and maintain clarity in the class interface.
</blockquote></details>
<details><summary>sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (2)</summary><blockquote>

* 8-12: The inclusion of new headers suggests that the interface now depends on additional components such as `IAudioStream`, `OPL`, `IDevice`, and `WAVFile`. Ensure that these dependencies are necessary and properly managed to avoid tight coupling and maintain modularity.



* 26-46: The introduction of `renderBuffer`, `renderFlush`, and `renderBufferFlush` methods, along with their inline overloads, extends the functionality of the `IRenderer` interface to handle more complex audio rendering scenarios. The inline overloads provide a convenient way to work with shared device pointers, which is a good use of modern C++ features. However, ensure that the documentation for these methods is clear and accurately describes their behavior and side effects, if any. Additionally, consider the exception safety of these methods, especially since they are interacting with hardware and file streams which can be error-prone.




</blockquote></details>
<details><summary>sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (5)</summary><blockquote>

* 4-5: The inclusion of `<algorithm>` and `<ranges>` headers is appropriate for the use of `std::ranges::all_of` in the `renderFlush` function. This is a good use of C++20 features for clean and expressive code.



* 36-37: The `renderBuffer` function writes the buffer to the output file without checking if the read was successful or if there was an error. It's important to handle potential errors from `stream->readBuffer` and `m_out->save_streaming`.



* 49-62: The `renderFlush` function uses a for-loop to iterate a fixed number of times, determined by `MaxRendererFlushIterations`. This is a safety measure to prevent potential infinite loops, which is good. However, it's important to ensure that this constant is set to a sensible value that balances performance with the need to flush the buffer completely.



* 55-57: The use of `std::ranges::all_of` to check for silence in the buffer is efficient and modern C++ practice. However, it's important to ensure that the data type of the buffer (`m_buf`) is compatible with the comparison to `0`. If `m_buf` contains floating-point samples, a direct comparison to `0` might not be appropriate due to the nature of floating-point arithmetic.



* 65-71: The `renderBufferFlush` function plays a track and then flushes the buffer. It's important to ensure that `drv.play(track)` and `drv.isPlaying()` are thread-safe and that there are no race conditions if they are called from multiple threads.



</blockquote></details>
<details><summary>sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp (2)</summary><blockquote>

* 65-86: The test case `render_wav` has been updated to include the new `renderFlush` function and additional assertions to compare the rendered audio data with expected data. This is a good practice to ensure that the new functionality is working as expected and that the audio output is correct. The loop to call `renderBuffer` until `isPlaying` returns false is a typical pattern for audio rendering tests.



* 88-107: The new test case `render_wav2` is added to test the `renderBufferFlush` function. It's good to see that the test case is following the same pattern as the previous test, ensuring consistency in how the tests are written and executed. The assertions at the end of the test case are important to verify that the audio data rendered matches the expected output.




</blockquote></details></blockquote></details>



</details>

@Raffaello Raffaello removed driver driver related file I/O file related device wrapper around drivers and hardware to represent a sound card labels Nov 15, 2023
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2563cab and 0549551.
Files selected for processing (3)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (2 hunks)
  • sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1 hunks)
Additional comments: 6
sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IRenderer.hpp (2)
  • 8-12: The inclusion of new headers should be verified to ensure they are necessary for the interface and that they do not introduce any circular dependencies or increase compilation time unnecessarily.

  • 26-43: The addition of renderFlush and renderBufferFlush methods, along with their inline overloads, is a significant enhancement. Ensure that the documentation for these methods is clear and that they are implemented correctly in derived classes. Also, verify that the inline overloads are necessary and that they do not lead to code bloat.

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.hpp (1)
  • 23-25: The renderBuffer function is overridden without changing the signature, which is good for maintaining compatibility. However, the renderFlush and renderBufferFlush functions have been updated to return bool instead of void. Ensure that all parts of the code that use these functions are updated to handle the boolean return type correctly. This change implies that the functions now indicate success or failure, which can be used for error handling.
sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp (3)
  • 4-5: The inclusion of <algorithm> and <ranges> headers is appropriate for the use of std::ranges::all_of in the renderFlush function. Ensure that these headers are not included elsewhere in the project to avoid redundancy.

  • 10-12: The comment added for MaxRendererFlushIterations is clear and explains the purpose of the constant well. This is a good practice for maintainability.

  • 67-74: The renderBufferFlush function seems to be correctly implemented, playing the track and then flushing the buffer. However, ensure that the drv.isPlaying() method is reliable and won't result in an infinite loop if, for some reason, it doesn't return false when expected.

@Raffaello Raffaello changed the title rendererer flush Renderer Flush and BufferFlush methods Nov 15, 2023
Copy link

sonarcloud bot commented Nov 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Raffaello Raffaello merged commit 2939550 into master Nov 15, 2023
9 checks passed
OPL automation moved this from In progress to Done Nov 15, 2023
Digital Sound automation moved this from In progress to Done Nov 15, 2023
@Raffaello Raffaello deleted the renderer-improvement branch November 15, 2023 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
OPL
Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant