I have a number of .wav files in a folder. I want to:
- Import each file as data,
- cut each list into a certain number of small lists,
- export each list as .csv.
The .wav files have a length of approx. 25 s with 48 kHz (approx. 1,400,000 samples).
What's the bottleneck here? The for loops? What would be a faster formulation?
Thanks in advance.
fps = 48000;
fullpath = (* "path to folder" *)
peaklist = {69373, 194369, 328822, 449814, 578921, 693582, 816820, 954078, 1084577, 1213780};
For[mic = 1, mic <= 82, mic++,
sig = Import[fullpath<>"S__"<>StringTake["_"<>ToString[mic],-2<>"_Take01_M24.wav","Data"]//Flatten;
For[peak=1, peak<=Length[peaklist], peak++,
von=peaklist[[peak]]-4800;
bis=von+fps-1;
Export[fullpath<>"Cut\\"<>plate<>"_Take"<>ToString[peak]<>"_Mic"<>ToString[mic]<>".csv",sig[[von ;; bis]]];
];
];
UPDATE
I found the .csv export to be horribly slow. Since I have simple lists I will export them as binaries:
a = RandomReal[1, 48000];
AbsoluteTiming[Export["test.csv", a]]
{2.5001, "test.csv"}
AbsoluteTiming[
file = "test.bin";
BinaryWrite[file, a, "Real32"]
Close[file];
]
{0.0061165, Null}