Remove system() call from compiledata.c

This commit is contained in:
Yury Popov
2022-10-30 10:11:44 +02:00
committed by Juho Hiltunen
parent 5738827dbf
commit a178ea1b13
-52
View File
@@ -1193,12 +1193,7 @@ static int LoadWavefile(FILE *f, const char *fname)
int max = 0; int max = 0;
int length; int length;
int sr1, sr2; int sr1, sr2;
bool failed;
int len; int len;
bool resample_wav = false;
const char *fname2;
char fname_temp[100];
char msg[120];
int scale_factor = 0; int scale_factor = 0;
fseek(f, 24, SEEK_SET); fseek(f, 24, SEEK_SET);
@@ -1207,56 +1202,13 @@ static int LoadWavefile(FILE *f, const char *fname)
fseek(f, 40, SEEK_SET); fseek(f, 40, SEEK_SET);
if ((sr1 != samplerate_native) || (sr2 != sr1*2)) { if ((sr1 != samplerate_native) || (sr2 != sr1*2)) {
char command[sizeof(path_home)+250];
failed = false;
#ifdef HAVE_MKSTEMP
strcpy(fname_temp, "/tmp/espeakXXXXXX");
int fd_temp;
if ((fd_temp = mkstemp(fname_temp)) >= 0)
close(fd_temp);
#else
strcpy(fname_temp, tmpnam(NULL));
#endif
fname2 = fname;
len = strlen(fname);
if (strcmp(&fname[len-4], ".wav") == 0) {
strcpy(msg, fname);
msg[len-4] = 0;
fname2 = msg;
}
sprintf(command, "sox \"%s/%s.wav\" -r %d -c1 -t wav %s\n", phsrc, fname2, samplerate_native, fname_temp);
if (system(command) != 0)
failed = true;
if (failed || (GetFileLength(fname_temp) <= 0)) {
if (resample_fails < 2)
error("Resample command failed: %s", command);
resample_fails++;
if (sr1 != samplerate_native) if (sr1 != samplerate_native)
error("Can't resample (%d to %d): %s", sr1, samplerate_native, fname); error("Can't resample (%d to %d): %s", sr1, samplerate_native, fname);
else else
error("WAV file is not mono: %s", fname); error("WAV file is not mono: %s", fname);
remove(fname_temp);
return 0; return 0;
} }
f = fopen(fname_temp, "rb");
if (f == NULL) {
error("Can't read temp file: %s", fname_temp);
return 0;
}
if (f_report != NULL)
fprintf(f_report, "resampled %s\n", fname);
resample_count++;
resample_wav = true;
fseek(f, 40, SEEK_SET); // skip past the WAV header, up to before "data length"
}
displ = ftell(f_phdata); displ = ftell(f_phdata);
// data contains: 4 bytes of length (n_samples * 2), followed by 2-byte samples (lsb byte first) // data contains: 4 bytes of length (n_samples * 2), followed by 2-byte samples (lsb byte first)
@@ -1325,10 +1277,6 @@ static int LoadWavefile(FILE *f, const char *fname)
length++; length++;
} }
if (resample_wav == true) {
fclose(f);
remove(fname_temp);
}
return displ | 0x800000; // set bit 23 to indicate a wave file rather than a spectrum return displ | 0x800000; // set bit 23 to indicate a wave file rather than a spectrum
} }