[vorbis-dev] decoder_example -- event driven?

Wayne F Davis wfdavis at seas.upenn.edu
Thu Apr 5 22:58:12 PDT 2001



I'm trying to adapt decoder_example to to support more of an event driven
model.  I'm building an RTSP client/server where the client will have a
function called everytime a new packet comes in.  So, I want to queue
up these packets to be played.

My current attack is as follows (note this isn't very robust and I
realized that):

For first and second packet i grab all the header stuff in the same way
as decoder_example.  From the third packet on, I send it to a bunch of
code:

      float **pcm;
      int samples;

      buffer=ogg_sync_buffer(&oy,4096);
  
      bytes = 4096;
      buffer = memcpy (buffer, data, bytes);

      ogg_sync_wrote(&oy,bytes);

      ogg_sync_pageout(&oy,&og);
      ogg_stream_pagein(&os,&og); /* can safely ignore errors at
                                     this point */
      
      /* we have a packet.  Decode it */
      
      if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
        vorbis_synthesis_blockin(&vd,&vb);
      /* 
         
      **pcm is a multichannel float vector.  In stereo, for
      example, pcm[0] is left, and pcm[1] is right.  samples is
      the size of each channel.  Convert the float values
      (-1.<=range<=1.) to whatever PCM format and write it out */
      
      while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0) {
        int i,j;
        int clipflag=0;
        int bout=(samples<convsize?samples:convsize);
      
        fprintf (stderr,
                 "\nhoebag, i made it the while loop");

        /* convert floats to 16 bit signed ints (host order) and
           interleave */
        for(i=0;i<vi.channels;i++){
          ogg_int16_t *ptr=convbuffer+i;
          float  *mono=pcm[i];
          for(j=0;j<bout;j++){
#if 1
            int val=mono[j]*32767.f;
#else /* optional dither */
            int val=mono[j]*32767.f+drand48()-0.5f;
#endif
            /* might as well guard against clipping */
            if(val>32767){
              val=32767;
              clipflag=1;
            }
            if(val<-32768){
              val=-32768;
              clipflag=1;
            }
            *ptr=val;
            ptr+=2;
          }
        }
        
        if(clipflag)
          fprintf(stderr,"Clipping in frame %ld\n",(long)(vd.sequence));
        
        
        write (mywav, convbuffer, 2*vi.channels*bout);

        vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
                                            many samples we
                                            actually consumed */
      }	    


---

So, the first packets come in fine because I can retrieve the title, etc
properly.  All of the packets come in correctly because I write them out
to disk and it is the same file as the original file.  However, when I put
the packets through the above code, I lose a lot of information and the
mywav file is a small portion of what it should be.

If anyone has some ideas how I can solve this problem, I would appreciate
any help.

Thanks,
Wayne

-- 
Wayne Davis - wfdavis at seas.upenn.edu - PGP Key Available

--- >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