0
0

Quick question:
Is it possible to stop the loading of a sound into memory? For example: the user loads a very long sound and when the half of the song is loaded he wants to abort that and load another sound.

  • You must to post comments
0
0

not by just using createSound, if internally it is in a loop inside a codec trying to decompress the whole thing.

Another option is to decompress the data yourself, using FMOD_OPENONLY flag, so that no decompression happens, then you use Sound::readData and Sound::lock/unlock to decode the data in small blocks (with your own cancel check) until the whole sample is read. This would work the way you wanted.

  • You must to post comments
0
0

Thanks for the answer, brett!

So I would do something like this:

[code:2jlms0mk]
do {

if (abort) {
    return;
}

result = sound->lock(offset, chunksize, &ptr1, &ptr2, &len1, &len2);
offset += len1;
result = sound->readData((char *)ptr1, chunksize, &read);
bytesread += read;
result = sound->unlock(ptr1, ptr2, len1, len2);

} while (result == FMOD_OK && read == chunksize);

[/code:2jlms0mk]

  • You must to post comments
0
0

Yes that looks about right.

  • You must to post comments
0
0

I don’t know if this is the best solution, but it seems to work, you can even set the position of the sound to an unloaded part and it will start playing from that position when it finished loading.

If somebody is interested here’ the code:

[code:2upzfcwi]
FMOD_RESULT result;
FMOD::Sound *sound;
unsigned int offset = 0;
unsigned int chunksize = 4096;
void *ptr1;
void *ptr2;
unsigned int len1 = 0;
unsigned int len2 = 0;
unsigned int read = 0;
unsigned int bytesread = 0;

result = system->createSound(filename, FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
ERRCHECK(result);

do {

if (abort) {
    return;
}

result = sound->lock(offset, chunksize, &ptr1, &ptr2, &len1, &len2);
ERRCHECK(result);
offset += len1;

result = sound->readData((char *)ptr1, chunksize, &read);
ERRCHECK(result);
bytesread += read;

result = sound->unlock(ptr1, ptr2, len1, len2);
ERRCHECK(result);

} while (result == FMOD_OK && read == chunksize);

[/code:2upzfcwi]

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.