Upgrade sonic to 8694c596378c24e340c09ff2cd47c065494233f1 am: 526b30c5c9 am: 289fc2803a am: ef0c46db69 am: 81824d4049 am: ebea0f6094

Original change: https://android-review.googlesource.com/c/platform/external/sonic/+/2787654

Change-Id: I81b6fb79182655e32556ad4d7873f2bc0d53ff21
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/METADATA b/METADATA
index a800c58..df77656 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
 third_party {
   url {
     type: ARCHIVE
-    value: "https://github.com/waywardgeek/sonic/archive/9a8d05dc0baa9159fc322dd9905a04e23b161337.zip"
+    value: "https://github.com/waywardgeek/sonic/archive/8694c596378c24e340c09ff2cd47c065494233f1.zip"
   }
-  version: "9a8d05dc0baa9159fc322dd9905a04e23b161337"
+  version: "8694c596378c24e340c09ff2cd47c065494233f1"
   license_type: NOTICE
   last_upgrade_date {
     year: 2023
-    month: 9
-    day: 9
+    month: 10
+    day: 13
   }
 }
diff --git a/Makefile b/Makefile
index 2f7fd60..5e99ad1 100644
--- a/Makefile
+++ b/Makefile
@@ -81,7 +81,7 @@
 # Define a version of sonic with the internal names defined so others (i.e. Speedy)
 # can build new APIs that superscede the default API.
 sonic_internal.o: sonic.c sonic.h
-	$(CC) $(CPPFLAGS) $(CFLAGS) -DSONIC_INTERNAL -DSONIC_SPECTROGRAM -c sonic.c -o sonic_internal.o
+	$(CC) $(CPPFLAGS) $(CFLAGS) -DSONIC_INTERNAL -c sonic.c -o sonic_internal.o
 
 wave.o: wave.c wave.h
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c wave.c
@@ -99,8 +99,8 @@
 	ln -sf $(LIB_NAME)$(LIB_TAG) $(LIB_NAME).0
 endif
 
-$(LIB_INTERNAL_NAME)$(LIB_TAG): $(EXTRA_OBJ) sonic_internal.o spectrogram.o wave.o
-	$(CC) $(CFLAGS) $(LDFLAGS) $(SHARED_OPT) -Wl,$(SONAME)$(LIB_INTERNAL_NAME) $(EXTRA_OBJ) sonic_internal.o spectrogram.o -o $(LIB_INTERNAL_NAME)$(LIB_TAG) $(FFTLIB)  wave.o
+$(LIB_INTERNAL_NAME)$(LIB_TAG): $(EXTRA_OBJ) sonic_internal.o wave.o  # No spectrogram needed here.
+	$(CC) $(CFLAGS) $(LDFLAGS) $(SHARED_OPT) -Wl,$(SONAME)$(LIB_INTERNAL_NAME) $(EXTRA_OBJ) sonic_internal.o -o $(LIB_INTERNAL_NAME)$(LIB_TAG) $(FFTLIB)  wave.o
 ifneq ($(UNAME), Darwin)
 	ln -sf $(LIB_INTERNAL_NAME)$(LIB_TAG) $(LIB_INTERNAL_NAME)
 	ln -sf $(LIB_INTERNAL_NAME)$(LIB_TAG) $(LIB_INTERNAL_NAME).0
@@ -138,3 +138,13 @@
 
 check:
 	./sonic -s 2.0 ./samples/talking.wav ./test.wav
+
+
+libspeedy.so:
+	cd speedy; make libspeedy.so  SONIC_DIR=.. FFTW_DIR=../../fftw
+
+speedy_wave: libsonic_internal.so
+	cd speedy; make speedy_wave SONIC_DIR=.. FFTW_DIR=../../fftw
+	# You will probably also need to set the LDPATH.  For example
+	#    export LD_LIBRARY_PATH=/usr/local/lib:../kissfft:speedy:.
+
diff --git a/sonic.c b/sonic.c
index c18fc6e..d04f015 100644
--- a/sonic.c
+++ b/sonic.c
@@ -235,8 +235,6 @@
   int prevMinDiff;
 };
 
-#ifdef SONIC_SPECTROGRAM
-
 /* Attach user data to the stream. */
 void sonicSetUserData(sonicStream stream, void *userData) {
   stream->userData = userData;
@@ -247,6 +245,8 @@
   return stream->userData;
 }
 
+#ifdef SONIC_SPECTROGRAM
+
 /* Compute a spectrogram on the fly. */
 void sonicComputeSpectrogram(sonicStream stream) {
   stream->spectrogram = sonicCreateSpectrogram(stream->sampleRate);
@@ -391,7 +391,7 @@
   /* Allocate 25% more than needed so we hopefully won't grow. */
   stream->pitchBufferSize = maxRequired + (maxRequired >> 2);
   stream->pitchBuffer =
-      (short*)sonicCalloc(stream->pitchBufferSize, sizeof(short) * numChannels);
+      (short*)sonicCalloc(maxRequired, sizeof(short) * numChannels);
   if (stream->pitchBuffer == NULL) {
     sonicDestroyStream(stream);
     return 0;
@@ -887,12 +887,15 @@
                                        int originalNumOutputSamples) {
   int numSamples = stream->numOutputSamples - originalNumOutputSamples;
   int numChannels = stream->numChannels;
-  int pitchBufferSize = stream->pitchBufferSize;
 
-  if (stream->numPitchSamples + numSamples > pitchBufferSize) {
+  if (stream->numPitchSamples + numSamples > stream->pitchBufferSize) {
+    int pitchBufferSize = stream->pitchBufferSize;
     stream->pitchBufferSize += (pitchBufferSize >> 1) + numSamples;
-    stream->pitchBuffer = (short*)sonicRealloc(stream->pitchBuffer,
-        pitchBufferSize, stream->pitchBufferSize, sizeof(short) * numChannels);
+    stream->pitchBuffer = (short*)sonicRealloc(
+        stream->pitchBuffer,
+        pitchBufferSize,
+        stream->pitchBufferSize,
+        sizeof(short) * numChannels);
   }
   memcpy(stream->pitchBuffer + stream->numPitchSamples * numChannels,
          stream->outputBuffer + originalNumOutputSamples * numChannels,
diff --git a/sonic.h b/sonic.h
index ea439b0..f393dce 100644
--- a/sonic.h
+++ b/sonic.h
@@ -1,3 +1,6 @@
+#ifndef SONIC_H_
+#define SONIC_H_
+
 /* Sonic library
    Copyright 2010
    Bill Cox
@@ -57,7 +60,7 @@
 
 #ifdef SONIC_INTERNAL
 /* The following #define's are used to change the names of the routines defined
- * here so that a new library (sonic2) can reuse these names, and then call
+ * here so that a new library (i.e. speedy) can reuse these names, and then call
  * the original names.  We do this for two reasons: 1) we don't want to change
  * the original API, and 2) we want to add a shim, using the original names and
  * still call these routines.
@@ -98,6 +101,7 @@
 #define sonicChangeFloatSpeed sonicIntChangeFloatSpeed
 #define sonicChangeShortSpeed sonicIntChangeShortSpeed
 #define sonicEnableNonlinearSpeedup sonicIntEnableNonlinearSpeedup
+#define sonicSetDurationFeedbackStrength sonicIntSetDurationFeedbackStrength
 #define sonicComputeSpectrogram sonicIntComputeSpectrogram
 #define sonicGetSpectrogram sonicIntGetSpectrogram
 
@@ -283,3 +287,5 @@
 #ifdef __cplusplus
 }
 #endif
+
+#endif  /* SONIC_H_ */
diff --git a/spectrogram.c b/spectrogram.c
index 8eef8f4..6305130 100644
--- a/spectrogram.c
+++ b/spectrogram.c
@@ -7,8 +7,9 @@
 */
 
 #ifdef  KISS_FFT
-#include <stddef.h>  /* kiss_fft.h fails to load this */
+#include <stddef.h>  /* kiss_fft.h failes to load this */
 #include <kiss_fft.h>
+#include <kiss_fft_impl.h>
 #else
 #include <fftw3.h>
 #endif
@@ -369,9 +370,3 @@
   fclose(file);
   return 1;
 }
-
-#ifdef	MAIN
-main(){
-
-}
-#endif
diff --git a/wave.c b/wave.c
index ace469a..65d1a22 100644
--- a/wave.c
+++ b/wave.c
@@ -177,7 +177,7 @@
   data = readShort(file); /* 20 - what is the audio format? 1 for PCM = Pulse
                              Code Modulation */
   if (data != 1) {
-    fprintf(stderr, "Only PCM wave files are supported\n");
+    fprintf(stderr, "Only PCM wave files are supported (not %d)\n", data);
     return 0;
   }
   file->numChannels =