diff options
author | Adam Scott <ascott.ca@gmail.com> | 2024-08-20 10:29:32 -0400 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-16 17:15:29 +0200 |
commit | 219ddde30c8d6a27548d5e237e0951b9a5d8ff9f (patch) | |
tree | 4976833ba9a55948fd9bd733887c45423b379566 /platform | |
parent | 2dd696867f3087e1d95f16fd6a875331629bde99 (diff) | |
download | redot-engine-219ddde30c8d6a27548d5e237e0951b9a5d8ff9f.tar.gz |
Honor `pitch_scale` value before playing audio sample
(cherry picked from commit aaafd163b29180090161c0169c70ab2772dfdcd7)
Diffstat (limited to 'platform')
-rw-r--r-- | platform/web/audio_driver_web.cpp | 1 | ||||
-rw-r--r-- | platform/web/godot_audio.h | 2 | ||||
-rw-r--r-- | platform/web/js/libs/library_godot_audio.js | 10 |
3 files changed, 9 insertions, 4 deletions
diff --git a/platform/web/audio_driver_web.cpp b/platform/web/audio_driver_web.cpp index 5e046d7050..0108f40726 100644 --- a/platform/web/audio_driver_web.cpp +++ b/platform/web/audio_driver_web.cpp @@ -294,6 +294,7 @@ void AudioDriverWeb::start_sample_playback(const Ref<AudioSamplePlayback> &p_pla itos(p_playback->stream->get_instance_id()).utf8().get_data(), AudioServer::get_singleton()->get_bus_index(p_playback->bus), p_playback->offset, + p_playback->pitch_scale, volume_ptrw); } diff --git a/platform/web/godot_audio.h b/platform/web/godot_audio.h index 4961ebd2bb..f5a2a85605 100644 --- a/platform/web/godot_audio.h +++ b/platform/web/godot_audio.h @@ -51,7 +51,7 @@ extern void godot_audio_input_stop(); extern int godot_audio_sample_stream_is_registered(const char *p_stream_object_id); extern void godot_audio_sample_register_stream(const char *p_stream_object_id, float *p_frames_buf, int p_frames_total, const char *p_loop_mode, int p_loop_begin, int p_loop_end); extern void godot_audio_sample_unregister_stream(const char *p_stream_object_id); -extern void godot_audio_sample_start(const char *p_playback_object_id, const char *p_stream_object_id, int p_bus_index, float p_offset, float *p_volume_ptr); +extern void godot_audio_sample_start(const char *p_playback_object_id, const char *p_stream_object_id, int p_bus_index, float p_offset, float p_pitch_scale, float *p_volume_ptr); extern void godot_audio_sample_stop(const char *p_playback_object_id); extern void godot_audio_sample_set_pause(const char *p_playback_object_id, bool p_pause); extern int godot_audio_sample_is_active(const char *p_playback_object_id); diff --git a/platform/web/js/libs/library_godot_audio.js b/platform/web/js/libs/library_godot_audio.js index 0ba6eed464..40fb0c356c 100644 --- a/platform/web/js/libs/library_godot_audio.js +++ b/platform/web/js/libs/library_godot_audio.js @@ -328,6 +328,7 @@ class SampleNodeBus { * offset?: number * playbackRate?: number * startTime?: number + * pitchScale?: number * loopMode?: LoopMode * volume?: Float32Array * start?: boolean @@ -438,7 +439,7 @@ class SampleNode { /** @type {LoopMode} */ this.loopMode = options.loopMode ?? this.getSample().loopMode ?? 'disabled'; /** @type {number} */ - this._pitchScale = 1; + this._pitchScale = options.pitchScale ?? 1; /** @type {number} */ this._sourceStartTime = 0; /** @type {Map<Bus, SampleNodeBus>} */ @@ -1648,13 +1649,14 @@ const _GodotAudio = { }, godot_audio_sample_start__proxy: 'sync', - godot_audio_sample_start__sig: 'viiiii', + godot_audio_sample_start__sig: 'viiiifi', /** * Starts a sample. * @param {number} playbackObjectIdStrPtr Playback object id pointer * @param {number} streamObjectIdStrPtr Stream object id pointer * @param {number} busIndex Bus index * @param {number} offset Sample offset + * @param {number} pitchScale Pitch scale * @param {number} volumePtr Volume pointer * @returns {void} */ @@ -1663,6 +1665,7 @@ const _GodotAudio = { streamObjectIdStrPtr, busIndex, offset, + pitchScale, volumePtr ) { /** @type {string} */ @@ -1671,11 +1674,12 @@ const _GodotAudio = { const streamObjectId = GodotRuntime.parseString(streamObjectIdStrPtr); /** @type {Float32Array} */ const volume = GodotRuntime.heapSub(HEAPF32, volumePtr, 8); - /** @type {SampleNodeConstructorOptions} */ + /** @type {SampleNodeOptions} */ const startOptions = { offset, volume, playbackRate: 1, + pitchScale, start: true, }; GodotAudio.start_sample( |