Robin Siegemund
2007-Nov-23 19:37 UTC
[Vorbis-dev] Controlling the vorbis encoder precisely
Hello, currently I'm working on a vorbis based encoder that adds multiple single wave sounds into one vorbis stream (and put every sound in one or more ogg pages). During the process an index is written in an extra file so later you can locate a sound's position easily by a file position and length value. The problem is the sample-exact separation between those encoded wave sounds: If I add the audio data from a new wave sound to the encoding process the resulting vorbis packets also include some samples from the previous encoded wave file at the beginning. This seems to be caused by the vorbis encoder using a "delay window" (or something like that) during the process so there's always some data left in the current encoding state. So how can I flush those cached samples before every new audio data I'm going to add to the encoding process? Unfortunately there's still no documentation of libvorbis available even the original source code has no comments at all. And those encoder examples don't use all of the provided functionality. I tried the function vorbis_synthesis_restart() because it's named like the thing I've looking for but it doesn't work as expected. Currently I only use a hack which produces good but not perfect results: Before I add data from a new wave sound to the encoding process I set the pcm_current variable in the vorbis dsp state to 0 (it's typical size is about 3500). But there should be a more appropriate solution, isn't it? I'm looking forward to get some hints on this. Thx, Robin Siegemund, dp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/vorbis-dev/attachments/20071123/63db2a46/attachment.html
Erik de Castro Lopo
2007-Nov-24 08:21 UTC
[Vorbis-dev] Controlling the vorbis encoder precisely
Robin Siegemund wrote:> currently I'm working on a vorbis based encoder that adds multiple > single wave sounds into one vorbis streamWhy haven't you put them ins spearate streams?> The problem is the sample-exact separation between those encoded wave > sounds: If I add the audio data from a new wave sound to the encoding > process the resulting vorbis packets also include some samples from the > previous encoded wave file at the beginning.What you are basically doing is concatenating all the wave sounds than then running that concatenated signal through the encoder. Lossy encoders (like Vorbis and MP3) perform analysis on (possibly overlapping) chunks of audio and then looking for a way to encode that chunk at the require bit rate. If you butt to wave sounds up against one another then you will get bleed from one to the other across the boundary. There are two ways of avoiding this: - Use lossless encoding like FLAC. - Insert large chunks of silence between the wave sounds.> So how can I flush those cached samples before every new audio data > I'm going to add to the encoding process?You can have this if you start a new stream for each separate wave. HTH, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "Microsoft's biggest weakness is that they still don't realize how much they suck." -- Paul Graham
xiphmont@xiph.org
2007-Nov-24 12:49 UTC
[Vorbis-dev] Controlling the vorbis encoder precisely
On Nov 23, 2007 5:23 AM, Robin Siegemund <r.siegemund@digitalpublishing.de> wrote:> The problem is the sample-exact separation between those encoded wave > sounds: If I add the audio data from a new wave sound to the encoding > process the resulting vorbis packets also include some samples from the > previous encoded wave file at the beginning. > > This seems to be caused by the vorbis encoder using a "delay window" (or > something like that) during the process so there's always some data left in > the current encoding state.It is not using a delay window, it is using a lapped transform space. Any audio output from the encoder is the product of overlapping the inverse transform of two audio packets due to the way the MDCT works. You'll either need to pad the samples or use completely seperate chained streams. Monty