craeteStream with file data, return OK, yet play no sound.


(kevinvan) #1

code 1:
int mode = 0;
mode |= (is3D) ? FMOD_3D : FMOD_2D;
mode |= FMOD_LOWMEM;

FMOD::Sound* music = nullptr;
FMOD_RESULT result = mSystem->createStream(filePath.getUtf8CString(), mode, nullptr, &music);

code 2:
FMOD::Sound* music = nullptr;
FMOD_RESULT result = FMOD_RESULT_FORCEINT;
std::string fileContent;
if (mResourceLoader.load(ResourceLocation(soundName), fileContent)) {
int mode = 0;
mode |= FMOD_OPENMEMORY;
mode |= FMOD_LOWMEM;
mode |= (is3D) ? FMOD_3D : FMOD_2D;

    FMOD_CREATESOUNDEXINFO extraInfo;
    std::memset(&extraInfo, 0, sizeof(extraInfo));
    extraInfo.cbsize = sizeof(extraInfo);
    extraInfo.length = static_cast<unsigned int>(fileContent.size());
    result = mSystem->createStream(fileContent.c_str(), mode, &extraInfo, &music);
}

Both results are OK, however, code 1 plays good music, yet code 2 plays nothing. Anything that I missed?


(Brett Paterson) #2

have you inspected the memory returned by str() to make sure it is non zero?
Is the channel saying that the position is moving as it plays and there are no other errors?

The code looks ok, it may be a content issue from what I can see from that snipped. If you have a testbed + data that reproduces your issue I can probably see where your problem lies.


(kevinvan) #3

I’ve added break point to view the runtime data. In code 2, the fileContent was not nullptr, it did load the data from the exact file. I now guess it is because the codes are in a function, not the main function, and the fileContent is a local paramater in that function, as soon as the function exits its region, fileContent is released. Although I have return “music”, there should be no sound later when I try to call playSound, since the buffer was released.


(Brett Paterson) #4

the value of the pointer will probably be valid (ie not null), but that’s not what i’m interested in.

It is the actual contents of the pointer i’m talking about. You’d have to put it in the debugger memory view window to see if the contents of the pointer are non zero.