[vorbis] Ogg ouput using libvorbisfile

David St.Clair dstclair at cs.wcu.edu
Sun Jul 27 10:48:42 PDT 2003



Hi, I'm new to writing any kind of sound program and somewhat new to C. 
I am on linux and I've been trying to get the example code
(http://www.xiph.org/ogg/vorbis/doc/vorbisfile/example.html)for the
decoder using libvorbisfile to work.  I think my main problem is output
to /dev/dsp.  If I use the example where the only change I made were to
open a file instead of using stdin and I ouput to /dev/dsp after opening
it, I get a weird static noise.

Any idea what I'm doing wrong or not doing?  

<code>

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "vorbis/codec.h"
#include "vorbis/vorbisfile.h"

char pcmout[4096];

int main()

{
  FILE * input;
  FILE * dspdev;
  OggVorbis_File *vf;
  int eof=0;
  int current_section;

/* Opening File */

if ((input = fopen("sound.ogg", "r")) == NULL)
           fprintf(stderr, "Cannot open %s\n", "sound.ogg");

/* Opening /dev/dsp for writing*/

dspdev=fopen("/dev/dsp","w");
  if (!dspdev)
          fprintf(stderr, "Cannont open dsp device");

vf=(OggVorbis_File*)malloc(sizeof(OggVorbis_File));

while(!eof){
    long ret=ov_read(vf,pcmout,sizeof(pcmout),0,2,1,&current_section);
                                //fprintf(stderr,"Reading\n");
    if (ret == 0) {
      /* EOF */
      eof=1;
    } else if (ret < 0) {
      /* error in the stream.  Not a problem, just reporting it in
         case we (the app) cares.  In this case, we don't. */
    } else {
      /* we don't bother dealing with sample rate changes, etc, but
         you'll have to*/
      fwrite(pcmout,1,ret,dspdev);	
    }
  }
    ov_clear(vf);
    free(vf);
    fclose(dspdev);
    fprintf(stderr,"Done.\n");
    return (0);
}

<p></code>

Thank you,

<p>
-- 
David St.Clair <dstclair at cs.wcu.edu>

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