diff --git a/Rapport2wavs.py b/Rapport2wavs.py new file mode 100644 index 0000000000000000000000000000000000000000..5497fcbf058c62e4e8a01e21c3b340ac0a8468d0 --- /dev/null +++ b/Rapport2wavs.py @@ -0,0 +1,44 @@ +import numpy as np +import soundfile as sf +import argparse + +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) + +file = open(args.filename, 'r') +lines = iter(file.readlines()) + +for l in lines: + if l == ' rorqual predPeaks\n': + l = next(lines) + if ',' in l: + l = next(lines) + if ',' in l: + sig = np.zeros((30 * 128_000, 5), dtype='int16') + peaks = np.array(l[:-2].split(',')).astype(int) + 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[:-9]}_rorqual.wav', sig, RAPPORT_FE) + if l == ' cacha predPeaks\n': + l = next(lines) + if ',' in l: + sig = np.zeros((10 * 128_000, 5), dtype='int16') + peaks = np.array(l[:-2].split(',')).astype(int) + l = next(lines) + for p in peaks: + 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[:-9]}_cacha.wav', sig, RAPPORT_FE) + +file.close() diff --git a/RapportInfo2txt b/RapportInfo2txt index eaec6d4a3e5d9220e79d216ec3cf989f36b46aaa..fe26c0854764098b3757999fa6823120478d86f0 100755 Binary files a/RapportInfo2txt and b/RapportInfo2txt differ diff --git a/RapportInfo2txt.c b/RapportInfo2txt.c index ca885ba555ac0fa6e87e92d3b33d857ed8a8220a..b10c2e9bf90495a762965d508106c237d4442ebc 100755 --- a/RapportInfo2txt.c +++ b/RapportInfo2txt.c @@ -72,7 +72,7 @@ int main(int argc, char* argv[]){ for(i=0; i<rapport.numDetectionsRorqual; i++){ for(j=0; j<RORQUAL_RAPPORT_SAMPLESPERSAMPLE; j++){ for(k=0; k<RAPPORT_CHANNELS; k++){ - // fprintf(outfile, "%hd,", rapport.samplesR[i][j][k]); + fprintf(outfile, "%hd,", rapport.samplesR[i][j][k]); } } fprintf(outfile, "\n"); @@ -89,7 +89,7 @@ int main(int argc, char* argv[]){ for(i=0; i<rapport.numDetectionsCachalot; i++){ for(j=0; j<CACHA_RAPPORT_SAMPLESPERSAMPLE; j++){ for(k=0; k<RAPPORT_CHANNELS; k++){ - // fprintf(outfile, "%hd,", rapport.samplesC[i][j][k]); + fprintf(outfile, "%hd,", rapport.samplesC[i][j][k]); } } fprintf(outfile, "\n");