Rename AudioStreamSample to a more discoverable name

This commit is contained in:
DeeJayLSP 2022-07-23 11:34:36 -03:00
parent 667cef39b4
commit 4889659227
14 changed files with 146 additions and 144 deletions

View File

@ -14,7 +14,7 @@
</tutorials> </tutorials>
<methods> <methods>
<method name="get_recording" qualifiers="const"> <method name="get_recording" qualifiers="const">
<return type="AudioStreamSample" /> <return type="AudioStreamWAV" />
<description> <description>
Returns the recorded sample. Returns the recorded sample.
</description> </description>
@ -34,8 +34,8 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamSample.Format" default="1"> <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamWAV.Format" default="1">
Specifies the format in which the sample will be recorded. See [enum AudioStreamSample.Format] for available formats. Specifies the format in which the sample will be recorded. See [enum AudioStreamWAV.Format] for available formats.
</member> </member>
</members> </members>
</class> </class>

View File

@ -4,7 +4,7 @@
Base class for audio streams. Base class for audio streams.
</brief_description> </brief_description>
<description> <description>
Base class for audio streams. Audio streams are used for sound effects and music playback, and support WAV (via [AudioStreamSample]) and OGG (via [AudioStreamOGGVorbis]) file formats. Base class for audio streams. Audio streams are used for sound effects and music playback, and support WAV (via [AudioStreamWAV]) and OGG (via [AudioStreamOGGVorbis]) file formats.
</description> </description>
<tutorials> <tutorials>
<link title="Audio streams">$DOCS_URL/tutorials/audio/audio_streams.html</link> <link title="Audio streams">$DOCS_URL/tutorials/audio/audio_streams.html</link>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="AudioStreamSample" inherits="AudioStream" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <class name="AudioStreamWAV" inherits="AudioStream" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description> <brief_description>
Stores audio data loaded from WAV files. Stores audio data loaded from WAV files.
</brief_description> </brief_description>
<description> <description>
AudioStreamSample stores sound samples loaded from WAV files. To play the stored sound, use an [AudioStreamPlayer] (for non-positional audio) or [AudioStreamPlayer2D]/[AudioStreamPlayer3D] (for positional audio). The sound can be looped. AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an [AudioStreamPlayer] (for non-positional audio) or [AudioStreamPlayer2D]/[AudioStreamPlayer3D] (for positional audio). The sound can be looped.
This class can also be used to store dynamically-generated PCM audio data. See also [AudioStreamGenerator] for procedural audio generation. This class can also be used to store dynamically-generated PCM audio data. See also [AudioStreamGenerator] for procedural audio generation.
</description> </description>
<tutorials> <tutorials>
@ -14,7 +14,7 @@
<return type="int" enum="Error" /> <return type="int" enum="Error" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />
<description> <description>
Saves the AudioStreamSample as a WAV file to [code]path[/code]. Samples with IMA ADPCM format can't be saved. Saves the AudioStreamWAV as a WAV file to [code]path[/code]. Samples with IMA ADPCM format can't be saved.
[b]Note:[/b] A [code].wav[/code] extension is automatically appended to [code]path[/code] if it is missing. [b]Note:[/b] A [code].wav[/code] extension is automatically appended to [code]path[/code] if it is missing.
</description> </description>
</method> </method>
@ -24,7 +24,7 @@
Contains the audio data in bytes. Contains the audio data in bytes.
[b]Note:[/b] This property expects signed PCM8 data. To convert unsigned PCM8 to signed PCM8, subtract 128 from each byte. [b]Note:[/b] This property expects signed PCM8 data. To convert unsigned PCM8 to signed PCM8, subtract 128 from each byte.
</member> </member>
<member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamSample.Format" default="0"> <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamWAV.Format" default="0">
Audio format. See [enum Format] constants for values. Audio format. See [enum Format] constants for values.
</member> </member>
<member name="loop_begin" type="int" setter="set_loop_begin" getter="get_loop_begin" default="0"> <member name="loop_begin" type="int" setter="set_loop_begin" getter="get_loop_begin" default="0">
@ -33,7 +33,7 @@
<member name="loop_end" type="int" setter="set_loop_end" getter="get_loop_end" default="0"> <member name="loop_end" type="int" setter="set_loop_end" getter="get_loop_end" default="0">
The loop end point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present. The loop end point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present.
</member> </member>
<member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="AudioStreamSample.LoopMode" default="0"> <member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="AudioStreamWAV.LoopMode" default="0">
The loop mode. This information will be imported automatically from the WAV file if present. See [enum LoopMode] constants for values. The loop mode. This information will be imported automatically from the WAV file if present. See [enum LoopMode] constants for values.
</member> </member>
<member name="mix_rate" type="int" setter="set_mix_rate" getter="get_mix_rate" default="44100"> <member name="mix_rate" type="int" setter="set_mix_rate" getter="get_mix_rate" default="44100">

View File

@ -100,7 +100,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
extension_guess["tga"] = tree->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")); extension_guess["tga"] = tree->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons"));
extension_guess["webp"] = tree->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")); extension_guess["webp"] = tree->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons"));
extension_guess["wav"] = tree->get_theme_icon(SNAME("AudioStreamSample"), SNAME("EditorIcons")); extension_guess["wav"] = tree->get_theme_icon(SNAME("AudioStreamWAV"), SNAME("EditorIcons"));
extension_guess["ogg"] = tree->get_theme_icon(SNAME("AudioStreamOGGVorbis"), SNAME("EditorIcons")); extension_guess["ogg"] = tree->get_theme_icon(SNAME("AudioStreamOGGVorbis"), SNAME("EditorIcons"));
extension_guess["mp3"] = tree->get_theme_icon(SNAME("AudioStreamMP3"), SNAME("EditorIcons")); extension_guess["mp3"] = tree->get_theme_icon(SNAME("AudioStreamMP3"), SNAME("EditorIcons"));

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -33,7 +33,7 @@
#include "core/io/file_access.h" #include "core/io/file_access.h"
#include "core/io/marshalls.h" #include "core/io/marshalls.h"
#include "core/io/resource_saver.h" #include "core/io/resource_saver.h"
#include "scene/resources/audio_stream_sample.h" #include "scene/resources/audio_stream_wav.h"
const float TRIM_DB_LIMIT = -50; const float TRIM_DB_LIMIT = -50;
const int TRIM_FADE_OUT_FRAMES = 500; const int TRIM_FADE_OUT_FRAMES = 500;
@ -55,7 +55,7 @@ String ResourceImporterWAV::get_save_extension() const {
} }
String ResourceImporterWAV::get_resource_type() const { String ResourceImporterWAV::get_resource_type() const {
return "AudioStreamSample"; return "AudioStreamWAV";
} }
bool ResourceImporterWAV::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const { bool ResourceImporterWAV::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@ -86,7 +86,7 @@ void ResourceImporterWAV::get_import_options(const String &p_path, List<ImportOp
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_RANGE, "11025,192000,1,exp"), 44100)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_RANGE, "11025,192000,1,exp"), 44100));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/trim"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/trim"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/normalize"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/normalize"), false));
// Keep the `edit/loop_mode` enum in sync with AudioStreamSample::LoopMode (note: +1 offset due to "Detect From WAV"). // Keep the `edit/loop_mode` enum in sync with AudioStreamWAV::LoopMode (note: +1 offset due to "Detect From WAV").
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_mode", PROPERTY_HINT_ENUM, "Detect From WAV,Disabled,Forward,Ping-Pong,Backward", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_mode", PROPERTY_HINT_ENUM, "Detect From WAV,Disabled,Forward,Ping-Pong,Backward", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_begin"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_begin"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_end"), -1)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_end"), -1));
@ -130,7 +130,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
int format_bits = 0; int format_bits = 0;
int format_channels = 0; int format_channels = 0;
AudioStreamSample::LoopMode loop_mode = AudioStreamSample::LOOP_DISABLED; AudioStreamWAV::LoopMode loop_mode = AudioStreamWAV::LOOP_DISABLED;
uint16_t compression_code = 1; uint16_t compression_code = 1;
bool format_found = false; bool format_found = false;
bool data_found = false; bool data_found = false;
@ -282,11 +282,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
int loop_type = file->get_32(); int loop_type = file->get_32();
if (loop_type == 0x00 || loop_type == 0x01 || loop_type == 0x02) { if (loop_type == 0x00 || loop_type == 0x01 || loop_type == 0x02) {
if (loop_type == 0x00) { if (loop_type == 0x00) {
loop_mode = AudioStreamSample::LOOP_FORWARD; loop_mode = AudioStreamWAV::LOOP_FORWARD;
} else if (loop_type == 0x01) { } else if (loop_type == 0x01) {
loop_mode = AudioStreamSample::LOOP_PINGPONG; loop_mode = AudioStreamWAV::LOOP_PINGPONG;
} else if (loop_type == 0x02) { } else if (loop_type == 0x02) {
loop_mode = AudioStreamSample::LOOP_BACKWARD; loop_mode = AudioStreamWAV::LOOP_BACKWARD;
} }
loop_begin = file->get_32(); loop_begin = file->get_32();
loop_end = file->get_32(); loop_end = file->get_32();
@ -386,7 +386,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
bool trim = p_options["edit/trim"]; bool trim = p_options["edit/trim"];
if (trim && (loop_mode != AudioStreamSample::LOOP_DISABLED) && format_channels > 0) { if (trim && (loop_mode != AudioStreamWAV::LOOP_DISABLED) && format_channels > 0) {
int first = 0; int first = 0;
int last = (frames / format_channels) - 1; int last = (frames / format_channels) - 1;
bool found = false; bool found = false;
@ -431,7 +431,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
} }
if (import_loop_mode >= 2) { if (import_loop_mode >= 2) {
loop_mode = (AudioStreamSample::LoopMode)(import_loop_mode - 1); loop_mode = (AudioStreamWAV::LoopMode)(import_loop_mode - 1);
loop_begin = p_options["edit/loop_begin"]; loop_begin = p_options["edit/loop_begin"];
loop_end = p_options["edit/loop_end"]; loop_end = p_options["edit/loop_end"];
// Wrap around to max frames, so `-1` can be used to select the end, etc. // Wrap around to max frames, so `-1` can be used to select the end, etc.
@ -463,10 +463,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
} }
Vector<uint8_t> dst_data; Vector<uint8_t> dst_data;
AudioStreamSample::Format dst_format; AudioStreamWAV::Format dst_format;
if (compression == 1) { if (compression == 1) {
dst_format = AudioStreamSample::FORMAT_IMA_ADPCM; dst_format = AudioStreamWAV::FORMAT_IMA_ADPCM;
if (format_channels == 1) { if (format_channels == 1) {
_compress_ima_adpcm(data, dst_data); _compress_ima_adpcm(data, dst_data);
} else { } else {
@ -503,7 +503,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
} }
} else { } else {
dst_format = is16 ? AudioStreamSample::FORMAT_16_BITS : AudioStreamSample::FORMAT_8_BITS; dst_format = is16 ? AudioStreamWAV::FORMAT_16_BITS : AudioStreamWAV::FORMAT_8_BITS;
dst_data.resize(data.size() * (is16 ? 2 : 1)); dst_data.resize(data.size() * (is16 ? 2 : 1));
{ {
uint8_t *w = dst_data.ptrw(); uint8_t *w = dst_data.ptrw();
@ -521,7 +521,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
} }
} }
Ref<AudioStreamSample> sample; Ref<AudioStreamWAV> sample;
sample.instantiate(); sample.instantiate();
sample->set_data(dst_data); sample->set_data(dst_data);
sample->set_format(dst_format); sample->set_format(dst_format);

View File

@ -120,7 +120,7 @@ static const char *enum_renames[][2] = {
{ "JOINT_PIN", "JOINT_TYPE_PIN" }, // PhysicsServer2D { "JOINT_PIN", "JOINT_TYPE_PIN" }, // PhysicsServer2D
{ "JOINT_SLIDER", "JOINT_TYPE_SLIDER" }, // PhysicsServer3D { "JOINT_SLIDER", "JOINT_TYPE_SLIDER" }, // PhysicsServer3D
{ "KEY_CONTROL", "KEY_CTRL" }, // Globals { "KEY_CONTROL", "KEY_CTRL" }, // Globals
{ "LOOP_PING_PONG", "LOOP_PINGPONG" }, //AudioStreamSample { "LOOP_PING_PONG", "LOOP_PINGPONG" }, // AudioStreamWAV
{ "MATH_RAND", "MATH_RANDF_RANGE" }, // VisualScriptBuiltinFunc { "MATH_RAND", "MATH_RANDF_RANGE" }, // VisualScriptBuiltinFunc
{ "MATH_RANDOM", "MATH_RANDI_RANGE" }, // VisualScriptBuiltinFunc { "MATH_RANDOM", "MATH_RANDI_RANGE" }, // VisualScriptBuiltinFunc
{ "MATH_STEPIFY", "MATH_STEP_DECIMALS" }, // VisualScriptBuiltinFunc { "MATH_STEPIFY", "MATH_STEP_DECIMALS" }, // VisualScriptBuiltinFunc
@ -1251,6 +1251,7 @@ static const char *class_renames[][2] = {
{ "AnimationTreePlayer", "AnimationTree" }, { "AnimationTreePlayer", "AnimationTree" },
{ "Area", "Area3D" }, // Be careful, this will be used everywhere { "Area", "Area3D" }, // Be careful, this will be used everywhere
{ "AudioStreamRandomPitch", "AudioStreamRandomizer" }, { "AudioStreamRandomPitch", "AudioStreamRandomizer" },
{ "AudioStreamSample", "AudioStreamWAV" },
{ "BakedLightmap", "LightmapGI" }, { "BakedLightmap", "LightmapGI" },
{ "BakedLightmapData", "LightmapGIData" }, { "BakedLightmapData", "LightmapGIData" },
{ "BitmapFont", "FontFile" }, { "BitmapFont", "FontFile" },

View File

@ -141,7 +141,7 @@
#include "scene/multiplayer/scene_replication_interface.h" #include "scene/multiplayer/scene_replication_interface.h"
#include "scene/multiplayer/scene_rpc_interface.h" #include "scene/multiplayer/scene_rpc_interface.h"
#include "scene/resources/animation_library.h" #include "scene/resources/animation_library.h"
#include "scene/resources/audio_stream_sample.h" #include "scene/resources/audio_stream_wav.h"
#include "scene/resources/bit_map.h" #include "scene/resources/bit_map.h"
#include "scene/resources/bone_map.h" #include "scene/resources/bone_map.h"
#include "scene/resources/box_shape_3d.h" #include "scene/resources/box_shape_3d.h"
@ -903,7 +903,7 @@ void register_scene_types() {
GDREGISTER_CLASS(AudioStreamPlayer3D); GDREGISTER_CLASS(AudioStreamPlayer3D);
#endif #endif
GDREGISTER_ABSTRACT_CLASS(VideoStream); GDREGISTER_ABSTRACT_CLASS(VideoStream);
GDREGISTER_CLASS(AudioStreamSample); GDREGISTER_CLASS(AudioStreamWAV);
OS::get_singleton()->yield(); // may take time to init OS::get_singleton()->yield(); // may take time to init
@ -1090,6 +1090,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("World", "World3D"); ClassDB::add_compatibility_class("World", "World3D");
// Renamed during 4.0 alpha, added to ease transition between alphas. // Renamed during 4.0 alpha, added to ease transition between alphas.
ClassDB::add_compatibility_class("AudioStreamSample", "AudioStreamWAV");
ClassDB::add_compatibility_class("StreamCubemap", "CompressedCubemap"); ClassDB::add_compatibility_class("StreamCubemap", "CompressedCubemap");
ClassDB::add_compatibility_class("StreamCubemapArray", "CompressedCubemapArray"); ClassDB::add_compatibility_class("StreamCubemapArray", "CompressedCubemapArray");
ClassDB::add_compatibility_class("StreamTexture2D", "CompressedTexture2D"); ClassDB::add_compatibility_class("StreamTexture2D", "CompressedTexture2D");

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* audio_stream_sample.cpp */ /* audio_stream_wav.cpp */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -28,13 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "audio_stream_sample.h" #include "audio_stream_wav.h"
#include "core/io/file_access.h" #include "core/io/file_access.h"
#include "core/io/marshalls.h" #include "core/io/marshalls.h"
void AudioStreamPlaybackSample::start(float p_from_pos) { void AudioStreamPlaybackWAV::start(float p_from_pos) {
if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) { if (base->format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
//no seeking in IMA_ADPCM //no seeking in IMA_ADPCM
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
ima_adpcm[i].step_index = 0; ima_adpcm[i].step_index = 0;
@ -55,24 +55,24 @@ void AudioStreamPlaybackSample::start(float p_from_pos) {
active = true; active = true;
} }
void AudioStreamPlaybackSample::stop() { void AudioStreamPlaybackWAV::stop() {
active = false; active = false;
} }
bool AudioStreamPlaybackSample::is_playing() const { bool AudioStreamPlaybackWAV::is_playing() const {
return active; return active;
} }
int AudioStreamPlaybackSample::get_loop_count() const { int AudioStreamPlaybackWAV::get_loop_count() const {
return 0; return 0;
} }
float AudioStreamPlaybackSample::get_playback_position() const { float AudioStreamPlaybackWAV::get_playback_position() const {
return float(offset >> MIX_FRAC_BITS) / base->mix_rate; return float(offset >> MIX_FRAC_BITS) / base->mix_rate;
} }
void AudioStreamPlaybackSample::seek(float p_time) { void AudioStreamPlaybackWAV::seek(float p_time) {
if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) { if (base->format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
return; //no seeking in ima-adpcm return; //no seeking in ima-adpcm
} }
@ -87,7 +87,7 @@ void AudioStreamPlaybackSample::seek(float p_time) {
} }
template <class Depth, bool is_stereo, bool is_ima_adpcm> template <class Depth, bool is_stereo, bool is_ima_adpcm>
void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm) { void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm) {
// this function will be compiled branchless by any decent compiler // this function will be compiled branchless by any decent compiler
int32_t final, final_r, next, next_r; int32_t final, final_r, next, next_r;
@ -124,7 +124,7 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
ima_adpcm[i].last_nibble++; ima_adpcm[i].last_nibble++;
const uint8_t *src_ptr = (const uint8_t *)base->data; const uint8_t *src_ptr = (const uint8_t *)base->data;
src_ptr += AudioStreamSample::DATA_PAD; src_ptr += AudioStreamWAV::DATA_PAD;
uint8_t nbb = src_ptr[(ima_adpcm[i].last_nibble >> 1) * (is_stereo ? 2 : 1) + i]; uint8_t nbb = src_ptr[(ima_adpcm[i].last_nibble >> 1) * (is_stereo ? 2 : 1) + i];
nibble = (ima_adpcm[i].last_nibble & 1) ? (nbb >> 4) : (nbb & 0xF); nibble = (ima_adpcm[i].last_nibble & 1) ? (nbb >> 4) : (nbb & 0xF);
@ -221,7 +221,7 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
} }
} }
int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
if (!base->data || !active) { if (!base->data || !active) {
for (int i = 0; i < p_frames; i++) { for (int i = 0; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0, 0); p_buffer[i] = AudioFrame(0, 0);
@ -231,13 +231,13 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
int len = base->data_bytes; int len = base->data_bytes;
switch (base->format) { switch (base->format) {
case AudioStreamSample::FORMAT_8_BITS: case AudioStreamWAV::FORMAT_8_BITS:
len /= 1; len /= 1;
break; break;
case AudioStreamSample::FORMAT_16_BITS: case AudioStreamWAV::FORMAT_16_BITS:
len /= 2; len /= 2;
break; break;
case AudioStreamSample::FORMAT_IMA_ADPCM: case AudioStreamWAV::FORMAT_IMA_ADPCM:
len *= 2; len *= 2;
break; break;
} }
@ -251,13 +251,13 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
int64_t loop_begin_fp = ((int64_t)base->loop_begin << MIX_FRAC_BITS); int64_t loop_begin_fp = ((int64_t)base->loop_begin << MIX_FRAC_BITS);
int64_t loop_end_fp = ((int64_t)base->loop_end << MIX_FRAC_BITS); int64_t loop_end_fp = ((int64_t)base->loop_end << MIX_FRAC_BITS);
int64_t length_fp = ((int64_t)len << MIX_FRAC_BITS); int64_t length_fp = ((int64_t)len << MIX_FRAC_BITS);
int64_t begin_limit = (base->loop_mode != AudioStreamSample::LOOP_DISABLED) ? loop_begin_fp : 0; int64_t begin_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_begin_fp : 0;
int64_t end_limit = (base->loop_mode != AudioStreamSample::LOOP_DISABLED) ? loop_end_fp : length_fp; int64_t end_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_end_fp : length_fp;
bool is_stereo = base->stereo; bool is_stereo = base->stereo;
int32_t todo = p_frames; int32_t todo = p_frames;
if (base->loop_mode == AudioStreamSample::LOOP_BACKWARD) { if (base->loop_mode == AudioStreamWAV::LOOP_BACKWARD) {
sign = -1; sign = -1;
} }
@ -271,20 +271,20 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
//looping //looping
AudioStreamSample::LoopMode loop_format = base->loop_mode; AudioStreamWAV::LoopMode loop_format = base->loop_mode;
AudioStreamSample::Format format = base->format; AudioStreamWAV::Format format = base->format;
/* audio data */ /* audio data */
uint8_t *dataptr = (uint8_t *)base->data; uint8_t *dataptr = (uint8_t *)base->data;
const void *data = dataptr + AudioStreamSample::DATA_PAD; const void *data = dataptr + AudioStreamWAV::DATA_PAD;
AudioFrame *dst_buff = p_buffer; AudioFrame *dst_buff = p_buffer;
if (format == AudioStreamSample::FORMAT_IMA_ADPCM) { if (format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
if (loop_format != AudioStreamSample::LOOP_DISABLED) { if (loop_format != AudioStreamWAV::LOOP_DISABLED) {
ima_adpcm[0].loop_pos = loop_begin_fp >> MIX_FRAC_BITS; ima_adpcm[0].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
ima_adpcm[1].loop_pos = loop_begin_fp >> MIX_FRAC_BITS; ima_adpcm[1].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
loop_format = AudioStreamSample::LOOP_FORWARD; loop_format = AudioStreamWAV::LOOP_FORWARD;
} }
} }
@ -297,9 +297,9 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
if (increment < 0) { if (increment < 0) {
/* going backwards */ /* going backwards */
if (loop_format != AudioStreamSample::LOOP_DISABLED && offset < loop_begin_fp) { if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset < loop_begin_fp) {
/* loopstart reached */ /* loopstart reached */
if (loop_format == AudioStreamSample::LOOP_PINGPONG) { if (loop_format == AudioStreamWAV::LOOP_PINGPONG) {
/* bounce ping pong */ /* bounce ping pong */
offset = loop_begin_fp + (loop_begin_fp - offset); offset = loop_begin_fp + (loop_begin_fp - offset);
increment = -increment; increment = -increment;
@ -317,10 +317,10 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
} }
} else { } else {
/* going forward */ /* going forward */
if (loop_format != AudioStreamSample::LOOP_DISABLED && offset >= loop_end_fp) { if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset >= loop_end_fp) {
/* loopend reached */ /* loopend reached */
if (loop_format == AudioStreamSample::LOOP_PINGPONG) { if (loop_format == AudioStreamWAV::LOOP_PINGPONG) {
/* bounce ping pong */ /* bounce ping pong */
offset = loop_end_fp - (offset - loop_end_fp); offset = loop_end_fp - (offset - loop_end_fp);
increment = -increment; increment = -increment;
@ -328,7 +328,7 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
} else { } else {
/* go to loop-begin */ /* go to loop-begin */
if (format == AudioStreamSample::FORMAT_IMA_ADPCM) { if (format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
ima_adpcm[i].step_index = ima_adpcm[i].loop_step_index; ima_adpcm[i].step_index = ima_adpcm[i].loop_step_index;
ima_adpcm[i].predictor = ima_adpcm[i].loop_predictor; ima_adpcm[i].predictor = ima_adpcm[i].loop_predictor;
@ -366,14 +366,14 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
todo -= target; todo -= target;
switch (base->format) { switch (base->format) {
case AudioStreamSample::FORMAT_8_BITS: { case AudioStreamWAV::FORMAT_8_BITS: {
if (is_stereo) { if (is_stereo) {
do_resample<int8_t, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); do_resample<int8_t, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
} else { } else {
do_resample<int8_t, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); do_resample<int8_t, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
} }
} break; } break;
case AudioStreamSample::FORMAT_16_BITS: { case AudioStreamWAV::FORMAT_16_BITS: {
if (is_stereo) { if (is_stereo) {
do_resample<int16_t, true, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm); do_resample<int16_t, true, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm);
} else { } else {
@ -381,7 +381,7 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
} }
} break; } break;
case AudioStreamSample::FORMAT_IMA_ADPCM: { case AudioStreamWAV::FORMAT_IMA_ADPCM: {
if (is_stereo) { if (is_stereo) {
do_resample<int8_t, true, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); do_resample<int8_t, true, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
} else { } else {
@ -406,73 +406,73 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
return p_frames; return p_frames;
} }
void AudioStreamPlaybackSample::tag_used_streams() { void AudioStreamPlaybackWAV::tag_used_streams() {
base->tag_used(get_playback_position()); base->tag_used(get_playback_position());
} }
AudioStreamPlaybackSample::AudioStreamPlaybackSample() {} AudioStreamPlaybackWAV::AudioStreamPlaybackWAV() {}
///////////////////// /////////////////////
void AudioStreamSample::set_format(Format p_format) { void AudioStreamWAV::set_format(Format p_format) {
format = p_format; format = p_format;
} }
AudioStreamSample::Format AudioStreamSample::get_format() const { AudioStreamWAV::Format AudioStreamWAV::get_format() const {
return format; return format;
} }
void AudioStreamSample::set_loop_mode(LoopMode p_loop_mode) { void AudioStreamWAV::set_loop_mode(LoopMode p_loop_mode) {
loop_mode = p_loop_mode; loop_mode = p_loop_mode;
} }
AudioStreamSample::LoopMode AudioStreamSample::get_loop_mode() const { AudioStreamWAV::LoopMode AudioStreamWAV::get_loop_mode() const {
return loop_mode; return loop_mode;
} }
void AudioStreamSample::set_loop_begin(int p_frame) { void AudioStreamWAV::set_loop_begin(int p_frame) {
loop_begin = p_frame; loop_begin = p_frame;
} }
int AudioStreamSample::get_loop_begin() const { int AudioStreamWAV::get_loop_begin() const {
return loop_begin; return loop_begin;
} }
void AudioStreamSample::set_loop_end(int p_frame) { void AudioStreamWAV::set_loop_end(int p_frame) {
loop_end = p_frame; loop_end = p_frame;
} }
int AudioStreamSample::get_loop_end() const { int AudioStreamWAV::get_loop_end() const {
return loop_end; return loop_end;
} }
void AudioStreamSample::set_mix_rate(int p_hz) { void AudioStreamWAV::set_mix_rate(int p_hz) {
ERR_FAIL_COND(p_hz == 0); ERR_FAIL_COND(p_hz == 0);
mix_rate = p_hz; mix_rate = p_hz;
} }
int AudioStreamSample::get_mix_rate() const { int AudioStreamWAV::get_mix_rate() const {
return mix_rate; return mix_rate;
} }
void AudioStreamSample::set_stereo(bool p_enable) { void AudioStreamWAV::set_stereo(bool p_enable) {
stereo = p_enable; stereo = p_enable;
} }
bool AudioStreamSample::is_stereo() const { bool AudioStreamWAV::is_stereo() const {
return stereo; return stereo;
} }
float AudioStreamSample::get_length() const { float AudioStreamWAV::get_length() const {
int len = data_bytes; int len = data_bytes;
switch (format) { switch (format) {
case AudioStreamSample::FORMAT_8_BITS: case AudioStreamWAV::FORMAT_8_BITS:
len /= 1; len /= 1;
break; break;
case AudioStreamSample::FORMAT_16_BITS: case AudioStreamWAV::FORMAT_16_BITS:
len /= 2; len /= 2;
break; break;
case AudioStreamSample::FORMAT_IMA_ADPCM: case AudioStreamWAV::FORMAT_IMA_ADPCM:
len *= 2; len *= 2;
break; break;
} }
@ -484,11 +484,11 @@ float AudioStreamSample::get_length() const {
return float(len) / mix_rate; return float(len) / mix_rate;
} }
bool AudioStreamSample::is_monophonic() const { bool AudioStreamWAV::is_monophonic() const {
return false; return false;
} }
void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { void AudioStreamWAV::set_data(const Vector<uint8_t> &p_data) {
AudioServer::get_singleton()->lock(); AudioServer::get_singleton()->lock();
if (data) { if (data) {
memfree(data); memfree(data);
@ -510,7 +510,7 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) {
AudioServer::get_singleton()->unlock(); AudioServer::get_singleton()->unlock();
} }
Vector<uint8_t> AudioStreamSample::get_data() const { Vector<uint8_t> AudioStreamWAV::get_data() const {
Vector<uint8_t> pv; Vector<uint8_t> pv;
if (data) { if (data) {
@ -525,8 +525,8 @@ Vector<uint8_t> AudioStreamSample::get_data() const {
return pv; return pv;
} }
Error AudioStreamSample::save_to_wav(const String &p_path) { Error AudioStreamWAV::save_to_wav(const String &p_path) {
if (format == AudioStreamSample::FORMAT_IMA_ADPCM) { if (format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
WARN_PRINT("Saving IMA_ADPC samples are not supported yet"); WARN_PRINT("Saving IMA_ADPC samples are not supported yet");
return ERR_UNAVAILABLE; return ERR_UNAVAILABLE;
} }
@ -544,13 +544,13 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
int byte_pr_sample = 0; int byte_pr_sample = 0;
switch (format) { switch (format) {
case AudioStreamSample::FORMAT_8_BITS: case AudioStreamWAV::FORMAT_8_BITS:
byte_pr_sample = 1; byte_pr_sample = 1;
break; break;
case AudioStreamSample::FORMAT_16_BITS: case AudioStreamWAV::FORMAT_16_BITS:
byte_pr_sample = 2; byte_pr_sample = 2;
break; break;
case AudioStreamSample::FORMAT_IMA_ADPCM: case AudioStreamWAV::FORMAT_IMA_ADPCM:
byte_pr_sample = 4; byte_pr_sample = 4;
break; break;
} }
@ -583,19 +583,19 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
Vector<uint8_t> data = get_data(); Vector<uint8_t> data = get_data();
const uint8_t *read_data = data.ptr(); const uint8_t *read_data = data.ptr();
switch (format) { switch (format) {
case AudioStreamSample::FORMAT_8_BITS: case AudioStreamWAV::FORMAT_8_BITS:
for (unsigned int i = 0; i < data_bytes; i++) { for (unsigned int i = 0; i < data_bytes; i++) {
uint8_t data_point = (read_data[i] + 128); uint8_t data_point = (read_data[i] + 128);
file->store_8(data_point); file->store_8(data_point);
} }
break; break;
case AudioStreamSample::FORMAT_16_BITS: case AudioStreamWAV::FORMAT_16_BITS:
for (unsigned int i = 0; i < data_bytes / 2; i++) { for (unsigned int i = 0; i < data_bytes / 2; i++) {
uint16_t data_point = decode_uint16(&read_data[i * 2]); uint16_t data_point = decode_uint16(&read_data[i * 2]);
file->store_16(data_point); file->store_16(data_point);
} }
break; break;
case AudioStreamSample::FORMAT_IMA_ADPCM: case AudioStreamWAV::FORMAT_IMA_ADPCM:
//Unimplemented //Unimplemented
break; break;
} }
@ -603,40 +603,40 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
return OK; return OK;
} }
Ref<AudioStreamPlayback> AudioStreamSample::instantiate_playback() { Ref<AudioStreamPlayback> AudioStreamWAV::instantiate_playback() {
Ref<AudioStreamPlaybackSample> sample; Ref<AudioStreamPlaybackWAV> sample;
sample.instantiate(); sample.instantiate();
sample->base = Ref<AudioStreamSample>(this); sample->base = Ref<AudioStreamWAV>(this);
return sample; return sample;
} }
String AudioStreamSample::get_stream_name() const { String AudioStreamWAV::get_stream_name() const {
return ""; return "";
} }
void AudioStreamSample::_bind_methods() { void AudioStreamWAV::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamSample::set_data); ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamWAV::set_data);
ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamSample::get_data); ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamWAV::get_data);
ClassDB::bind_method(D_METHOD("set_format", "format"), &AudioStreamSample::set_format); ClassDB::bind_method(D_METHOD("set_format", "format"), &AudioStreamWAV::set_format);
ClassDB::bind_method(D_METHOD("get_format"), &AudioStreamSample::get_format); ClassDB::bind_method(D_METHOD("get_format"), &AudioStreamWAV::get_format);
ClassDB::bind_method(D_METHOD("set_loop_mode", "loop_mode"), &AudioStreamSample::set_loop_mode); ClassDB::bind_method(D_METHOD("set_loop_mode", "loop_mode"), &AudioStreamWAV::set_loop_mode);
ClassDB::bind_method(D_METHOD("get_loop_mode"), &AudioStreamSample::get_loop_mode); ClassDB::bind_method(D_METHOD("get_loop_mode"), &AudioStreamWAV::get_loop_mode);
ClassDB::bind_method(D_METHOD("set_loop_begin", "loop_begin"), &AudioStreamSample::set_loop_begin); ClassDB::bind_method(D_METHOD("set_loop_begin", "loop_begin"), &AudioStreamWAV::set_loop_begin);
ClassDB::bind_method(D_METHOD("get_loop_begin"), &AudioStreamSample::get_loop_begin); ClassDB::bind_method(D_METHOD("get_loop_begin"), &AudioStreamWAV::get_loop_begin);
ClassDB::bind_method(D_METHOD("set_loop_end", "loop_end"), &AudioStreamSample::set_loop_end); ClassDB::bind_method(D_METHOD("set_loop_end", "loop_end"), &AudioStreamWAV::set_loop_end);
ClassDB::bind_method(D_METHOD("get_loop_end"), &AudioStreamSample::get_loop_end); ClassDB::bind_method(D_METHOD("get_loop_end"), &AudioStreamWAV::get_loop_end);
ClassDB::bind_method(D_METHOD("set_mix_rate", "mix_rate"), &AudioStreamSample::set_mix_rate); ClassDB::bind_method(D_METHOD("set_mix_rate", "mix_rate"), &AudioStreamWAV::set_mix_rate);
ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioStreamSample::get_mix_rate); ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioStreamWAV::get_mix_rate);
ClassDB::bind_method(D_METHOD("set_stereo", "stereo"), &AudioStreamSample::set_stereo); ClassDB::bind_method(D_METHOD("set_stereo", "stereo"), &AudioStreamWAV::set_stereo);
ClassDB::bind_method(D_METHOD("is_stereo"), &AudioStreamSample::is_stereo); ClassDB::bind_method(D_METHOD("is_stereo"), &AudioStreamWAV::is_stereo);
ClassDB::bind_method(D_METHOD("save_to_wav", "path"), &AudioStreamSample::save_to_wav); ClassDB::bind_method(D_METHOD("save_to_wav", "path"), &AudioStreamWAV::save_to_wav);
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_data", "get_data");
ADD_PROPERTY(PropertyInfo(Variant::INT, "format", PROPERTY_HINT_ENUM, "8-Bit,16-Bit,IMA-ADPCM"), "set_format", "get_format"); ADD_PROPERTY(PropertyInfo(Variant::INT, "format", PROPERTY_HINT_ENUM, "8-Bit,16-Bit,IMA-ADPCM"), "set_format", "get_format");
@ -656,9 +656,9 @@ void AudioStreamSample::_bind_methods() {
BIND_ENUM_CONSTANT(LOOP_BACKWARD); BIND_ENUM_CONSTANT(LOOP_BACKWARD);
} }
AudioStreamSample::AudioStreamSample() {} AudioStreamWAV::AudioStreamWAV() {}
AudioStreamSample::~AudioStreamSample() { AudioStreamWAV::~AudioStreamWAV() {
if (data) { if (data) {
memfree(data); memfree(data);
data = nullptr; data = nullptr;

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* audio_stream_sample.h */ /* audio_stream_wav.h */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -28,15 +28,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifndef AUDIO_STREAM_SAMPLE_H #ifndef AUDIO_STREAM_WAV_H
#define AUDIO_STREAM_SAMPLE_H #define AUDIO_STREAM_WAV_H
#include "servers/audio/audio_stream.h" #include "servers/audio/audio_stream.h"
class AudioStreamSample; class AudioStreamWAV;
class AudioStreamPlaybackSample : public AudioStreamPlayback { class AudioStreamPlaybackWAV : public AudioStreamPlayback {
GDCLASS(AudioStreamPlaybackSample, AudioStreamPlayback); GDCLASS(AudioStreamPlaybackWAV, AudioStreamPlayback);
enum { enum {
MIX_FRAC_BITS = 13, MIX_FRAC_BITS = 13,
MIX_FRAC_LEN = (1 << MIX_FRAC_BITS), MIX_FRAC_LEN = (1 << MIX_FRAC_BITS),
@ -57,8 +57,8 @@ class AudioStreamPlaybackSample : public AudioStreamPlayback {
int64_t offset = 0; int64_t offset = 0;
int sign = 1; int sign = 1;
bool active = false; bool active = false;
friend class AudioStreamSample; friend class AudioStreamWAV;
Ref<AudioStreamSample> base; Ref<AudioStreamWAV> base;
template <class Depth, bool is_stereo, bool is_ima_adpcm> template <class Depth, bool is_stereo, bool is_ima_adpcm>
void do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm); void do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm);
@ -77,11 +77,11 @@ public:
virtual void tag_used_streams() override; virtual void tag_used_streams() override;
AudioStreamPlaybackSample(); AudioStreamPlaybackWAV();
}; };
class AudioStreamSample : public AudioStream { class AudioStreamWAV : public AudioStream {
GDCLASS(AudioStreamSample, AudioStream); GDCLASS(AudioStreamWAV, AudioStream);
RES_BASE_EXTENSION("sample") RES_BASE_EXTENSION("sample")
public: public:
@ -100,7 +100,7 @@ public:
}; };
private: private:
friend class AudioStreamPlaybackSample; friend class AudioStreamPlaybackWAV;
enum { enum {
DATA_PAD = 16 //padding for interpolation DATA_PAD = 16 //padding for interpolation
@ -149,11 +149,11 @@ public:
virtual Ref<AudioStreamPlayback> instantiate_playback() override; virtual Ref<AudioStreamPlayback> instantiate_playback() override;
virtual String get_stream_name() const override; virtual String get_stream_name() const override;
AudioStreamSample(); AudioStreamWAV();
~AudioStreamSample(); ~AudioStreamWAV();
}; };
VARIANT_ENUM_CAST(AudioStreamSample::Format) VARIANT_ENUM_CAST(AudioStreamWAV::Format)
VARIANT_ENUM_CAST(AudioStreamSample::LoopMode) VARIANT_ENUM_CAST(AudioStreamWAV::LoopMode)
#endif // AUDIO_STREAM_SAMPLE_H #endif // AUDIO_STREAM_WAV_H

View File

@ -199,16 +199,16 @@ bool AudioEffectRecord::is_recording_active() const {
return recording_active; return recording_active;
} }
void AudioEffectRecord::set_format(AudioStreamSample::Format p_format) { void AudioEffectRecord::set_format(AudioStreamWAV::Format p_format) {
format = p_format; format = p_format;
} }
AudioStreamSample::Format AudioEffectRecord::get_format() const { AudioStreamWAV::Format AudioEffectRecord::get_format() const {
return format; return format;
} }
Ref<AudioStreamSample> AudioEffectRecord::get_recording() const { Ref<AudioStreamWAV> AudioEffectRecord::get_recording() const {
AudioStreamSample::Format dst_format = format; AudioStreamWAV::Format dst_format = format;
bool stereo = true; //forcing mono is not implemented bool stereo = true; //forcing mono is not implemented
Vector<uint8_t> dst_data; Vector<uint8_t> dst_data;
@ -216,7 +216,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
ERR_FAIL_COND_V(current_instance.is_null(), nullptr); ERR_FAIL_COND_V(current_instance.is_null(), nullptr);
ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, nullptr); ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, nullptr);
if (dst_format == AudioStreamSample::FORMAT_8_BITS) { if (dst_format == AudioStreamWAV::FORMAT_8_BITS) {
int data_size = current_instance->recording_data.size(); int data_size = current_instance->recording_data.size();
dst_data.resize(data_size); dst_data.resize(data_size);
uint8_t *w = dst_data.ptrw(); uint8_t *w = dst_data.ptrw();
@ -225,7 +225,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
int8_t v = CLAMP(current_instance->recording_data[i] * 128, -128, 127); int8_t v = CLAMP(current_instance->recording_data[i] * 128, -128, 127);
w[i] = v; w[i] = v;
} }
} else if (dst_format == AudioStreamSample::FORMAT_16_BITS) { } else if (dst_format == AudioStreamWAV::FORMAT_16_BITS) {
int data_size = current_instance->recording_data.size(); int data_size = current_instance->recording_data.size();
dst_data.resize(data_size * 2); dst_data.resize(data_size * 2);
uint8_t *w = dst_data.ptrw(); uint8_t *w = dst_data.ptrw();
@ -234,7 +234,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
int16_t v = CLAMP(current_instance->recording_data[i] * 32768, -32768, 32767); int16_t v = CLAMP(current_instance->recording_data[i] * 32768, -32768, 32767);
encode_uint16(v, &w[i * 2]); encode_uint16(v, &w[i * 2]);
} }
} else if (dst_format == AudioStreamSample::FORMAT_IMA_ADPCM) { } else if (dst_format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
//byte interleave //byte interleave
Vector<float> left; Vector<float> left;
Vector<float> right; Vector<float> right;
@ -273,12 +273,12 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
ERR_PRINT("Format not implemented."); ERR_PRINT("Format not implemented.");
} }
Ref<AudioStreamSample> sample; Ref<AudioStreamWAV> sample;
sample.instantiate(); sample.instantiate();
sample->set_data(dst_data); sample->set_data(dst_data);
sample->set_format(dst_format); sample->set_format(dst_format);
sample->set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); sample->set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
sample->set_loop_mode(AudioStreamSample::LOOP_DISABLED); sample->set_loop_mode(AudioStreamWAV::LOOP_DISABLED);
sample->set_loop_begin(0); sample->set_loop_begin(0);
sample->set_loop_end(0); sample->set_loop_end(0);
sample->set_stereo(stereo); sample->set_stereo(stereo);
@ -297,6 +297,6 @@ void AudioEffectRecord::_bind_methods() {
} }
AudioEffectRecord::AudioEffectRecord() { AudioEffectRecord::AudioEffectRecord() {
format = AudioStreamSample::FORMAT_16_BITS; format = AudioStreamWAV::FORMAT_16_BITS;
recording_active = false; recording_active = false;
} }

View File

@ -35,7 +35,7 @@
#include "core/io/marshalls.h" #include "core/io/marshalls.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/os/thread.h" #include "core/os/thread.h"
#include "scene/resources/audio_stream_sample.h" #include "scene/resources/audio_stream_wav.h"
#include "servers/audio/audio_effect.h" #include "servers/audio/audio_effect.h"
#include "servers/audio_server.h" #include "servers/audio_server.h"
@ -85,7 +85,7 @@ class AudioEffectRecord : public AudioEffect {
bool recording_active; bool recording_active;
Ref<AudioEffectRecordInstance> current_instance; Ref<AudioEffectRecordInstance> current_instance;
AudioStreamSample::Format format; AudioStreamWAV::Format format;
void ensure_thread_stopped(); void ensure_thread_stopped();
@ -96,9 +96,9 @@ public:
Ref<AudioEffectInstance> instantiate() override; Ref<AudioEffectInstance> instantiate() override;
void set_recording_active(bool p_record); void set_recording_active(bool p_record);
bool is_recording_active() const; bool is_recording_active() const;
void set_format(AudioStreamSample::Format p_format); void set_format(AudioStreamWAV::Format p_format);
AudioStreamSample::Format get_format() const; AudioStreamWAV::Format get_format() const;
Ref<AudioStreamSample> get_recording() const; Ref<AudioStreamWAV> get_recording() const;
AudioEffectRecord(); AudioEffectRecord();
}; };

View File

@ -39,7 +39,7 @@
#include "core/os/os.h" #include "core/os/os.h"
#include "core/string/string_name.h" #include "core/string/string_name.h"
#include "core/templates/pair.h" #include "core/templates/pair.h"
#include "scene/resources/audio_stream_sample.h" #include "scene/resources/audio_stream_wav.h"
#include "servers/audio/audio_driver_dummy.h" #include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/effects/audio_effect_compressor.h" #include "servers/audio/effects/audio_effect_compressor.h"

View File

@ -43,7 +43,7 @@
class AudioDriverDummy; class AudioDriverDummy;
class AudioStream; class AudioStream;
class AudioStreamSample; class AudioStreamWAV;
class AudioStreamPlayback; class AudioStreamPlayback;
class AudioDriver { class AudioDriver {