Browse Source

Merge pull request #58681 from akien-mga/3.x-cherrypicks

Rémi Verschelde 3 years ago
parent
commit
cf970aab26

+ 5 - 7
core/io/pck_packer.cpp

@@ -154,13 +154,11 @@ Error PCKPacker::flush(bool p_verbose) {
 		src->close();
 		src->close();
 		memdelete(src);
 		memdelete(src);
 		count += 1;
 		count += 1;
-		if (p_verbose && files.size() > 0) {
-			if (count % 100 == 0) {
-				printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100);
-				fflush(stdout);
-			};
-		};
-	};
+		const int file_num = files.size();
+		if (p_verbose && (file_num > 0)) {
+			print_line(vformat("[%d/%d - %d%%] PCKPacker flush: %s -> %s", count, file_num, float(count) / file_num * 100, files[i].src_path, files[i].path));
+		}
+	}
 
 
 	if (p_verbose) {
 	if (p_verbose) {
 		printf("\n");
 		printf("\n");

+ 17 - 28
core/undo_redo.cpp

@@ -33,6 +33,20 @@
 #include "core/os/os.h"
 #include "core/os/os.h"
 #include "core/resource.h"
 #include "core/resource.h"
 
 
+void UndoRedo::Operation::delete_reference() {
+	if (type != Operation::TYPE_REFERENCE) {
+		return;
+	}
+	if (ref.is_valid()) {
+		ref.unref();
+	} else {
+		Object *obj = ObjectDB::get_instance(object);
+		if (obj) {
+			memdelete(obj);
+		}
+	}
+}
+
 void UndoRedo::_discard_redo() {
 void UndoRedo::_discard_redo() {
 	if (current_action == actions.size() - 1) {
 	if (current_action == actions.size() - 1) {
 		return;
 		return;
@@ -40,16 +54,7 @@ void UndoRedo::_discard_redo() {
 
 
 	for (int i = current_action + 1; i < actions.size(); i++) {
 	for (int i = current_action + 1; i < actions.size(); i++) {
 		for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) {
 		for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) {
-			if (E->get().type == Operation::TYPE_REFERENCE) {
-				if (E->get().ref.is_valid()) {
-					E->get().ref.unref();
-				} else {
-					Object *obj = ObjectDB::get_instance(E->get().object);
-					if (obj) {
-						memdelete(obj);
-					}
-				}
-			}
+			E->get().delete_reference();
 		}
 		}
 		//ERASE do data
 		//ERASE do data
 	}
 	}
@@ -72,14 +77,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
 				List<Operation>::Element *E = actions.write[current_action + 1].do_ops.front();
 				List<Operation>::Element *E = actions.write[current_action + 1].do_ops.front();
 
 
 				while (E) {
 				while (E) {
-					if (E->get().type == Operation::TYPE_REFERENCE) {
-						Object *obj = ObjectDB::get_instance(E->get().object);
-
-						if (obj) {
-							memdelete(obj);
-						}
-					}
-
+					E->get().delete_reference();
 					E = E->next();
 					E = E->next();
 					actions.write[current_action + 1].do_ops.pop_front();
 					actions.write[current_action + 1].do_ops.pop_front();
 				}
 				}
@@ -224,16 +222,7 @@ void UndoRedo::_pop_history_tail() {
 	}
 	}
 
 
 	for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) {
 	for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) {
-		if (E->get().type == Operation::TYPE_REFERENCE) {
-			if (E->get().ref.is_valid()) {
-				E->get().ref.unref();
-			} else {
-				Object *obj = ObjectDB::get_instance(E->get().object);
-				if (obj) {
-					memdelete(obj);
-				}
-			}
-		}
+		E->get().delete_reference();
 	}
 	}
 
 
 	actions.remove(0);
 	actions.remove(0);

+ 2 - 0
core/undo_redo.h

@@ -64,6 +64,8 @@ private:
 		ObjectID object;
 		ObjectID object;
 		String name;
 		String name;
 		Variant args[VARIANT_ARG_MAX];
 		Variant args[VARIANT_ARG_MAX];
+
+		void delete_reference();
 	};
 	};
 
 
 	struct Action {
 	struct Action {

+ 33 - 5
doc/classes/String.xml

@@ -188,7 +188,10 @@
 		<method name="bigrams">
 		<method name="bigrams">
 			<return type="PoolStringArray" />
 			<return type="PoolStringArray" />
 			<description>
 			<description>
-				Returns the bigrams (pairs of consecutive letters) of this string.
+				Returns an array containing the bigrams (pairs of consecutive letters) of this string.
+				[codeblock]
+				print("Bigrams".bigrams()) # Prints "[Bi, ig, gr, ra, am, ms]"
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="c_escape">
 		<method name="c_escape">
@@ -447,7 +450,14 @@
 		<method name="is_valid_float">
 		<method name="is_valid_float">
 			<return type="bool" />
 			<return type="bool" />
 			<description>
 			<description>
-				Returns [code]true[/code] if this string contains a valid float.
+				Returns [code]true[/code] if this string contains a valid float. This is inclusive of integers, and also supports exponents:
+				[codeblock]
+				print("1.7".is_valid_float()) # Prints "true"
+				print("24".is_valid_float()) # Prints "true"
+				print("7e3".is_valid_float()) # Prints "true"
+				print("24".is_valid_float()) # Prints "true"
+				print("Hello".is_valid_float()) # Prints "false"
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="is_valid_hex_number">
 		<method name="is_valid_hex_number">
@@ -467,12 +477,24 @@
 			<return type="bool" />
 			<return type="bool" />
 			<description>
 			<description>
 				Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit.
 				Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit.
+				[codeblock]
+				print("good_ident_1".is_valid_identifier()) # Prints "true"
+				print("1st_bad_ident".is_valid_identifier()) # Prints "false"
+				print("bad_ident_#2".is_valid_identifier()) # Prints "false"
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="is_valid_integer">
 		<method name="is_valid_integer">
 			<return type="bool" />
 			<return type="bool" />
 			<description>
 			<description>
 				Returns [code]true[/code] if this string contains a valid integer.
 				Returns [code]true[/code] if this string contains a valid integer.
+				[codeblock]
+				print("7".is_valid_int()) # Prints "true"
+				print("14.6".is_valid_int()) # Prints "false"
+				print("L".is_valid_int()) # Prints "false"
+				print("+3".is_valid_int()) # Prints "true"
+				print("-12".is_valid_int()) # Prints "true"
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="is_valid_ip_address">
 		<method name="is_valid_ip_address">
@@ -523,14 +545,14 @@
 			<return type="bool" />
 			<return type="bool" />
 			<argument index="0" name="expr" type="String" />
 			<argument index="0" name="expr" type="String" />
 			<description>
 			<description>
-				Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]).
+				Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code].
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="matchn">
 		<method name="matchn">
 			<return type="bool" />
 			<return type="bool" />
 			<argument index="0" name="expr" type="String" />
 			<argument index="0" name="expr" type="String" />
 			<description>
 			<description>
-				Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]).
+				Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code].
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="md5_buffer">
 		<method name="md5_buffer">
@@ -707,7 +729,13 @@
 			<return type="float" />
 			<return type="float" />
 			<argument index="0" name="text" type="String" />
 			<argument index="0" name="text" type="String" />
 			<description>
 			<description>
-				Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.
+				Returns the similarity index ([url=https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient]Sorensen-Dice coefficient[/url]) this string compared to another. 1.0 means totally similar and 0.0 means totally dissimilar.
+				[codeblock]
+				print("ABC123".similarity("ABC123")) # Prints "1"
+				print("ABC123".similarity("XYZ456")) # Prints "0"
+				print("ABC123".similarity("123ABC")) # Prints "0.8"
+				print("ABC123".similarity("abc123")) # Prints "0.4"
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="simplify_path">
 		<method name="simplify_path">

+ 2 - 0
platform/iphone/godot_view.mm

@@ -145,6 +145,8 @@ static const int max_touches = 8;
 
 
 	[self initTouches];
 	[self initTouches];
 
 
+	self.multipleTouchEnabled = YES;
+
 	// Configure and start accelerometer
 	// Configure and start accelerometer
 	if (!self.motionManager) {
 	if (!self.motionManager) {
 		self.motionManager = [[CMMotionManager alloc] init];
 		self.motionManager = [[CMMotionManager alloc] init];

+ 5 - 5
scene/2d/animated_sprite.cpp

@@ -364,14 +364,14 @@ void AnimatedSprite::_notification(int p_what) {
 				return;
 				return;
 			}
 			}
 
 
-			float speed = frames->get_animation_speed(animation) * speed_scale;
-			if (speed == 0) {
-				return; //do nothing
-			}
-
 			float remaining = get_process_delta_time();
 			float remaining = get_process_delta_time();
 
 
 			while (remaining) {
 			while (remaining) {
+				float speed = frames->get_animation_speed(animation) * speed_scale;
+				if (speed == 0) {
+					return; //do nothing
+				}
+
 				if (timeout <= 0) {
 				if (timeout <= 0) {
 					timeout = _get_frame_duration();
 					timeout = _get_frame_duration();
 
 

+ 5 - 5
scene/3d/sprite_3d.cpp

@@ -980,14 +980,14 @@ void AnimatedSprite3D::_notification(int p_what) {
 				return;
 				return;
 			}
 			}
 
 
-			float speed = frames->get_animation_speed(animation);
-			if (speed == 0) {
-				return; //do nothing
-			}
-
 			float remaining = get_process_delta_time();
 			float remaining = get_process_delta_time();
 
 
 			while (remaining) {
 			while (remaining) {
+				float speed = frames->get_animation_speed(animation);
+				if (speed == 0) {
+					return; // Do nothing.
+				}
+
 				if (timeout <= 0) {
 				if (timeout <= 0) {
 					timeout = 1.0 / speed;
 					timeout = 1.0 / speed;
 
 

+ 3 - 3
scene/gui/rich_text_label.cpp

@@ -414,7 +414,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
 							cw = tab_size * font->get_char_size(' ').width;
 							cw = tab_size * font->get_char_size(' ').width;
 						}
 						}
 
 
-						if (end > 0 && w + cw + begin > p_width) {
+						if (end > 0 && fw + cw + begin > p_width) {
 							break; //don't allow lines longer than assigned width
 							break; //don't allow lines longer than assigned width
 						}
 						}
 
 
@@ -437,13 +437,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
 						was_separatable = separatable;
 						was_separatable = separatable;
 						just_breaked_in_middle = false;
 						just_breaked_in_middle = false;
 
 
-						w += cw;
 						fw += cw;
 						fw += cw;
 
 
 						end++;
 						end++;
 					}
 					}
 					CHECK_HEIGHT(fh);
 					CHECK_HEIGHT(fh);
-					ENSURE_WIDTH(w);
+					ENSURE_WIDTH(fw);
 
 
 					line_ascent = MAX(line_ascent, ascent);
 					line_ascent = MAX(line_ascent, ascent);
 					line_descent = MAX(line_descent, descent);
 					line_descent = MAX(line_descent, descent);
@@ -579,6 +578,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
 
 
 								if (visible) {
 								if (visible) {
 									line_is_blank = false;
 									line_is_blank = false;
+									w += font->get_char_size(c[i], c[i + 1]).x;
 								}
 								}
 
 
 								if (c[i] == '\t') {
 								if (c[i] == '\t') {

+ 35 - 61
servers/audio/effects/audio_effect_pitch_shift.cpp

@@ -74,7 +74,7 @@
 *
 *
 *****************************************************************************/
 *****************************************************************************/
 
 
-void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int64_t fftFrameSize, int64_t osamp, float sampleRate, float *indata, float *outdata,int stride) {
+void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata,int stride) {
 
 
 
 
 	/*
 	/*
@@ -85,32 +85,19 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 	*/
 	*/
 
 
 	double magn, phase, tmp, window, real, imag;
 	double magn, phase, tmp, window, real, imag;
-	double freqPerBin, expct, reciprocalFftFrameSize;
-	int64_t i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;
+	double freqPerBin, expct;
+	long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;
 
 
 	/* set up some handy variables */
 	/* set up some handy variables */
 	fftFrameSize2 = fftFrameSize/2;
 	fftFrameSize2 = fftFrameSize/2;
-	reciprocalFftFrameSize = 1./fftFrameSize;
 	stepSize = fftFrameSize/osamp;
 	stepSize = fftFrameSize/osamp;
-	freqPerBin = reciprocalFftFrameSize * sampleRate;
-	expct = Math_TAU * reciprocalFftFrameSize * stepSize;
+	freqPerBin = sampleRate/(double)fftFrameSize;
+	expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize;
 	inFifoLatency = fftFrameSize-stepSize;
 	inFifoLatency = fftFrameSize-stepSize;
-	if (gRover == 0) {
-		gRover = inFifoLatency;
-	}
+	if (gRover == 0) { gRover = inFifoLatency;
+}
 
 
-	// If pitchShift changes clear arrays to prevent some artifacts and quality loss.
-	if (lastPitchShift != pitchShift) {
-		lastPitchShift = pitchShift;
-		memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
-		memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
-		memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(double));
-		memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double));
-		memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double));
-		memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(double));
-		memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(double));
-		memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(double));
-	}
+	/* initialize our static arrays */
 
 
 	/* main processing loop */
 	/* main processing loop */
 	for (i = 0; i < numSampsToProcess; i++){
 	for (i = 0; i < numSampsToProcess; i++){
@@ -126,7 +113,7 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 
 
 			/* do windowing and re,im interleave */
 			/* do windowing and re,im interleave */
 			for (k = 0; k < fftFrameSize;k++) {
 			for (k = 0; k < fftFrameSize;k++) {
-				window = -.5*cos(Math_TAU * reciprocalFftFrameSize * k)+.5;
+				window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5;
 				gFFTworksp[2*k] = gInFIFO[k] * window;
 				gFFTworksp[2*k] = gInFIFO[k] * window;
 				gFFTworksp[2*k+1] = 0.;
 				gFFTworksp[2*k+1] = 0.;
 			}
 			}
@@ -138,7 +125,6 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 
 
 			/* this is the analysis step */
 			/* this is the analysis step */
 			for (k = 0; k <= fftFrameSize2; k++) {
 			for (k = 0; k <= fftFrameSize2; k++) {
-
 				/* de-interlace FFT buffer */
 				/* de-interlace FFT buffer */
 				real = gFFTworksp[2*k];
 				real = gFFTworksp[2*k];
 				imag = gFFTworksp[2*k+1];
 				imag = gFFTworksp[2*k+1];
@@ -156,15 +142,13 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 
 
 				/* map delta phase into +/- Pi interval */
 				/* map delta phase into +/- Pi interval */
 				qpd = tmp/Math_PI;
 				qpd = tmp/Math_PI;
-				if (qpd >= 0) {
-					qpd += qpd&1;
-				} else {
-					qpd -= qpd&1;
-				}
+				if (qpd >= 0) { qpd += qpd&1;
+				} else { qpd -= qpd&1;
+}
 				tmp -= Math_PI*(double)qpd;
 				tmp -= Math_PI*(double)qpd;
 
 
 				/* get deviation from bin frequency from the +/- Pi interval */
 				/* get deviation from bin frequency from the +/- Pi interval */
-				tmp = osamp*tmp/Math_TAU;
+				tmp = osamp*tmp/(2.*Math_PI);
 
 
 				/* compute the k-th partials' true frequency */
 				/* compute the k-th partials' true frequency */
 				tmp = (double)k*freqPerBin + tmp*freqPerBin;
 				tmp = (double)k*freqPerBin + tmp*freqPerBin;
@@ -177,8 +161,8 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 
 
 			/* ***************** PROCESSING ******************* */
 			/* ***************** PROCESSING ******************* */
 			/* this does the actual pitch shifting */
 			/* this does the actual pitch shifting */
-			memset(gSynMagn, 0, fftFrameSize*sizeof(double));
-			memset(gSynFreq, 0, fftFrameSize*sizeof(double));
+			memset(gSynMagn, 0, fftFrameSize*sizeof(float));
+			memset(gSynFreq, 0, fftFrameSize*sizeof(float));
 			for (k = 0; k <= fftFrameSize2; k++) {
 			for (k = 0; k <= fftFrameSize2; k++) {
 				index = k*pitchShift;
 				index = k*pitchShift;
 				if (index <= fftFrameSize2) {
 				if (index <= fftFrameSize2) {
@@ -202,7 +186,7 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 				tmp /= freqPerBin;
 				tmp /= freqPerBin;
 
 
 				/* take osamp into account */
 				/* take osamp into account */
-				tmp = Math_TAU*tmp/osamp;
+				tmp = 2.*Math_PI*tmp/osamp;
 
 
 				/* add the overlap phase advance back in */
 				/* add the overlap phase advance back in */
 				tmp += (double)k*expct;
 				tmp += (double)k*expct;
@@ -217,35 +201,33 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6
 			}
 			}
 
 
 			/* zero negative frequencies */
 			/* zero negative frequencies */
-			for (k = fftFrameSize+2; k < 2*MAX_FRAME_LENGTH; k++) {
-				gFFTworksp[k] = 0.;
-			}
+			for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) { gFFTworksp[k] = 0.;
+}
 
 
 			/* do inverse transform */
 			/* do inverse transform */
 			smbFft(gFFTworksp, fftFrameSize, 1);
 			smbFft(gFFTworksp, fftFrameSize, 1);
 
 
 			/* do windowing and add to output accumulator */
 			/* do windowing and add to output accumulator */
 			for(k=0; k < fftFrameSize; k++) {
 			for(k=0; k < fftFrameSize; k++) {
-				window = -.5*cos(Math_TAU * reciprocalFftFrameSize * k)+.5;
+				window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5;
 				gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
 				gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
 			}
 			}
-			for (k = 0; k < stepSize; k++) {
-				gOutFIFO[k] = gOutputAccum[k];
-			}
+			for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k];
+}
 
 
 			/* shift accumulator */
 			/* shift accumulator */
-			memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(double));
+			memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float));
 
 
 			/* move input FIFO */
 			/* move input FIFO */
-			for (k = 0; k < inFifoLatency; k++) {
-				gInFIFO[k] = gInFIFO[k+stepSize];
-			}
+			for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize];
+}
 		}
 		}
 	}
 	}
 }
 }
 
 
 
 
-void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign)
+
+void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign)
 /*
 /*
 	FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse)
 	FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse)
 	Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the
 	Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the
@@ -258,16 +240,14 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign
 	of the frequencies of interest is in fftBuffer[0...fftFrameSize].
 	of the frequencies of interest is in fftBuffer[0...fftFrameSize].
 */
 */
 {
 {
-	double wr, wi, arg, *p1, *p2, temp;
-	double tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i;
-	int64_t i, bitm, j, le, le2, k, logN;
-	logN = (int64_t)(log(fftFrameSize) / log(2.) + .5);
+	float wr, wi, arg, *p1, *p2, temp;
+	float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i;
+	long i, bitm, j, le, le2, k;
 
 
 	for (i = 2; i < 2*fftFrameSize-2; i += 2) {
 	for (i = 2; i < 2*fftFrameSize-2; i += 2) {
 		for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) {
 		for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) {
-			if (i & bitm) {
-				j++;
-			}
+			if (i & bitm) { j++;
+}
 			j <<= 1;
 			j <<= 1;
 		}
 		}
 		if (i < j) {
 		if (i < j) {
@@ -277,8 +257,7 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign
 			*p1 = *p2; *p2 = temp;
 			*p1 = *p2; *p2 = temp;
 		}
 		}
 	}
 	}
-
-	for (k = 0, le = 2; k < logN; k++) {
+	for (k = 0, le = 2; k < (long)(log((double)fftFrameSize)/log(2.)+.5); k++) {
 		le <<= 1;
 		le <<= 1;
 		le2 = le>>1;
 		le2 = le>>1;
 		ur = 1.0;
 		ur = 1.0;
@@ -310,14 +289,6 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign
 void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
 void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
 	float sample_rate = AudioServer::get_singleton()->get_mix_rate();
 	float sample_rate = AudioServer::get_singleton()->get_mix_rate();
 
 
-	// For pitch_scale 1.0 it's cheaper to just pass samples without processing them.
-	if (Math::is_equal_approx(base->pitch_scale, 1.0f)) {
-		for (int i = 0; i < p_frame_count; i++) {
-			p_dst_frames[i] = p_src_frames[i];
-		}
-		return;
-	}
-
 	float *in_l = (float *)p_src_frames;
 	float *in_l = (float *)p_src_frames;
 	float *in_r = in_l + 1;
 	float *in_r = in_l + 1;
 
 
@@ -391,4 +362,7 @@ AudioEffectPitchShift::AudioEffectPitchShift() {
 	pitch_scale = 1.0;
 	pitch_scale = 1.0;
 	oversampling = 4;
 	oversampling = 4;
 	fft_size = FFT_SIZE_2048;
 	fft_size = FFT_SIZE_2048;
+	wet = 0.0;
+	dry = 0.0;
+	filter = false;
 }
 }

+ 21 - 20
servers/audio/effects/audio_effect_pitch_shift.h

@@ -40,33 +40,31 @@ class SMBPitchShift {
 
 
 	float gInFIFO[MAX_FRAME_LENGTH];
 	float gInFIFO[MAX_FRAME_LENGTH];
 	float gOutFIFO[MAX_FRAME_LENGTH];
 	float gOutFIFO[MAX_FRAME_LENGTH];
-	double gFFTworksp[2 * MAX_FRAME_LENGTH];
-	double gLastPhase[MAX_FRAME_LENGTH / 2 + 1];
-	double gSumPhase[MAX_FRAME_LENGTH / 2 + 1];
-	double gOutputAccum[2 * MAX_FRAME_LENGTH];
-	double gAnaFreq[MAX_FRAME_LENGTH];
-	double gAnaMagn[MAX_FRAME_LENGTH];
-	double gSynFreq[MAX_FRAME_LENGTH];
-	double gSynMagn[MAX_FRAME_LENGTH];
-	int64_t gRover;
-	float lastPitchShift;
-
-	void smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign);
+	float gFFTworksp[2 * MAX_FRAME_LENGTH];
+	float gLastPhase[MAX_FRAME_LENGTH / 2 + 1];
+	float gSumPhase[MAX_FRAME_LENGTH / 2 + 1];
+	float gOutputAccum[2 * MAX_FRAME_LENGTH];
+	float gAnaFreq[MAX_FRAME_LENGTH];
+	float gAnaMagn[MAX_FRAME_LENGTH];
+	float gSynFreq[MAX_FRAME_LENGTH];
+	float gSynMagn[MAX_FRAME_LENGTH];
+	long gRover;
+
+	void smbFft(float *fftBuffer, long fftFrameSize, long sign);
 
 
 public:
 public:
-	void PitchShift(float pitchShift, int64_t numSampsToProcess, int64_t fftFrameSize, int64_t osamp, float sampleRate, float *indata, float *outdata, int stride);
+	void PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata, int stride);
 
 
 	SMBPitchShift() {
 	SMBPitchShift() {
 		gRover = 0;
 		gRover = 0;
 		memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
 		memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
 		memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
 		memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
-		memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(double));
-		memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double));
-		memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double));
-		memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(double));
-		memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(double));
-		memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(double));
-		lastPitchShift = 1.0;
+		memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(float));
+		memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float));
+		memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float));
+		memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(float));
+		memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(float));
+		memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(float));
 	}
 	}
 };
 };
 
 
@@ -103,6 +101,9 @@ public:
 	float pitch_scale;
 	float pitch_scale;
 	int oversampling;
 	int oversampling;
 	FFT_Size fft_size;
 	FFT_Size fft_size;
+	float wet;
+	float dry;
+	bool filter;
 
 
 protected:
 protected:
 	static void _bind_methods();
 	static void _bind_methods();

+ 2 - 2
thirdparty/README.md

@@ -364,8 +364,8 @@ Collection of single-file libraries used in Godot components.
   * Modifications: use `const char*` instead of `char*` for input string
   * Modifications: use `const char*` instead of `char*` for input string
 - `stb_rect_pack.h`
 - `stb_rect_pack.h`
   * Upstream: https://github.com/nothings/stb
   * Upstream: https://github.com/nothings/stb
-  * Version: 1.00
-  * License: Public Domain (Unlicense) or MIT
+  * Version: 1.01 (af1a5bc352164740c1cc1354942b1c6b72eacb8a, 2021)
+  * License: Public Domain or Unlicense or MIT
 - `stb_vorbis.c`
 - `stb_vorbis.c`
   * Upstream: https://github.com/nothings/stb
   * Upstream: https://github.com/nothings/stb
   * Version: 1.20 (314d0a6f9af5af27e585336eecea333e95c5a2d8, 2020)
   * Version: 1.20 (314d0a6f9af5af27e585336eecea333e95c5a2d8, 2020)

+ 15 - 20
thirdparty/stb_rect_pack/stb_rect_pack.h

@@ -1,9 +1,15 @@
-// stb_rect_pack.h - v1.00 - public domain - rectangle packing
+// stb_rect_pack.h - v1.01 - public domain - rectangle packing
 // Sean Barrett 2014
 // Sean Barrett 2014
 //
 //
 // Useful for e.g. packing rectangular textures into an atlas.
 // Useful for e.g. packing rectangular textures into an atlas.
 // Does not do rotation.
 // Does not do rotation.
 //
 //
+// Before #including,
+//
+//    #define STB_RECT_PACK_IMPLEMENTATION
+//
+// in the file that you want to have the implementation.
+//
 // Not necessarily the awesomest packing method, but better than
 // Not necessarily the awesomest packing method, but better than
 // the totally naive one in stb_truetype (which is primarily what
 // the totally naive one in stb_truetype (which is primarily what
 // this is meant to replace).
 // this is meant to replace).
@@ -35,6 +41,7 @@
 //
 //
 // Version history:
 // Version history:
 //
 //
+//     1.01  (2021-07-11)  always use large rect mode, expose STBRP__MAXVAL in public section
 //     1.00  (2019-02-25)  avoid small space waste; gracefully fail too-wide rectangles
 //     1.00  (2019-02-25)  avoid small space waste; gracefully fail too-wide rectangles
 //     0.99  (2019-02-07)  warning fixes
 //     0.99  (2019-02-07)  warning fixes
 //     0.11  (2017-03-03)  return packing success/fail result
 //     0.11  (2017-03-03)  return packing success/fail result
@@ -75,11 +82,10 @@ typedef struct stbrp_context stbrp_context;
 typedef struct stbrp_node    stbrp_node;
 typedef struct stbrp_node    stbrp_node;
 typedef struct stbrp_rect    stbrp_rect;
 typedef struct stbrp_rect    stbrp_rect;
 
 
-#ifdef STBRP_LARGE_RECTS
 typedef int            stbrp_coord;
 typedef int            stbrp_coord;
-#else
-typedef unsigned short stbrp_coord;
-#endif
+
+#define STBRP__MAXVAL  0x7fffffff
+// Mostly for internal use, but this is the maximum supported coordinate value.
 
 
 STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
 STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
 // Assign packed locations to rectangles. The rectangles are of type
 // Assign packed locations to rectangles. The rectangles are of type
@@ -209,8 +215,10 @@ struct stbrp_context
 
 
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 #define STBRP__NOTUSED(v)  (void)(v)
 #define STBRP__NOTUSED(v)  (void)(v)
+#define STBRP__CDECL       __cdecl
 #else
 #else
 #define STBRP__NOTUSED(v)  (void)sizeof(v)
 #define STBRP__NOTUSED(v)  (void)sizeof(v)
+#define STBRP__CDECL
 #endif
 #endif
 
 
 enum
 enum
@@ -253,9 +261,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou
 STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
 STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
 {
 {
    int i;
    int i;
-#ifndef STBRP_LARGE_RECTS
-   STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
-#endif
 
 
    for (i=0; i < num_nodes-1; ++i)
    for (i=0; i < num_nodes-1; ++i)
       nodes[i].next = &nodes[i+1];
       nodes[i].next = &nodes[i+1];
@@ -274,11 +279,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
    context->extra[0].y = 0;
    context->extra[0].y = 0;
    context->extra[0].next = &context->extra[1];
    context->extra[0].next = &context->extra[1];
    context->extra[1].x = (stbrp_coord) width;
    context->extra[1].x = (stbrp_coord) width;
-#ifdef STBRP_LARGE_RECTS
    context->extra[1].y = (1<<30);
    context->extra[1].y = (1<<30);
-#else
-   context->extra[1].y = 65535;
-#endif
    context->extra[1].next = NULL;
    context->extra[1].next = NULL;
 }
 }
 
 
@@ -520,7 +521,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
    return res;
    return res;
 }
 }
 
 
-static int rect_height_compare(const void *a, const void *b)
+static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
 {
 {
    const stbrp_rect *p = (const stbrp_rect *) a;
    const stbrp_rect *p = (const stbrp_rect *) a;
    const stbrp_rect *q = (const stbrp_rect *) b;
    const stbrp_rect *q = (const stbrp_rect *) b;
@@ -531,19 +532,13 @@ static int rect_height_compare(const void *a, const void *b)
    return (p->w > q->w) ? -1 : (p->w < q->w);
    return (p->w > q->w) ? -1 : (p->w < q->w);
 }
 }
 
 
-static int rect_original_order(const void *a, const void *b)
+static int STBRP__CDECL rect_original_order(const void *a, const void *b)
 {
 {
    const stbrp_rect *p = (const stbrp_rect *) a;
    const stbrp_rect *p = (const stbrp_rect *) a;
    const stbrp_rect *q = (const stbrp_rect *) b;
    const stbrp_rect *q = (const stbrp_rect *) b;
    return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
    return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
 }
 }
 
 
-#ifdef STBRP_LARGE_RECTS
-#define STBRP__MAXVAL  0xffffffff
-#else
-#define STBRP__MAXVAL  0xffff
-#endif
-
 STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
 STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
 {
 {
    int i, all_rects_packed = 1;
    int i, all_rects_packed = 1;