Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. speex - undefined reference

speex - undefined reference

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structures
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daerner Mandla
    wrote on last edited by
    #1

    Hello,

    #include "speex/speex.h"
    #include

    /*The frame size in hardcoded for this sample code but it doesn't have to be*/
    #define FRAME_SIZE 160
    int main(int argc, char **argv)
    {
    char *inFile;
    FILE *fin;
    short in[FRAME_SIZE];
    float input[FRAME_SIZE];
    char cbits[200];
    int nbBytes;
    /*Holds the state of the encoder*/
    void *state;
    /*Holds bits so they can be read and written to by the Speex routines*/
    SpeexBits bits;
    int i, tmp;

    /*Create a new encoder state in narrowband mode*/
    state = speex_encoder_init(&speex_nb_mode);

    /*Set the quality to 8 (15 kbps)*/
    tmp=8;
    speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp);

    inFile = argv[1];
    fin = fopen(inFile, "r");

    /*Initialization of the structure that holds the bits*/
    speex_bits_init(&bits);
    while (1)
    {
    /*Read a 16 bits/sample audio frame*/
    fread(in, sizeof(short), FRAME_SIZE, fin);
    if (feof(fin))
    break;
    /*Copy the 16 bits values to float so Speex can work on them*/
    for (i=0;i<frame_size;i++)>
    input[i]=in[i];

      /\*Flush all the bits in the struct so we can encode a new frame\*/
      speex\_bits\_reset(&bits);
    
      /\*Encode the frame\*/
      speex\_encode(state, input, &bits);
      /\*Copy the bits to an array of char that can be written\*/
      nbBytes = speex\_bits\_write(&bits, cbits, 200);
    
      /\*Write the size of the frame first. This is what sampledec expects but
       it's likely to be different in your own application\*/
      fwrite(&nbBytes, sizeof(int), 1, stdout);
      /\*Write the compressed data\*/
      fwrite(cbits, 1, nbBytes, stdout);
    

    }

    /*Destroy the encoder state*/
    speex_encoder_destroy(state);
    /*Destroy the bit-packing struct*/
    speex_bits_destroy(&bits);
    fclose(fin);
    return 0;
    }

    This libs are include Libs: libspeex.lib und libspeexdsp.lib But my Compiler Say: H:\speex\main.cpp|21|undefined reference to `speex_nb_mode'| What is the mistake?

    C A 2 Replies Last reply
    0
    • D Daerner Mandla

      Hello,

      #include "speex/speex.h"
      #include

      /*The frame size in hardcoded for this sample code but it doesn't have to be*/
      #define FRAME_SIZE 160
      int main(int argc, char **argv)
      {
      char *inFile;
      FILE *fin;
      short in[FRAME_SIZE];
      float input[FRAME_SIZE];
      char cbits[200];
      int nbBytes;
      /*Holds the state of the encoder*/
      void *state;
      /*Holds bits so they can be read and written to by the Speex routines*/
      SpeexBits bits;
      int i, tmp;

      /*Create a new encoder state in narrowband mode*/
      state = speex_encoder_init(&speex_nb_mode);

      /*Set the quality to 8 (15 kbps)*/
      tmp=8;
      speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp);

      inFile = argv[1];
      fin = fopen(inFile, "r");

      /*Initialization of the structure that holds the bits*/
      speex_bits_init(&bits);
      while (1)
      {
      /*Read a 16 bits/sample audio frame*/
      fread(in, sizeof(short), FRAME_SIZE, fin);
      if (feof(fin))
      break;
      /*Copy the 16 bits values to float so Speex can work on them*/
      for (i=0;i<frame_size;i++)>
      input[i]=in[i];

        /\*Flush all the bits in the struct so we can encode a new frame\*/
        speex\_bits\_reset(&bits);
      
        /\*Encode the frame\*/
        speex\_encode(state, input, &bits);
        /\*Copy the bits to an array of char that can be written\*/
        nbBytes = speex\_bits\_write(&bits, cbits, 200);
      
        /\*Write the size of the frame first. This is what sampledec expects but
         it's likely to be different in your own application\*/
        fwrite(&nbBytes, sizeof(int), 1, stdout);
        /\*Write the compressed data\*/
        fwrite(cbits, 1, nbBytes, stdout);
      

      }

      /*Destroy the encoder state*/
      speex_encoder_destroy(state);
      /*Destroy the bit-packing struct*/
      speex_bits_destroy(&bits);
      fclose(fin);
      return 0;
      }

      This libs are include Libs: libspeex.lib und libspeexdsp.lib But my Compiler Say: H:\speex\main.cpp|21|undefined reference to `speex_nb_mode'| What is the mistake?

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Your variable speex_nb_mode is never defined. You first have to define a variable before being able to use it (for instance you are passing its address to the speex_encoder_init function and the variable doesn't even exist).

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • D Daerner Mandla

        Hello,

        #include "speex/speex.h"
        #include

        /*The frame size in hardcoded for this sample code but it doesn't have to be*/
        #define FRAME_SIZE 160
        int main(int argc, char **argv)
        {
        char *inFile;
        FILE *fin;
        short in[FRAME_SIZE];
        float input[FRAME_SIZE];
        char cbits[200];
        int nbBytes;
        /*Holds the state of the encoder*/
        void *state;
        /*Holds bits so they can be read and written to by the Speex routines*/
        SpeexBits bits;
        int i, tmp;

        /*Create a new encoder state in narrowband mode*/
        state = speex_encoder_init(&speex_nb_mode);

        /*Set the quality to 8 (15 kbps)*/
        tmp=8;
        speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp);

        inFile = argv[1];
        fin = fopen(inFile, "r");

        /*Initialization of the structure that holds the bits*/
        speex_bits_init(&bits);
        while (1)
        {
        /*Read a 16 bits/sample audio frame*/
        fread(in, sizeof(short), FRAME_SIZE, fin);
        if (feof(fin))
        break;
        /*Copy the 16 bits values to float so Speex can work on them*/
        for (i=0;i<frame_size;i++)>
        input[i]=in[i];

          /\*Flush all the bits in the struct so we can encode a new frame\*/
          speex\_bits\_reset(&bits);
        
          /\*Encode the frame\*/
          speex\_encode(state, input, &bits);
          /\*Copy the bits to an array of char that can be written\*/
          nbBytes = speex\_bits\_write(&bits, cbits, 200);
        
          /\*Write the size of the frame first. This is what sampledec expects but
           it's likely to be different in your own application\*/
          fwrite(&nbBytes, sizeof(int), 1, stdout);
          /\*Write the compressed data\*/
          fwrite(cbits, 1, nbBytes, stdout);
        

        }

        /*Destroy the encoder state*/
        speex_encoder_destroy(state);
        /*Destroy the bit-packing struct*/
        speex_bits_destroy(&bits);
        fclose(fin);
        return 0;
        }

        This libs are include Libs: libspeex.lib und libspeexdsp.lib But my Compiler Say: H:\speex\main.cpp|21|undefined reference to `speex_nb_mode'| What is the mistake?

        A Offline
        A Offline
        alphaxz
        wrote on last edited by
        #3

        you have to add libspeex.lib libspeexdsp.lib into the project setting ->link->object/library modules blank

        a beginner

        D 1 Reply Last reply
        0
        • A alphaxz

          you have to add libspeex.lib libspeexdsp.lib into the project setting ->link->object/library modules blank

          a beginner

          D Offline
          D Offline
          Daerner Mandla
          wrote on last edited by
          #4

          The whole time both libarys are include in the speex projekt. If i dont link it, there were more errors like this one. I think &speex_nb_mode is not difine in the both libs?

          C 1 Reply Last reply
          0
          • D Daerner Mandla

            The whole time both libarys are include in the speex projekt. If i dont link it, there were more errors like this one. I think &speex_nb_mode is not difine in the both libs?

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            Did you read my reply ? speex_nb_mode is a variable, so you should declare it somewhere. It is like using an integer, you first have to declare it before using it. Is this variable supposed to be declared as a global variable in your library ? What is the type of this variable ? I am pretty sure you are missing the point here and simply forgot to declare the variable and blame it on the library :)

            Cédric Moonen Software developer
            Charting control [v1.5] OpenGL game tutorial in C++

            D 1 Reply Last reply
            0
            • C Cedric Moonen

              Did you read my reply ? speex_nb_mode is a variable, so you should declare it somewhere. It is like using an integer, you first have to declare it before using it. Is this variable supposed to be declared as a global variable in your library ? What is the type of this variable ? I am pretty sure you are missing the point here and simply forgot to declare the variable and blame it on the library :)

              Cédric Moonen Software developer
              Charting control [v1.5] OpenGL game tutorial in C++

              D Offline
              D Offline
              Daerner Mandla
              wrote on last edited by
              #6

              hmm the docu: 5.1.4.10 void speex_encoder_init (const SpeexMode mode) Returns a handle to a newly created Speex encoder state structure. For now, the "mode" argument can be &nb_mode or &wb_mode . In the future, more modes may be added. Note that for now if you have more than one channels to encode, you need one state per channel. Parameters: mode The mode to use (either speex_nb_mode or speex_wb.mode) Returns: A newly created encoder state or NULL if state allocation fails The error in VC++08;

              failsextry2.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_speex_nb_mode".

              I think it isnt a variable. Ah, in speex.h

              /**
              * Returns a handle to a newly created Speex encoder state structure. For now,
              * the "mode" argument can be &nb_mode or &wb_mode . In the future, more modes
              * may be added. Note that for now if you have more than one channels to
              * encode, you need one state per channel.
              *
              * @param mode The mode to use (either speex_nb_mode or speex_wb.mode)
              * @return A newly created encoder state or NULL if state allocation fails
              */
              void *speex_encoder_init(const SpeexMode *mode);

              modified on Tuesday, February 3, 2009 9:41 AM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups