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,¤t_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@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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
On Sunday 27 July 2003 12:48 pm, David St.Clair wrote:> 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?> /* we don't bother dealing with sample rate changes, etc, but > you'll have to*/ > fwrite(pcmout,1,ret,dspdev);/dev/dsp probably defaults to some weird sample size and rate, so you'll need to do some ioctl()s on it before you write to it. I'm guessing the noise you hear is similar to the noise from "cat file.wav > /dev/dsp". -- Tom Felker The whole point of communication is sharing information. --- >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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
On Monday 28 July 2003 03:48, David St.Clair wrote:> 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?By default, /dev/dsp is opened in 8 bit mono u-law mode (I think). You need to set it to the correct format (generally 16 bit signed samples, and the appropriate sample rate and number of channels) using ioctl(). Mike --- >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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.