0
0

Hi i’m new to fmod. 😀
I’m programming synthesiser which should play samples on key pressed and maybe record this later.
I’m trying to figure this out but i just can’t see where the problem is.

here is my code, under every file is written where i think the problems occurs:

Sample.h
[code:3moo5cur]
class Sample {
//protected:
public:
System *system;
Sound *sound;
Channel *channel;
FMOD_RESULT result; //result for error checking
float volume;
string filename;

public:
    Sample() {}
    Sample (System *s, string fname, int control) {
        volume = 1.0;
        system = s;
        filename = fname;
        channel=NULL;

        //if control==0 Sound is created, else Stream
        if (control==0) result = system->createSound(filename.c_str(), FMOD_DEFAULT, 0, &sound);
        else result = system->createStream(filename.c_str(), FMOD_DEFAULT, 0, &sound);
        if (error(result)) { cout << "SYNTH: Error creating audio sample (" << fname << ")."<< endl; exit(1); }


    }

....
[/code:3moo5cur]
[color=red:3moo5cur]if (control==0) result = system->createSound(filename.c_str(), FMOD_DEFAULT, 0, &sound);
else result = system->createStream(filename.c_str(), FMOD_DEFAULT, 0, &sound);[/color:3moo5cur]

Synth.h
[code:3moo5cur]
class Synth {
private:
System *system;
vector <Sample> beats;
vector <Sample> fx;
vector <Sample> piano;
vector <Sample> melodies;
void fill (vector<Sample> &samples, string dirPath, int control);

public:
    //filling all samples
    Synth (System *s) {
        system=s;

        //creating, seting output &amp; initializing FMOD system
        result = System_Create(&amp;system);
        if (error(result)) exit(0);
        result = system-&gt;setOutput(FMOD_OUTPUTTYPE_ALSA); //output type ALSA
        if (error(result)) exit(0);
        result = system-&gt;init(32, FMOD_INIT_NORMAL, NULL);
        if (error(result)) exit(0);

        fill(beats, &quot;./Sample/beats&quot;, 0);
        fill(fx, &quot;./Sample/fx&quot;, 0);
        fill(piano, &quot;./Sample/piano&quot;, 0);
        fill(melodies, &quot;./Sample/melodies&quot;, 1);   

    }

};
....

//fill samples
void Synth::fill (vector<Sample> &samples, string dirPath, int control) {
vector <string> files;
getFiles(dirPath,files);

for (unsigned int i=0; i!=files.size(); i++) {

        samples.push_back(Sample(system, dirPath+&quot;/&quot;+files[i] , control));
        cout &lt;&lt; dirPath+&quot;/&quot;+files[i] &lt;&lt;&quot; filled. &quot;&lt;&lt; endl;
    }

}
[/code:3moo5cur]

[color=red:3moo5cur]fill(beats, "./Sample/beats", 0);
in Synth::fill – for …[/color:3moo5cur]

main.cpp
[code:3moo5cur]
int main() {

System *system;

Synth synth(system);

//synth.run();

return 0;   

}
[/code:3moo5cur]

output:
[code:3moo5cur]
./Sample/beats/TID_03crs_darktrance_s_135bpm.wav filled.
FMOD error! (36) An invalid object handle was used.
./Sample/beats/TID_04rid_darktrance_s_135bpm.wav filled.
Segmentation fault
[/code:3moo5cur]

please help.

  • You must to post comments
0
0

i found out error is in Sample class.
if i call
[code:3ngyadko] system->createSound("./Sample/beats/TID_03crs_darktrance_s_135bpm.wav", FMOD_DEFAULT, 0, &sound);[/code:3ngyadko]
all is ok.
but if i call
[code:3ngyadko]
Sample samp(system,"./Sample/beats/TID_03crs_darktrance_s_135bpm.wav",0);
[/code:3ngyadko]
i get this " An invalid object handle was used" error.

example class:
[code:3ngyadko]
class Test {
private:
System *system;
vector <Sample> samples;

public:
    Test(System *s) {
        system=s;
        //Sound* sound;
        Sample samp(system,&quot;./Sample/beats/TID_03crs_darktrance_s_135bpm.wav&quot;,0);  // NOT OK
        system-&gt;createSound(&quot;./Sample/beats/TID_03crs_darktrance_s_135bpm.wav&quot;, FMOD_DEFAULT, 0, &amp;sound); //OK
    }

};
[/code:3ngyadko]

i’m still hoping for a help. anyone?

  • You must to post comments
0
0

Does your Sample constructor do anything other than what you have posted? If so, can you post the full code for the Sample constructor please?

Also, what exactly does your error() function do?

  • You must to post comments
0
0

thank you for your reply :)

Sample contructor does what is posted in first post. thats it. nothing more.
my error function is for fmod error checking, similar to one in "getting started" tutorial from documentation.

error function:
[code:15du314t]
FMOD_RESULT result; //result for error checking

bool error (FMOD_RESULT result) {
if (result!=FMOD_OK) {
cout << "FMOD error! ("<< result << ") " << FMOD_ErrorString(result) << endl;
return 1;
}
return 0;
}
[/code:15du314t]

  • You must to post comments
0
0

I can’t see any problems with the code you have posted. I think you need to pinpoint the exact line that prints the invalid handle error, either by stepping through your code in a debugger or by inserting print statements throughout your code so you can see the flow of execution.

  • You must to post comments
0
0

solved. i had a Sample destructor [code:jfhtv1ib]~Sample() {sound->release; }[/code:jfhtv1ib] which caused error. :)

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.