Issues when using OggVorbisAudioFormat

Hello Jules

When I copy samples from ogg writer to an ogg reader, the samples are slowly starting to add gain and quite fast (after like 5 times) the gain is growing exponentially.

When I change that format to Aiff (both writer and reader) everything works fine.

I saw that in AudioFormatWriter::writeFromAudioReader() the reader’s usesFloatingPointData is true while the writer’s is false, (both for Ogg) it that OK?

Thank you

Sorry, not sure I understand? What’s increasing?

writeFromAudioReader is pretty robust, I don’t think that’ll be at fault.

This is a small example:

	for(int i = 0 ; i < 30 ; i++)
		Logger::info("max left level = "+String(heightLeft));
                memoryBlock_ = MemoryBlock();
		MemoryOutputStream* mos_ = new MemoryOutputStream(memoryBlock_, false);
		ScopedPointer<AudioFormatWriter> writer_(oggAudioFormat.createWriterFor(mos_, reader_->sampleRate,
			reader_->numChannels, (int) reader_->bitsPerSample,
			metadata, 0));

		writer_->writeFromAudioReader(*reader_, 0, reader_->lengthInSamples);

		writer_ = nullptr;

		MemoryInputStream* mis = new MemoryInputStream(memoryBlock_, true);
		reader_ = formatManager.createReaderFor(mis);

And this is the output:

INFO: max left level = 0.218616098
INFO: max left level = 0.204231709
INFO: max left level = 0.206640586
INFO: max left level = 0.225213498
INFO: max left level = 0.252182543
INFO: max left level = 0.255244434
INFO: max left level = 0.269231647
INFO: max left level = 0.290262252
INFO: max left level = 0.34386158
INFO: max left level = 0.401432842
INFO: max left level = 0.521992564
INFO: max left level = 0.787255526
INFO: max left level = 0.993495464
INFO: max left level = 1.42068315
INFO: max left level = 1.25658786
INFO: max left level = 1.2999177
INFO: max left level = 1.32784843
INFO: max left level = 1.33962893
INFO: max left level = 1.30674279
INFO: max left level = 1.30497968
INFO: max left level = 1.30894351
INFO: max left level = 1.29625916
INFO: max left level = 1.43839705
INFO: max left level = 1.50773096
INFO: max left level = 1.35312033
INFO: max left level = 1.54765451
INFO: max left level = 1.63104928
INFO: max left level = 1.84495401
INFO: max left level = 1.64452207
INFO: max left level = 1.56579041

not sure if its related, but i had some problem with mp3. If you skip through a mp3 file to a certain position, it takes some time until the signal has its full level. I believe is has to do with the frequency related compression, so it needs some samples pre-reading to reconstruct the original signal.

Well of course there’ll be some level creep if you repeatedly bounce it like that, decompressing and re-compressing the data each time!

I don’t understand, how can I go from a writer to a reader without an outputStream, cause AudioFormat::createWriterFor() must use outputStream?

And why does it have to grow that much when using this compression/decompression?

Sorry, your code isn’t easy to understand… It looks like you’re bouncing audio back and forth 30 times. Is that not what it’s supposed to do?

It’s a crazy thing to do - like repeatedly bouncing from tape-to-tape in the old days, the quality and levels will inevitably get screwed up, even if it only changes a tiny bit each time.

Thanks Jules, I will remove the compressing / decompressing.

When I change the format from Ogg to Aiff then the numbers stays exactly the same, is that the format itself or its implementation, how can that be?

aiff is uncompressed, so it’ll just store any numbers that you throw at it. Ogg is a lossy compression format, so the numbers that go in aren’t necessarily going to come out exactly the same. You seem overly confused by this…!

I understand, It just that I thought that it will result in only a small variation in the audio, and although I did 30 iterations, the deviation is huge.