Browse Source

check too-large FFT sizes for ana format

richarddobson 1 month ago
parent
commit
f8b0028023
1 changed files with 31 additions and 5 deletions
  1. 31 5
      dev/pv/ap_pvoc.c

+ 31 - 5
dev/pv/ap_pvoc.c

@@ -21,9 +21,9 @@
     02111-1307 USA
     02111-1307 USA
  *
  *
  */
  */
-
-
-
+
+
+
 /* May 2011 rebuilt with fixed mainfuncs.c for preserving sample type etc */
 /* May 2011 rebuilt with fixed mainfuncs.c for preserving sample type etc */
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -47,6 +47,8 @@
 #include <string.h>
 #include <string.h>
 #include <math.h>
 #include <math.h>
 
 
+//RWD 2025 zero error checking - will already have been done!
+static int checkchans4format(int chans, const char* fname);
 /***************************************************************************************/
 /***************************************************************************************/
 /****************************** FORMERLY IN aplinit.c **********************************/
 /****************************** FORMERLY IN aplinit.c **********************************/
 /***************************************************************************************/
 /***************************************************************************************/
@@ -387,14 +389,24 @@ int check_param_validity_and_consistency(dataptr dz)
 	int M, D, win_overlap;
 	int M, D, win_overlap;
 	float arate;
 	float arate;
 	int srate;
 	int srate;
-
-	switch(dz->process) {
+    //RWD 2025
+    const char* ofname = 0;
+	
+    switch(dz->process) {
 	case(PVOC_ANAL):
 	case(PVOC_ANAL):
+        //RWD 2025 to trap excessive fft sizes for .ana
+        ofname = dz->outfilename;
+ 
 		chans = dz->infile->channels;
 		chans = dz->infile->channels;
 		srate = dz->infile->srate;
 		srate = dz->infile->srate;
 		win_overlap = dz->iparam[PVOC_WINOVLP_INPUT]-1;
 		win_overlap = dz->iparam[PVOC_WINOVLP_INPUT]-1;
 		chancnt = dz->iparam[PVOC_CHANS_INPUT];
 		chancnt = dz->iparam[PVOC_CHANS_INPUT];
 		chancnt = chancnt + (chancnt%2);
 		chancnt = chancnt + (chancnt%2);
+            //RWD 2025
+        if(checkchans4format(chancnt,ofname) == 0) {
+            sprintf(errstr,"Requested analysis channel count %d > 8192: too large for .ana format\n",chancnt);
+            return DATA_ERROR;
+        }
 		switch(win_overlap) {
 		switch(win_overlap) {
 			case 0:	M = 4*chancnt;		break;
 			case 0:	M = 4*chancnt;		break;
 			case 1:	M = 2*chancnt;		break;
 			case 1:	M = 2*chancnt;		break;
@@ -448,3 +460,17 @@ int inner_loop
 	return(FINISHED);
 	return(FINISHED);
 }
 }
 
 
+//RWD 2025 zero error checking - will already have been done!
+static int checkchans4format(int chans, const char* fname)
+{
+    char *lastdot;
+    
+    lastdot = strrchr(fname,'.');
+    if(chans > 8192){
+        if((_stricmp(lastdot,".wav")==0)
+           || (_stricmp(lastdot,".ana")==0))
+            return 0;
+    }
+    
+    return 1;
+}