Thread: OGG Vorbis Decoder Error

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    47

    OGG Vorbis Decoder Error

    I've been trying to create some code in a program I am writing that will decode an OGG Vorbis file. I am using Dev-C++, the newest beta. When I run the compiled program on Windows, I get an error, and the program closes. Here is my code, followed by the flags used in Dev-C++.

    Code:
    #include <vorbis/codec.h>
    #include <vorbis/vorbisfile.h>
    #include <vorbis/vorbisenc.h>
    
    #include <gl/glut.h>
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    #include <wx/msgdlg.h>
    
    #ifdef _WIN32
     #include <io.h>
     #include <fcntl.h>
    #endif
    
    // Create a buffer for PCM audio output
    char pcmout[4096];
    
    // Declare vorbis file global variable
    OggVorbis_File OggFile;
    int end = 0;
    int current_section;
    
    // Create the initialization function
    void init()
     {
      glClearColor(1.0,1.0,1.0,0.0);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0.0,675.0,500.0,0.0);
     }
    
    // Create the display function
    void displayFunc()
     {
      // Clear the screen
      glClear(GL_COLOR_BUFFER_BIT);
    
      glPushMatrix();
    
      glColor3f(0.5,0.5,0.5);
    
      glBegin(GL_LINES);
       glVertex3f(15.0,15.0,0.0);
       glVertex3f(30.0,50.0,0.0);
      glEnd();
    
      glPopMatrix();
    
      glutSwapBuffers();
     }
    
    // Create a playback function
    void playback()
     {
      if(ov_open(stdin, &OggFile, NULL, 0) < 0)
       {
        wxMessageDialog error(NULL,wxT("Error!"),wxT("The file you specified is not in OGG Vorbis file format, or is corrupt and could not be opened."),wxOK);
        error.ShowModal();
        exit(1);
       }
      
      ov_clear(&OggFile);
     }
    
    // Create the main function
    int main(int argc, char *argv[])
     {
      #ifdef _WIN32
       _setmode( _fileno( stdin ), _O_BINARY );
       _setmode( _fileno( stdout ), _O_BINARY );
      #endif
    
      fopen("YourePitiful.ogg","rb");
    
      playback();
    
      glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
      glutInitWindowPosition(50,50);
      glutInitWindowSize(675,500);
      int drawWin = glutCreateWindow("Virtual Turntable Beta 1.0");
      glutDisplayFunc(displayFunc);
      init();
      glutMainLoop();
    
      fclose(stdin);
    
      return 0;
     }
    
    /*
    Compiler flags
    -fno-rtti
    -fno-exceptions
    -fno-pcc-struct-return
    -fstrict-aliasing
    -Wall
    -fvtable-thunks
    -D__WXMSW__
    -D__GNUWIN32__
    -D__WIN95__
    */
    
    /*
    C++ Compiler flags
    -fno-rtti
    -fno-exceptions
    -fno-pcc-struct-return
    -fstrict-aliasing
    -Wall
    -D__WXMSW__
    -D__GNUWIN32__
    -D__WIN95__
    -w
    */
    
    /*
    Linker flags
    -lwxmsw26
    -lwxmsw26_gl
    -lwxtiff
    -lwxjpeg
    -lwxpng
    -lwxzlib
    -lwxregex
    -lwxexpat
    -lkernel32
    -luser32
    -lgdi32
    -lcomdlg32
    -lwinspool
    -lshell32
    -lcomctl32
    -lole32
    -loleaut32
    -luuid
    -lrpcrt4
    -ladvapi32
    -lwsock32
    -lodbc32
    -lopengl32
    -lglut32
    -lglu32
    -lopengl32
    -lgdi32
    -lwinmm
    -logg_d
    -logg_static_d
    -lvorbis_d
    -lvorbis_static_d
    -lvorbisenc_d
    -lvorbisenc_static_d
    -lvorbisfile_d
    -lvorbisfile_static_d
    */
    Oh, yeah, I forgot to say that I will also be using parts of wxWidgets, mainly alert boxes, and GLUT, too. Even when I try to compile the Vorbis example code, I get the same error.
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > fopen("YourePitiful.ogg","rb");
    I've no idea what you're expecting this to do, but you need to assign the return result to a FILE* variable.

    It certainly doesn't make it stdin as the rest of your code seems to be.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    Quote Originally Posted by Salem
    > fopen("YourePitiful.ogg","rb");
    I've no idea what you're expecting this to do, but you need to assign the return result to a FILE* variable.
    How do assign it to a FILE* variable. STDIN is a FILE*, so what line of code should I use to set STDIN as "YourePitiful.ogg"?

    PS
    In case you're wondering, "You're Pitiful" is a Weird Al song.
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    Oh, wait. I think I found it.

    Code:
    /* fopen example */
    #include <stdio.h>
    int main ()
    {
      FILE * pFile;
      pFile = fopen ("myfile.txt","w");
      if (pFile!=NULL)
      {
        fputs ("fopen example",pFile);
        fclose (pFile);
      }
      return 0;
    }
    Thanks! I'll go test this.
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM