0
0

Sorry if this is the wrong section, I JUST signed up for the forums, but I think I’m having a problem with the lock function. My code currently is this:

[code:29ur8jt9] ssystem->createSound(file.c_str(), FMOD_DEFAULT, 0, &fmodsound);

unsigned int length,read;
void *buf;
unsigned int len1;
FMOD_RESULT res;

res = fmodsound->getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
res = fmodsound->lock(0,length, &buf,0,&len1,0);

int bps;
int channels;
float rate;

fmodsound->getFormat(0,0,&channels,&bps);
fmodsound->getDefaults(&rate,0,0,0);


for(unsigned i = 0; i < len1; i++)//i = bytes
{
    float wd = 0;                           //wave data
    float sample = i * 8 / bps / channels;  //samples
    float ms = sample / 1000 * rate;        //milliseconds

    if(bps == 8)    //if 8 bit
    {
        char *get = static_cast<char*>(buf);  //chars' sizes are 1
        wd = int(get[i]);
    }
    else if(bps == 16)  //if 16 bit
    {
        short *get = static_cast<short*>(buf);    //shorts' sizes are 2
        wd = get[i];
    }

    //Do stuff with info here...
}

res = fmodsound->unlock(buf,0, len1,0);[/code:29ur8jt9]

My problem is that when I tried outputting the samples, milliseconds, and wave data, things seemed to be off.

Some examples are (when sound is 16 bit):

[list:29ur8jt9]Crashing at the end[/list:u:29ur8jt9]
[list:29ur8jt9]Samples don’t match up with bytes ex: i=16 samples = 8[/list:u:29ur8jt9]

Again, really sorry if this is the wrong area. But I can’t put my finger on what’s wrong.

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.