Link to home
Start Free TrialLog in
Avatar of AndersBranderud
AndersBranderud

asked on

Audiere; LNK2028-error

Hello!

I develope my program using Virtual C++ 2008 Express.
I use one library "libsndfile" (http://www.mega-nerd.com/libsndfile/) and another library called Audiere.
  When I compile I get the following errors:
  ------

 1>Linking...
 1>Ljudtestet3.obj : warning LNK4248: unresolved typeref token (0100002A) for 'SNDFILE_tag'; image may not run
 1>Ljudtestet3.obj : error LNK2028: unresolved token (0A0003DF) "public: virtual class audiere::OutputStream * __stdcall audiere::AudioDevice::openBuffer(void *,int,int,int,enum audiere::SampleFormat)" (?openBuffer@AudioDevice@audiere@@$$FUAGPAVOutputStream@2@PAXHHHW4SampleFormat@2@@Z) referenced in function "private: void __clrcall Ljudtestet3::form1::play_audio_file(int)" (?play_audio_file@form1@Ljudtestet3@@$$FA$AAMXH@Z)
 1>Ljudtestet3.obj : error LNK2019: unresolved external symbol "public: virtual class audiere::OutputStream * __stdcall audiere::AudioDevice::openBuffer(void *,int,int,int,enum audiere::SampleFormat)" (?openBuffer@AudioDevice@audiere@@$$FUAGPAVOutputStream@2@PAXHHHW4SampleFormat@2@@Z) referenced in function "private: void __clrcall Ljudtestet3::form1::play_audio_file(int)" (?play_audio_file@form1@Ljudtestet3@@$$FA$AAMXH@Z)
 1>D:\programmering\Visual C++ Express\Ljudtestet3\Debug\Ljudtestet3.exe : fatal error LNK1120: 2 unresolved externals
 1>Build log was saved at "file://d:\programmering\Visual C++ Express\Ljudtestet3\Ljudtestet3\Debug\BuildLog.htm"
 1>Ljudtestet3 - 3 error(s), 9 warning(s)
 ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I have googled the errors but I haven't find a solution. I have included the lib-files, so that is not the reason for the problem. I had some other linking errors that got resolved when I included the lib-files.

Here is what I want to do with the following code:
I want to mix two wav.files, one of them containing noise.
In order to do that I want the samples of both of the files placed in different buffers. After that I add them together into one of the buffers. After that I want to play the content of the buffer. As you notice above I get problems with the OutputStream.

(I also will implement so that the noise level will be increased/decreased depending on user input. I will possibly also increase/decrease the volume of the other sound file before I mix it.)

If you either solve the linking issue above, or provide me another solution with the same functionality that I can use in a commercial product (If you provide me another solution I can  write your name and what you contributed with in a document that I attach with the application), I am thankful!
 
Thanks in advance!

Anders Branderud
http://bloganders.blogspot.com
#include "audiere.h"
      #include "sndfile.h"
  
  audiere::OutputStream* output_stream2;
  
  //Alot of other code that you don't need to see to help with this problem..

  //Open file, get information about it and then close it.
  SNDFILE* file;
  SF_INFO file_info; //Accessible file information.
  file = sf_open ("ljudfiler/HF01.wav", SFM_READ, &file_info);
 
  if (! file)
    this->angra_message_textbox->Text="Error when using sf_open;file1";
  else 
    {
    file_noise_sample_rate = file_info.samplerate;
    file_noise_channels = file_info.channels;
    file_noise_number_of_frames = file_info.frames;
    sf_close (file);
    //Todo: Error handling.
    } 

  //Open file2, get information about it and then close it.
  SNDFILE* file2; //internal information on file.
  SF_INFO file_info2; //Accessible file information.
  file2 = sf_open ("ljudfiler/noise/cocktail_noise.wav", SFM_READ, &file_info2);
  
  if (!file2)
    this->angra_message_textbox->Text="Error when using sf_open;file2";

  else
    {
  file_sample_rate = file_info2.samplerate;
  file_channels = file_info2.channels;
  file_number_of_frames = file_info2.frames;
  sf_close (file2);
  //Todo: Error handling.
    }

  //Open files and read them into buffer.
  FILE* file_a = fopen ("ljudfiler/HF01.wav", "rb");
  long len;
  short int *buffer;

  if (! file_a)
  this->angra_message_textbox->Text="Fel när filen skulle öppnas...";
  
  else
    { 
    fseek (file_a,0, SEEK_END); //go to end..
    len = ftell (file_a); //get position at end (length)
    fseek (file_a,0,SEEK_SET); //go to beginning
    buffer = (short int*) malloc (len); //malloc buffer
    fread (buffer, len, 1, file_a); //read into buffer
    fclose (file_a);
    }

  FILE* file_b = fopen ("ljudfiler/noise/cocktail_noise.wav", "rb");
  long len2;
  short int *buffer2;
  
  if (!file_b )
  this->angra_message_textbox->Text="Fel när filen skulle öppnas...";
  
  else
    {
    fseek (file_b,0, SEEK_END); //go to end..
    len2 = ftell (file_b); //get position at end (length)
    fseek (file_b,0,SEEK_SET); //go to beginning
    buffer2 = (short int*) malloc (len2); //malloc buffer
    fread (buffer2, len2,1, file_b); //read into buffer
    fclose (file_b);
    }

  //Place in SampleBuffers to be able to mix the samples of both wav files.

  SampleBuffer* sample_buffer = CreateSampleBuffer (buffer,file_number_of_frames,file_channels,file_sample_rate,SF_S16);
  SampleBuffer* sample_buffer2 = CreateSampleBuffer (buffer2,file_noise_number_of_frames,file_noise_channels,file_noise_sample_rate,SF_S16);

  //Open a seekable sample source using the samples contained in the buffer.
  SampleSource* sample_source = sample_buffer->openStream ();
  SampleSource* sample_source2 = sample_buffer2->openStream ();

  sample_source -> read (file_number_of_frames, buffer);
  sample_source2 -> read (file_noise_number_of_frames, buffer2);

  //Now the samples are placed in a buffer and we can manipulate with the buffers.
  //Mix audio file with noise file.

  for (int i =0; i < file_number_of_frames; i++ )
    {
  buffer[i] = buffer[i]+buffer2[i];
    }

                                 //Now we want to play the resulting buffer, that contains samples of the mixed wav-files.
  SampleBuffer* sample_buffer3 = CreateSampleBuffer (buffer,file_number_of_frames,file_channels,file_sample_rate,SF_S16);
  int file_to_play_frames;
  int file_to_play_channels;
  int file_to_play_sample_rate;
  enum SampleFormat file_noise_format = SF_S16;
  AudioDevicePtr audio_device(OpenDevice());
  sample_buffer3->getFormat (file_to_play_channels, file_to_play_sample_rate, file_noise_format);
  output_stream2 = audio_device->AudioDevice::openBuffer (sample_buffer3, file_number_of_frames, file_to_play_channels,file_to_play_sample_rate,SF_S16);
 

  output_stream2->play(); //Play the content of buffer

      Sleep (20000);
  fclose (file_a);
  //Todo: Error handling.

Open in new window

SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> I have included the lib-files, so that is not the reason for the problem.
You know libraries have to be included in the correct order, right?

http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html
http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
Is there any particular reason why you are mixing managed C++ an unmanaged libraries? I'd rather go the unmanaged way here, since these libs will be easier to deal with.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial