Dear Jan My intention is to read a piece at time of an .ogg file (stored in and external Multimedia card) decompress it and render it on and LPC2000 DAC. Because I don't have enough RAM memory to load the complete ogg file, I must read only a piece of file at certain time, then decompress and render it, and repeat the previous process until the end of the file. The problem is that I don't know what is the minimum file block size that I must consider. I red,of course, the example that exist in the speex manual, however I have some doubt. I got the FRAME_SIZE from the function /* Get frame size */ speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &nbBytes); repeat lb = file_read(&file, nbBytes, (void *)cbits); /*Copy the data into the bit-stream struct*/ speex_bits_read_from(&bits, cbits, nbBytes); /*Decode the data*/ speex_decode(state, &bits, output); until EOF (I get the number 160) that I use it in my file_read function to get a block of nbBytes (SPEEX_GET_FRAME_SIZE) bytes with which I feed the speex_bits_read_from(&bits, cbits, nbBytes). Then I call the and the speex_decode(state, &bits, output); The problem is that I receive the error message warning: Invalid mode encountered: corrupted stream? And the decode process doesn't continue. I have the suspect that the fetched block is too small. What is the minimum block side that speex_bits_read_from(&bits, cbits, nbBytes) accept ? Thank you Paolo
On Tue, Mar 21, 2006 at 09:56:04PM +0100, pberna@iol.it wrote:> My intention is to read a piece at time of an .ogg file (stored in and external Multimedia card) decompress it and render it on and LPC2000 DAC. Because I don't have enough RAM memory to load the complete ogg file, I must read only a piece of file at certain time, then decompress and render it, and repeat the previous process until the end of the file. The problem is that I don't know what is the minimum file block size that I must consider.What you appear to be missing is that the speex data packets are encapsulated in an Ogg container. You must first parse the Ogg header to extract the raw packets before passing them to libspeex with speex_bits_read_from(). It's not clear from your description that your file_read() function is doing all this. speexdec uses libogg to do this. Ogg pages produced by the reference encoder are around 4 kB, but by specification Ogg pages can be up to 65 kB in length. libogg will internally buffer a full page before returning any packet data for decode, so that's the minimum footprint you would have to design for. If you're in a memory contrained environment I'd recommend implementing your own ogg parser to pass the data to libspeex directly as it's read instead of buffering a whole page for checksum verification. You can either compute the checksum incrementally or dispense with it entirely and assume libspeex will detect any file corruption. Note that both of these are necessarily less robust against damaged files, but it should let you process data with an arbitrarily small read buffer. A compromise would be to use a static 5 kB buffer and verify the crc only if the page happens to fit, falling back to incremental parsing otherwise. HTH, -r