0
0

Hello everybody,

I’m having problems of using ERRCHECK(FMOD_RESULT result) in multiple files. I need the ERRCHECK in both files though(code is below all stacked together). When i’m building (VC++ 7.0) i’m getting a link 2005 error:
audiotest error LNK2005: "void __cdecl ERRCHECK(enum FMOD_RESULT)" (?ERRCHECK@@YAXW4FMOD_RESULT@@@Z) already defined in AudioLoop.obj


CODE PART:

Files of this program(are also available from: [url:bnfjal2m]http://adaptief.hku.nl/c/[/url:bnfjal2m]):
[list:bnfjal2m]
AudioLoop.cpp
AudioLoop.h
errfunc.h
fmod.h
fmod.hpp
fmod_errors.hpp
Mathl.cpp(optional)
Mathl.h(optional)
[/list:u:bnfjal2m]

AudioLoop.h
[code:bnfjal2m]

pragma once

include "fmod.hpp"

include "fmod_errors.h"

include "Mathl.h"

include "errfunc.h"

include <vector>

include <iostream>

using namespace std;

class AudioLoop
{
//Channel properties
FMOD::Channel *channel;
bool channelpaused;
static float channelvolume;
int channelcrossfadetime;

//Sound properties
FMOD::Sound *sound;
char *filename;
static int maxnumberofrepeats;

vector&lt;int&gt; breakpoints;
FMOD_RESULT result;
bool beentroughCrossFadeOnce;
bool beentroughCurrentUpdate;
unsigned int breakpoint;

void init();

public:

//constuctor &amp; destructors
AudioLoop();
~AudioLoop();
AudioLoop(char *filename, int maxnumberofrepeats, int crossfadetime, vector&lt;int&gt; breakpoints);

FMOD::Sound* LoadSound();

//inits etc
void setdata(char *filename, int maxnumberofrepeats, int crossfadetime, vector&lt;int&gt; breakpoints);

//functions
int getCurrentLocationReference();
bool updatePosition(AudioLoop *otherfile);
float* Crossfade(AudioLoop *otherfile);

//retrieve functions    
FMOD::Channel*      getChannel();
FMOD::Sound*        getSound();
bool                getPausedChannel();
bool                getbeentroughCrossFadeOnce(); 
bool                getbeentroughCurrentUpdate();
float               getChannelVolume();

void                setbeentroughCrossFadeOnce(bool truefalse);
void                setbeentroughCurrentUpdate(bool truefalse);
void                setChannelPaused(bool truefalse);
void                setChannelVolume(float newvolume);

};
[/code:bnfjal2m]

AudioLoop.cpp
[code:bnfjal2m]

include "audioloop.h"

float AudioLoop::channelvolume = 0.0;
int AudioLoop::maxnumberofrepeats = 0;

AudioLoop::AudioLoop()
{
init();
}

AudioLoop::~AudioLoop()
{
}

AudioLoop::AudioLoop(char *filename, int maxnumberofrepeats, int crossfadetime, vector<int> breakpoints)
{
init();
setdata(filename, maxnumberofrepeats, crossfadetime, breakpoints);
}

FMOD::Sound* AudioLoop::LoadSound()
{
FMOD::System *sys;
result = channel->getSystemObject(&sys);
ERRCHECK(result);

result = sys-&gt;createStream(filename, FMOD_NONBLOCKING, 0, &amp;sound);
ERRCHECK(result);
return sound;

}

void AudioLoop::init()
{
filename = "";
maxnumberofrepeats = 0;
breakpoint = 0;
channel = 0;
channelcrossfadetime = 44100;
channelpaused = false;
beentroughCrossFadeOnce = false;
beentroughCurrentUpdate = false;

}

void AudioLoop::setdata(char *filename, int maxnumberofrepeats, int crossfadetime, vector<int> breakpoints)
{
this->filename = filename;
this->maxnumberofrepeats = maxnumberofrepeats;
this->channelcrossfadetime = crossfadetime;
this->breakpoints = breakpoints;
}

int AudioLoop::getCurrentLocationReference()
{
if (beentroughCurrentUpdate == false)
{
//FMOD::System *sys; //0: Position of file
//FMOD::Sound *sound; //1: nearest possible breakpoint(number)
//FMOD_RESULT result; //2: nearest possible breakpoint(time)
int nearestbreakpoint, breakpointssize;
unsigned int position, length = 0;

    result = channel-&gt;getPosition(&amp;position, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

    result = channel-&gt;getCurrentSound(&amp;sound);
    ERRCHECK(result);

    result = sound-&gt;getLength(&amp;length, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

    breakpointssize = (int)breakpoints.size();

    unsigned int min = length;
    cout &lt;&lt; &quot;minimum: &quot; &lt;&lt; min &lt;&lt; endl;
    for (int i = 0; i &lt; breakpointssize; i++)
    {
        int tempbreakpoints = breakpoints[i];
        unsigned int tempding = (tempbreakpoints - position);
        if (tempding &lt; min)
        {
            min = breakpoints[i];
            nearestbreakpoint = i;
        }
    }
    breakpoint = min;

}
beentroughCurrentUpdate = true;
return breakpoint;

}
bool AudioLoop::updatePosition(AudioLoop *otherfile)
{
//if (AudioChange == true)
//{
unsigned int position;
channel->getPosition(&position, FMOD_TIMEUNIT_PCM);

if (position &gt;= breakpoint)
{
    if (!beentroughCrossFadeOnce)
    {
        cout &lt;&lt; &quot;Position for crossfading reached/passed!&quot; &lt;&lt; endl;
    }
    else
    {
        //cout &lt;&lt; &quot;Current position: &quot; &lt;&lt; position &lt;&lt; endl &lt;&lt; &quot;Breakpoint: &quot; &lt;&lt; *returnresult &lt;&lt; endl;
    }
    Crossfade(otherfile);
    return true;
}
return false;
//}
//return false;

}

FMOD::Channel* AudioLoop::getChannel()
{
return channel;
}
FMOD::Sound* AudioLoop::getSound()
{
return sound;
}

float* AudioLoop::Crossfade(AudioLoop *otherfile)
{
if (!beentroughCrossFadeOnce)
{
setChannelVolume(1.0);
setbeentroughCrossFadeOnce(true);
}

setChannelVolume((getChannelVolume() * 0.97)); 
otherfile-&gt;setChannelVolume(0.0+(1.0-channelvolume));

if (otherfile-&gt;getPausedChannel())
{
    otherfile-&gt;setChannelPaused(false);
}
if (channelvolume &lt;= 0.01)
{
    otherfile-&gt;setChannelVolume(1.0);
    setChannelPaused(true);
}
/*bool isPaused;
int crossfadetime = 44100;
static unsigned int crossfadedif1, crossfadedif2, crossfademin;


static float volume, volumechannel2;
FMOD_RESULT result;
if (!beentroughCrossfadeOnce)
{
    volume = 1.0;   // digital volume, between 0.0 and 1.0;
    result = channel-&gt;getPosition(&amp;crossfadedif1, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);
    beentroughCrossfadeOnce = true;
    crossfademin = crossfadedif1;       
}
result = channel-&gt;getPosition(&amp;crossfadedif2, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);

if ((crossfadedif2 - crossfadedif1) &lt; crossfademin)
{
    crossfademin = crossfadedif2 - crossfadedif1;
}

volume *= 0.97;

volumechannel2 = 0.0 + (1.0 - volume);

result = channel2-&gt;getPaused(&amp;isPaused);
ERRCHECK(result);
if (isPaused)
{
    cout &lt;&lt; &quot;Channel 2 PAUSED = &quot; &lt;&lt; isPaused &lt;&lt; endl;
    result = channel2-&gt;setVolume(volumechannel2);
    ERRCHECK(result);

    result = channel2-&gt;setPaused(false);
    ERRCHECK(result);
}
result = channel2-&gt;setVolume(volumechannel2);
ERRCHECK(result);

if (volume &lt;= 0.01)
{
    volume = 0.0;
    volumechannel2 = 1.0;
    result = channel-&gt;setPaused(true);
    ERRCHECK(result);
    result = channel2-&gt;setVolume(volumechannel2);
    ERRCHECK(result);
    //result = channel2-&gt;
}
else
{
    channel-&gt;setVolume(volume);
}
return &amp;volume;*/
return &amp;channelvolume;

}

bool AudioLoop::getPausedChannel()
{
return channelpaused;
}

bool AudioLoop::getbeentroughCrossFadeOnce()
{
return beentroughCrossFadeOnce;
}

bool AudioLoop::getbeentroughCurrentUpdate()
{
return beentroughCurrentUpdate;
}

float AudioLoop::getChannelVolume()
{
return channelvolume;
}

void AudioLoop::setbeentroughCrossFadeOnce(bool truefalse)
{
beentroughCrossFadeOnce = truefalse;
}

void AudioLoop::setbeentroughCurrentUpdate(bool truefalse)
{
beentroughCurrentUpdate = truefalse;
}

void AudioLoop::setChannelPaused(bool truefalse)
{
if (truefalse != channelpaused)
{
channelpaused = truefalse;
result = channel->setPaused(truefalse);
ERRCHECK(result);
}
}

void AudioLoop::setChannelVolume(float newvolume)
{
if (channelvolume != newvolume)
{
channelvolume = newvolume;
result = channel->setVolume(newvolume);
ERRCHECK(result);
}
}
[/code:bnfjal2m]

main.cpp
[code:bnfjal2m]

include "fmod.hpp"

include "fmod_errors.h"

include "Mathl.h"

include "AudioLoop.h"

include <conio.h>

include <windows.h>

include <stdio.h>

include <vector>

include <iostream>

include <iomanip>

using namespace std;

FMOD_RESULT F_CALLBACK nonblockcallback(FMOD_SOUND *sound, FMOD_RESULT result)
{
FMOD::Sound *snd = (FMOD::Sound *)sound;

printf(&quot;Sound loaded! (%d) %s\n&quot;, result, FMOD_ErrorString(result)); 

return FMOD_OK;

}

//int getCurrentLocationReference(FMOD::Channel channel, vector<int> *breakpoints);
//bool updatePosition(FMOD::Channel *channel, FMOD::Channel *channel2,int *returnresult);
//float
Crossfade(FMOD::Channel *channel, FMOD::Channel *channel2);

static bool AudioChange = false;
//static bool beentroughCurrentUpdate = false;
//static bool beentroughCrossfadeOnce = false;

void main()
{
FMOD::System system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key, length = 0, buffrange = 1024;
unsigned int version;
FMOD_CREATESOUNDEXINFO exinfo;
vector<AudioLoop
> audioloops;

result = FMOD::System_Create(&amp;system);
ERRCHECK(result);

result = system-&gt;getVersion(&amp;version);
ERRCHECK(result);

if (FMOD_VERSION &lt; version)
{
    cerr &lt;&lt; &quot;This is an old version of FMOD&quot; &lt;&lt; endl;
    exit(0);
}

result = system-&gt;init(3, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);

memset(&amp;exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.nonblockcallback = nonblockcallback;

result = system-&gt;createStream(&quot;test.mp3&quot;, FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, &amp;exinfo, &amp;sound);
ERRCHECK(result);

result = sound-&gt;setMode(FMOD_LOOP_OFF);
ERRCHECK(result);

result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound, false, &amp;channel);
ERRCHECK(result);

key = 0;

bool isPlaying = true;

int prevchan = 0, nchan = 0;
float pdsp , pstream , pupdate , ptotal , cdsp , cstream , cupdate , ctotal;
pdsp = pstream = pupdate = ptotal = cdsp = cstream = cupdate = ctotal = 0.0;

FMOD::Sound *LastCalled;
int finalchannels = 0;

do
{

    vector&lt;int&gt; *breakpoints = new vector&lt;int&gt;;
    static int returnresult;
    breakpoints = new vector&lt;int&gt;;
    int breakpoint1, breakpoint2, breakpoint3, breakpoint4;
    breakpoint1 = 300000;
    breakpoint2 = 562500;
    breakpoint3 = 605400;
    breakpoint4 = 878100;
    breakpoints-&gt;push_back(breakpoint1);
    breakpoints-&gt;push_back(breakpoint2);
    breakpoints-&gt;push_back(breakpoint3);
    breakpoints-&gt;push_back(breakpoint4);

    //Default track die opent
    FMOD_OPENSTATE state;

    result = sound-&gt;getOpenState(&amp;state, 0, 0);
    ERRCHECK(result);

    if (state == FMOD_OPENSTATE_READY &amp;&amp; !channel)
    {
        result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound, false, &amp;channel);
        ERRCHECK(result);

    }
    //Einde default track

    if(kbhit())
    {
        key = getch();
        switch (key)
        {

            case '1':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile1.mp3'&quot; &lt;&lt; endl;
                    //result = system-&gt;createStream(&quot;testfile1.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound1);
                    //ERRCHECK(result);
                    audioloops.push_back(new AudioLoop(&quot;testfile1.mp3&quot;, 6, 44100, *breakpoints));

                    LastCalled = audioloops[0]-&gt;getSound();
                    //AudioChange = true;
                    //beentroughCurrentUpdate= false;
                    break;
                }
            }
            case '2':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile2.mp3'&quot; &lt;&lt; endl;
                    //result = system-&gt;createStream(&quot;testfile2.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound2);
                    //ERRCHECK(result);
                    //LastCalled = sound2;
                    //AudioChange = true;
                    //beentroughCurrentUpdate = false;
                    break;
                }
            }

            case '3':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile3.mp3'&quot; &lt;&lt; endl;
                    /*result = system-&gt;createStream(&quot;testfile3.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound3);
                    ERRCHECK(result);
                    LastCalled = sound3;
                    AudioChange = true;
                    beentroughCurrentUpdate= false;*/
                    break;
                }
            }

            case '4':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile4.mp3'&quot; &lt;&lt; endl;
                /*  result = system-&gt;createStream(&quot;testfile4.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound4);
                    ERRCHECK(result);
                    LastCalled = sound4;
                    AudioChange = true;
                    beentroughCurrentUpdate= false;*/
                    break;
                }
            }

            case '5':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile5.mp3'&quot; &lt;&lt; endl;
                    /*result = system-&gt;createStream(&quot;testfile5.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound5);
                    ERRCHECK(result);
                    LastCalled = sound5;
                    AudioChange = true;
                    beentroughCurrentUpdate= false;*/
                    break;
                }
            }

            case '6':
            {
                if (AudioChange != true)
                {
                    cout &lt;&lt; &quot;Going to play 'testfile6.mp3'&quot; &lt;&lt; endl;
                    /*result = system-&gt;createStream(&quot;testfile6.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound6);
                    ERRCHECK(result);
                    LastCalled = sound6;
                    AudioChange = true;
                    beentroughCurrentUpdate= false;*/
                    break;
                }
            }

            case '7':
            {
                cout &lt;&lt; &quot;Going to play 'testfile7.mp3'&quot; &lt;&lt; endl;
                /*result = system-&gt;createStream(&quot;testfile7.mp3&quot;, FMOD_NONBLOCKING, &amp;exinfo, &amp;sound7);
                ERRCHECK(result);
                LastCalled = sound7;
                AudioChange = true;
                beentroughCurrentUpdate= false;*/
                break;
            }              
        }
    }
    system-&gt;update();
    if (AudioChange == true)
    {              
        bool getchannelpaused = false;
        if (!audioloops[0]-&gt;getbeentroughCurrentUpdate())
        {
            returnresult = audioloops[0]-&gt;getCurrentLocationReference();
            //result = system-&gt;playSound(FMOD_CHANNEL_FREE, LastCalled, true, &amp;channel2);
            //ERRCHECK(result);
        }
        result = channel-&gt;getPaused(&amp;getchannelpaused);
        ERRCHECK(result);


        audioloops[0]-&gt;updatePosition(audioloops[1]);
        if (getchannelpaused)
        {
            result = channel-&gt;stop();
            ERRCHECK(result);
            AudioChange = false;
            audioloops[0]-&gt;setbeentroughCurrentUpdate(false);
            //audioloops[0]-&gt;setbeentroughCrossfadeOnce(false);
        }
    }



    //ZOOI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Sleep(10);
    result = system-&gt;getChannelsPlaying(&amp;finalchannels);
    ERRCHECK(result);

    prevchan = nchan;
    result = system-&gt;getChannelsPlaying(&amp;nchan);
    ERRCHECK(result);
    if (nchan != prevchan)
    {
        cout &lt;&lt; &quot;Number of channels playing CHANGED!!! Current number of channels playing: &quot; &lt;&lt; nchan &lt;&lt; endl;
    }


    pdsp = cdsp;
    pstream = cstream;
    pupdate = cupdate;
    ptotal = ctotal;
    result = system-&gt;getCPUUsage(&amp;cdsp, &amp;cstream, &amp;cupdate, &amp;ctotal);
    ERRCHECK(result);


    if ((ctotal - ptotal) &gt;= 0.3 )
    {
        cout &lt;&lt; setprecision(1) &lt;&lt;  &quot;current CPU usage: DSP: &quot; &lt;&lt; cdsp &lt;&lt; &quot;%, Stream: &quot; &lt;&lt; cstream 
            &lt;&lt; &quot;%, Update: &quot;&lt;&lt; cupdate &lt;&lt; &quot;%,  Total :&quot; &lt;&lt; ctotal &lt;&lt; &quot;%&quot;&lt;&lt; endl;
    }

} while (finalchannels &gt; 0);

}

//int getCurrentLocationReference(FMOD::Channel *channel, vector<int> *breakpoints) //return order of returnresult:
//{
//int tempresult = 0;
//if (beentroughCurrentUpdate == false)
//{
// //FMOD::System *sys; //0: Position of file
// FMOD::Sound *sound; //1: nearest possible breakpoint(number)
// FMOD_RESULT result; //2: nearest possible breakpoint(time)
// int nearestbreakpoint, breakpointssize;
// unsigned int position, length = 0;
//
// result = channel->getPosition(&position, FMOD_TIMEUNIT_PCM);
// ERRCHECK(result);

//  result = channel-&gt;getCurrentSound(&amp;sound);
//  ERRCHECK(result);

//  result = sound-&gt;getLength(&amp;length, FMOD_TIMEUNIT_PCM);
//  ERRCHECK(result);

//  breakpointssize = breakpoints-&gt;size();

//  unsigned int min = length;
//  cout &lt;&lt; &quot;minimum: &quot; &lt;&lt; min &lt;&lt; endl;
//  for (int i = 0; i &lt; breakpointssize; i++)
//  {
//      int tempbreakpoints = (*breakpoints)[i];
//      unsigned int tempding = (tempbreakpoints - position);
//      if (tempding &lt; min)
//      {
//          min = (*breakpoints)[i];
//          nearestbreakpoint = i;
//      }
//  }
//  tempresult = min;

//}
//beentroughCurrentUpdate = true;
//return tempresult;

//}

/bool updatePosition(FMOD::Channel *channel, FMOD::Channel *channel2, int *returnresult)
{
//if (AudioChange == true)
//{
// unsigned int position;
// channel->getPosition(&position, FMOD_TIMEUNIT_PCM);
//
// if (position >= *returnresult)
// {
// if (!beentroughCrossfadeOnce)
// {
// cout << "Position for crossfading reached/passed!" << endl;
// }
// else
// {
// //cout << "Current position: " << position << endl << "Breakpoint: " << *returnresult << endl;
// }
// Crossfade(channel, channel2);
// return true;
// }
// return false;
//}
//return false;
}
/

/float Crossfade(FMOD::Channel *channel, FMOD::Channel *channel2)
{

}*/
[/code:bnfjal2m]

errfunc.h
[code:bnfjal2m]

pragma once

include "fmod.hpp"

include "fmod_errors.h"

include <iostream>

using namespace std;

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
[/code:bnfjal2m]

  • You must to post comments
0
0

Declare ERRCHECK to be inline or static.

  • Guy
  • You must to post comments
0
0

short… hits the spot… many thnx :)

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.