Hi Brett,
sorry for delay, I’m working on my personal project and fmod plugin is a tiny piece of it and has no relationship to the core of what I do, so when i got it working I moved on to my next task
So, as somebody who just recently suffered pain to get it working, I’ll share my thoughts. If fmod had a sample codec plugin that implements playback of some fairly simple stereo format it would make it simple to understand all the assumptions and details that fmod expects from a well behaved codec.
Even a fmod “codec” plugin for a stereo wav file with a “null” decoder would be helpful. Perhaps, people are familiar with mp3, a sample mp3 codec plugin that uses lame or any other mp3 decoder could be added to samples.
Some of the things that got me confused originally: mixing audio codec and format parser in one interface. wav “codec” would made it clear that fmod codec plugin is expected to do both of these tasks. Then along the way I had to guess stuff like what FMOD_CODEC_READ_CALLBACK expects. It passes samples_in
and expects in return samples_out
, however, looks like samples_in is raw count of samples (e.g. shorts for pcm16 output) and output should indicate how many samples of stereo data was read (e.g. I need to divide by channel count). Nothing in the docs indicates about that… did I even get it right? Without it sounds would be all electric and choppy.
Then, when playback reaches EOF, it’s not clear what should be returned. Originally I returned samples_out=0 and FMOD_OK, but doesn’t seem like FMOD expects that. In fact, this way it easily deadlocks when I try to release a sound: I get deadlock from this call and it’s stuck on Sleep() loop, while in another fmod thread keeps reading my file that constantly returns 0 and FMOD_OK. Why I didn’t return FMOD_ERR_FILE_EOF or FMOD_ERR_FILE_ENDOFDATA? Because docs make it clear that these aren’t really for a properly ended file, but for a truncated/damaged input. In any case, fmod sound release should handle that condition, and break that endless loop that reads nothing if sound is being released. (And by the way, does codec need to return EOF or ENDOFDATA or FMOD_OK?)
Also, I found something really interesting. Seems like fmod destroys my sound system. I don’t know how it does it, but sound stops working completely on my PC! I have RX-A2050 attached using hdmi, and at first I couldn’t figure out what was wrong, and then I noticed that these problems are related to fmod. When I left VS attached with debugger while fmod was stuck in that deadlock reading finished file and trying to release a sound my sound would eventually stop working completely. I was going nuts at first, only reboot would help, even if I disabled sound device and re-enabled it it would still stay completely mute. Only now I actually noticed that it was fmod related: when I break debugger there are some changes with the sound device.
When I noticed these issues with sound I wasn’t sure what it was related to, usually this would happen after I left my PC for some time and when I would come back it was totally silent. Eventually I found out that there was only one way to fix sound without rebooting: I had to change default format in device properties:
One other point, it would be very helpful if fmod.pdb was publicly available. Would be very helpful for anybody who needs to debug fmod related code.
I’m not sure what you mean about the docs …
For me docs, are the headers. That’s where I prefer to read docs, not in a browser, and it seems some parts of fmod docs aren’t in headers, but are available online. Maybe my fmod headers are outdated?.. I see this in headers: #define FMOD_VERSION 0x00010815