diff --git a/Rapport2wavs.py b/Rapport2wavs.py index 11ce8f949c652bbd37732b53ede307aa7b7d52d5..6b0340d47ac65e2c3aa4a60b58013ad97fe94f82 100644 --- a/Rapport2wavs.py +++ b/Rapport2wavs.py @@ -6,11 +6,12 @@ parser = argparse.ArgumentParser() parser.add_argument('filename') args = parser.parse_args() -RORQUAL_HOPSIZE, RORQUAL_WINSIZE, RORQUAL_FE = 256, 4096, 4000 -CACHA_HOPSIZE, CACHA_WINSIZE, CACHA_FE = 256, 512, 64000 -RAPPORT_FE = 128_000 -rorqual_predPos = lambda p: int(((p * RORQUAL_HOPSIZE + (RORQUAL_WINSIZE/2 + RORQUAL_HOPSIZE * 13) / 2) / RORQUAL_FE - 1) * RAPPORT_FE) -cacha_predPos = lambda p: int(((p * CACHA_HOPSIZE * 8 + (CACHA_WINSIZE + CACHA_HOPSIZE * 7 * 6) / 2) / CACHA_FE - 0.05) * RAPPORT_FE) +RORQUAL_HOPSIZE, RORQUAL_WINSIZE, RORQUAL_FE, RORQUAL_SAMPLEPERSAMPLE = 256, 4096, 4000, 25600 +CACHA_HOPSIZE, CACHA_WINSIZE, CACHA_FE, CACHA_SAMPLEPERSAMPLE = 256, 512, 64000, 12800 +CACHA_RAPPORT_FE, RORQUAL_RAPPORT_FE, RAPPORT_N_CHANNELS = 128_000, 128_00, 5 +CACHA_NUM_DETEC, RORQUAL_NUM_DETEC = 10, 3 +rorqual_predPos = lambda p: int(((p * RORQUAL_HOPSIZE + (RORQUAL_WINSIZE/2 + RORQUAL_HOPSIZE * 13) / 2) / RORQUAL_FE - 1) * RORQUAL_RAPPORT_FE) +cacha_predPos = lambda p: int(((p * CACHA_HOPSIZE * 8 + (CACHA_WINSIZE + CACHA_HOPSIZE * 7 * 6) / 4 ) / CACHA_FE - 0.05) * CACHA_RAPPORT_FE) file = open(args.filename, 'r') lines = iter(file.readlines()) @@ -19,26 +20,24 @@ for l in lines: if l == ' rorqual predPeaks\n': l = next(lines) if ',' in l: + sig = np.zeros((30 * RORQUAL_RAPPORT_FE, RAPPORT_N_CHANNELS), dtype='int16') + peaks = np.array(l[:-2].split(',')).astype(int) l = next(lines) - if ',' in l: - sig = np.zeros((30 * 128_000, 5), dtype='int16') - peaks = np.array(l[:-2].split(',')).astype(int) + for p in peaks[:RORQUAL_NUM_DETEC]: l = next(lines) - for p in peaks: - l = next(lines) - samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, 5) - sig[rorqual_predPos(p):rorqual_predPos(p)+256000] = samples - sf.write(f'{args.filename[:-8]}_rorqual.wav', sig, RAPPORT_FE) + samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, RAPPORT_N_CHANNELS) + sig[rorqual_predPos(p):rorqual_predPos(p)+RORQUAL_SAMPLEPERSAMPLE] = samples[:min(rorqual_predPos(p)+RORQUAL_SAMPLEPERSAMPLE, len(sig))-rorqual_predPos(p)] + sf.write(f'{args.filename[:-8]}_rorqual.wav', sig, RORQUAL_RAPPORT_FE) if l == ' cacha predPeaks\n': l = next(lines) if ',' in l: - sig = np.zeros((10 * 128_000, 5), dtype='int16') + sig = np.zeros((10 * CACHA_RAPPORT_FE, RAPPORT_N_CHANNELS), dtype='int16') peaks = np.array(l[:-2].split(',')).astype(int) l = next(lines) - for p in peaks: + for p in peaks[:CACHA_NUM_DETEC]: l = next(lines) - samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, 5) - sig[cacha_predPos(p):cacha_predPos(p)+12800] = samples - sf.write(f'{args.filename[:-8]}_cacha.wav', sig, RAPPORT_FE) + samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, RAPPORT_N_CHANNELS) + sig[cacha_predPos(p):cacha_predPos(p)+CACHA_SAMPLEPERSAMPLE] = samples + sf.write(f'{args.filename[:-8]}_cacha.wav', sig, CACHA_RAPPORT_FE) file.close() diff --git a/RapportInfo2txt b/RapportInfo2txt index fe26c0854764098b3757999fa6823120478d86f0..be9448a1b15a8fb4ace1ea1c416955ef833250a5 100755 Binary files a/RapportInfo2txt and b/RapportInfo2txt differ diff --git a/RapportInfo2txt.c b/RapportInfo2txt.c index b10c2e9bf90495a762965d508106c237d4442ebc..ca1f568d69424c020a636ab7a0424dca6991e162 100755 --- a/RapportInfo2txt.c +++ b/RapportInfo2txt.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <math.h> #define NTOAS_MAX 200 @@ -13,8 +14,8 @@ #define RORQUAL_HOPSIZE 256 #define RORQUAL_LENPRED RORQUAL_LENSPEC - (5-1)*3 //3 layers of kernel size 5 #define RORQUAL_RAPPORT_NSAMPLESTOSEND 3 // see cacha -#define RORQUAL_RAPPORT_SAMPLE_RATE 128000 -#define RORQUAL_RAPPORT_SAMPLESPERSAMPLE 256000 // see cacha +#define RORQUAL_RAPPORT_SAMPLE_RATE 12800 +#define RORQUAL_RAPPORT_SAMPLESPERSAMPLE 25600 // see cacha #define CACHA_SAMPLE_RATE 64000 #define CACHA_LENSIG CACHA_SAMPLE_RATE*10 // load 10sec @@ -86,7 +87,7 @@ int main(int argc, char* argv[]){ fprintf(outfile, "%hd,", rapport.predPeaksC[i]); } fprintf(outfile, "\n cacha samples\n"); - for(i=0; i<rapport.numDetectionsCachalot; i++){ + for(i=0; i < fmin(rapport.numDetectionsCachalot, CACHA_RAPPORT_NSAMPLESTOSEND); i++){ for(j=0; j<CACHA_RAPPORT_SAMPLESPERSAMPLE; j++){ for(k=0; k<RAPPORT_CHANNELS; k++){ fprintf(outfile, "%hd,", rapport.samplesC[i][j][k]);