Generate Looppoints when saving a wav-file

Hi there,

I am writing a little software, which creates wave-files and I would like to set loop-points to it. But I’m apparently too stupid to implement it properly… :man_facepalming:

First I am creating a stringarray object with string pairs for the metadata which looks like this:

StringPairArray metadata;
metadata.set("Loop0Start", String(points.x));
metadata.set("Loop0End", String(points.y));
metadata.set("NumSampleLoops", "1");

“Loop0Start” is the tag for the start of the loop. The second parameter is the start-position as int.
“Loop0End” guess what that stands for,…
“NumSampleLoops” the loops amount. I just need one.

After that, I transmit the data…

std::unique_ptr<AudioFormatWriter> writer;
writer.reset(format.createWriterFor(outStream.get(), 44100.0, 2, 32, metadata, 0));

When I disable the loop-tags or with other words, when the metadata object is empty, the wav-file will be correct (without loop-points). However, when I transmit them, the wav file is faulty. I can open and analyze it. The loop points are also in the right place, but suddenly there are missing samples at the beginning of the wave, which means that everything shifts a little to the left (int time). left channel by 21 samples, right channel by 22 samples.

I’m not sure, but it seems like I need to provide more metadata. the missing metadata will then be taken over by the samples. is that correct?

what should it look like? Can someone give me a small example? Unfortunately I can’t find much information about it.

Thank you and best regards