Repository navigation
[Feature Addition] SoundTouch #1136
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <class name="SoundTouch" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> | ||
| <brief_description> | ||
| Performs real-time audio time-stretching by adjusting playback tempo without changing pitch | ||
| </brief_description> | ||
| <description> | ||
| SoundTouch is a lightweight audio processing utility that wraps the SoundTouch library to allow tempo adjustment on raw audio samples without affecting pitch. This class is useful for gameplay-driven audio effects, dynamic music systems, or any scenario where audio tempo needs to change at runtime. | ||
| [codeblocks] | ||
| [gdscript] | ||
| var st = SoundTouch.new() | ||
|
|
||
| # Slow playback to 50% speed | ||
| st.set_tempo(0.5) | ||
| # Set the sample to mono. | ||
| st.put_samples(mono) | ||
| # Finalize buffer input. | ||
| st.flush() | ||
|
|
||
| # Obtain processed samples. | ||
| var processed := st.receive_samples() | ||
|
|
||
| # Play processed audio using AudioStreamGenerator. | ||
| var generator := AudioStreamGenerator.new() | ||
| generator.mix_rate = sample_rate | ||
| generator.buffer_length = duration | ||
|
|
||
| var player := AudioStreamPlayer.new() | ||
| add_child(player) | ||
| player.stream = generator | ||
| player.play() | ||
|
|
||
| var playback := player.get_stream_playback() | ||
| playback.push_buffer(mono_to_stereo(processed)) | ||
| [/gdscript] | ||
| [/codeblocks] | ||
| </description> | ||
| <tutorials> | ||
| </tutorials> | ||
| <methods> | ||
| <method name="flush"> | ||
| <return type="void" /> | ||
| <description> | ||
| Flushes any internally buffered samples and finalizes processing. | ||
| Call this when no more input samples will be provided. | ||
| </description> | ||
| </method> | ||
| <method name="put_samples"> | ||
| <return type="void" /> | ||
| <param index="0" name="samples" type="PackedFloat32Array" /> | ||
| <description> | ||
| Submits raw audio samples to the processor. | ||
| The samples must be mono, 32-bit floating-point PCM data at the configured sample rate. | ||
| </description> | ||
| </method> | ||
| <method name="receive_samples"> | ||
| <return type="PackedFloat32Array" /> | ||
| <description> | ||
| Retrieves processed audio samples if available. | ||
| Returns an empty array if no samples are currently ready. | ||
| </description> | ||
| </method> | ||
| <method name="set_tempo"> | ||
| <return type="void" /> | ||
| <param index="0" name="tempo" type="float" /> | ||
| <description> | ||
| Sets the playback tempo multiplier. | ||
| A value of `1.0` keeps the original tempo, values greater than `1.0` speed up playback, and values less than `1.0` slow it down. | ||
| </description> | ||
| </method> | ||
| </methods> | ||
| </class> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # ruff: noqa | ||
| Import("env") | ||
|
|
||
| soundtouch_dir = "#modules/soundtouch/soundtouch" | ||
|
|
||
| module_sources = [ | ||
| "soundtouch_module.cpp", | ||
| ] | ||
|
|
||
| soundtouch_sources = [ | ||
| "AAFilter.cpp", | ||
| "FIFOSampleBuffer.cpp", | ||
| "FIRFilter.cpp", | ||
| "InterpolateCubic.cpp", | ||
| "InterpolateLinear.cpp", | ||
| "InterpolateShannon.cpp", | ||
| "PeakFinder.cpp", | ||
| "RateTransposer.cpp", | ||
| "SoundTouch.cpp", | ||
| "TDStretch.cpp", | ||
| "cpu_detect_x86.cpp", | ||
| ] | ||
|
|
||
| optional_sources = [ | ||
| "mmx_optimized.cpp", | ||
| "sse_optimized.cpp", | ||
| ] | ||
|
|
||
| soundtouch_sources = [soundtouch_dir + "/" + s for s in soundtouch_sources] | ||
| optional_sources = [soundtouch_dir + "/" + s for s in optional_sources] | ||
|
|
||
| env.add_source_files(env.modules_sources, ["register_types.cpp"]) | ||
| env.add_source_files(env.modules_sources, module_sources) | ||
| env.add_source_files(env.modules_sources, soundtouch_sources) | ||
| env.add_source_files(env.modules_sources, optional_sources) | ||
|
|
||
| env.Append(CPPPATH=[soundtouch_dir]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| def can_build(env, platform): | ||
| return True | ||
|
|
||
|
|
||
| def configure(env): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /**************************************************************************/ | ||
| /* register_types.cpp */ | ||
| /**************************************************************************/ | ||
| /* This file is part of: */ | ||
| /* REDOT ENGINE */ | ||
| /* https://redotengine.org */ | ||
| /**************************************************************************/ | ||
| /* Copyright (c) 2024-present Redot Engine contributors */ | ||
| /* (see REDOT_AUTHORS.md) */ | ||
| /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
| /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
| /* */ | ||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | ||
| /* a copy of this software and associated documentation files (the */ | ||
| /* "Software"), to deal in the Software without restriction, including */ | ||
| /* without limitation the rights to use, copy, modify, merge, publish, */ | ||
| /* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
| /* permit persons to whom the Software is furnished to do so, subject to */ | ||
| /* the following conditions: */ | ||
| /* */ | ||
| /* The above copyright notice and this permission notice shall be */ | ||
| /* included in all copies or substantial portions of the Software. */ | ||
| /* */ | ||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
| /**************************************************************************/ | ||
|
|
||
| #include "register_types.h" | ||
| #include "core/object/class_db.h" | ||
| #include "soundtouch_module.h" | ||
|
|
||
| void initialize_soundtouch_module(ModuleInitializationLevel p_level) { | ||
| if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { | ||
| return; | ||
| } | ||
|
|
||
| ClassDB::register_class<SoundTouch>(); | ||
| } | ||
|
|
||
| void uninitialize_soundtouch_module(ModuleInitializationLevel p_level) { | ||
| if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { | ||
| return; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /**************************************************************************/ | ||
| /* register_types.h */ | ||
| /**************************************************************************/ | ||
| /* This file is part of: */ | ||
| /* REDOT ENGINE */ | ||
| /* https://redotengine.org */ | ||
| /**************************************************************************/ | ||
| /* Copyright (c) 2024-present Redot Engine contributors */ | ||
| /* (see REDOT_AUTHORS.md) */ | ||
| /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
| /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
| /* */ | ||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | ||
| /* a copy of this software and associated documentation files (the */ | ||
| /* "Software"), to deal in the Software without restriction, including */ | ||
| /* without limitation the rights to use, copy, modify, merge, publish, */ | ||
| /* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
| /* permit persons to whom the Software is furnished to do so, subject to */ | ||
| /* the following conditions: */ | ||
| /* */ | ||
| /* The above copyright notice and this permission notice shall be */ | ||
| /* included in all copies or substantial portions of the Software. */ | ||
| /* */ | ||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
| /**************************************************************************/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "modules/register_module_types.h" | ||
|
|
||
| void initialize_soundtouch_module(ModuleInitializationLevel p_level); | ||
| void uninitialize_soundtouch_module(ModuleInitializationLevel p_level); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of modifying the precommit config here?
Is the auto formatting causing breaking issues with the code for the module?