Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ repos:
modules/gdscript/tests/scripts/parser/features/mixed_indentation_on_blank_lines\.gd|
modules/gdscript/tests/scripts/parser/warnings/empty_file_newline_comment\.norun\.gd|
modules/gdscript/tests/scripts/parser/warnings/empty_file_newline\.norun\.gd|
tests/data/.*\.bin
tests/data/.*\.bin|
modules/soundtouch/soundtouch/.*|
modules/soundtouch/SCsub
Comment on lines +210 to +212

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.

What is the purpose of modifying the precommit config here?
Is the auto formatting causing breaking issues with the code for the module?

)$

- id: dotnet-format
Expand Down
71 changes: 71 additions & 0 deletions doc/classes/SoundTouch.xml
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>
37 changes: 37 additions & 0 deletions modules/soundtouch/SCsub
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])
6 changes: 6 additions & 0 deletions modules/soundtouch/config.py
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
49 changes: 49 additions & 0 deletions modules/soundtouch/register_types.cpp
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;
}
}
38 changes: 38 additions & 0 deletions modules/soundtouch/register_types.h
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);
Loading
Loading