[vorbis-dev] Flushing audio

Eric Ross eross+vorbis-dev at disc.ucn.cl
Thu Sep 11 22:52:14 PDT 2003



Hi there again..

I'm still writing my particular-case-vorbis-encoder-and-player, and it 
worked fine until now.

I'm having a problem trying to encoding the audio. I need to send the data 
very quickly, as soon as i capture it from the sound card.

Currently i have the following (audio captured 16 bits, mono):

void VorbisEncoder::encode(void *data, int r)
{
        char *buf = (char *) data;
        int vals = r / 2;
                        
        float **buffer = vorbis_analysis_buffer(&dsp_state, vals);
        
        for(int i=0;i<vals;i++){
                buffer[0][i] = ((buf[i*2 + 1] << 8) | 
                                (0x00ff & (int) buf[i*2])) / 32768.f;
        }
        
        vorbis_analysis_wrote(&dsp_state, vals);

        while(vorbis_analysis_blockout(&dsp_state, &vblock) == 1){
                ogg_packet ogg_pkt;
                vorbis_analysis(&vblock, &ogg_pkt);
                ogg_stream_packetin(&ogg_stream, &ogg_pkt);

                while(1){
                        int result = ogg_stream_flush(&ogg_stream, &page);
                                        
                        if(!result)
                                break;
                                        
                        write_ogg_page(&page);
                }
        }
}

My problem is that in some cases, i capture some data from the sound card 
and i feed it to this function, but vorbis_analysus_blockout doesnt output 
any block.

When i encode all the data i capture from the sound card (continuos 
audio), it works fine. But if i start detecting levels, and sending to the 
encoder only the audio louder that some level, in some cases 
vorbis_analysis_blockout returns 0.  I guess it's because it doesnt have 
enought data to output a regular block.

Any idea how can i make it work ? Or maybe using vorbis to try to transmit 
realtime audio is not a good idea ?

Thanks in advance


-- 
The names of their development products, visual this, visual that, almost 
makes one think that you can create software just by looking at your computer

<p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Vorbis-dev mailing list