给定一个应该在 C# 中播放 SNES SPC 文件和 FMOD 的 DLL,为什么这个调用会system.createSound
失败?
var ret = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
var soundEx = new FMOD.CREATESOUNDEXINFO()
{
cbsize = Marshal.SizeOf(soundEx),
fileoffset = 0,
length = ~0U,
numchannels = 2,
defaultfrequency = 32000,
format = FMOD.SOUND_FORMAT.PCM16,
pcmreadcallback = pcmreadcallback,
pcmsetposcallback = pcmsetposcallback,
dlsname = null,
};
var mode = FMOD.MODE.DEFAULT | FMOD.MODE.OPENUSER
| FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATESTREAM;
ret = system.createSound((string)null, mode, ref soundEx, ref sound);
//^-- ERR_INVALID_PARAM
ret = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
将其usercreatedsound
与 FMOD 附带的示例进行比较:
FMOD.MODE mode = (FMOD.MODE._2D | FMOD.MODE.DEFAULT
| FMOD.MODE.OPENUSER | FMOD.MODE.LOOP_NORMAL
| FMOD.MODE.HARDWARE);
//snip
createsoundexinfo.cbsize = Marshal.SizeOf(createsoundexinfo);
createsoundexinfo.fileoffset = 0;
createsoundexinfo.length = frequency * channels * 2 * 2;
createsoundexinfo.numchannels = (int)channels;
createsoundexinfo.defaultfrequency = (int)frequency;
createsoundexinfo.format = FMOD.SOUND_FORMAT.PCM16;
createsoundexinfo.pcmreadcallback = pcmreadcallback;
createsoundexinfo.pcmsetposcallback = pcmsetposcallback;
createsoundexinfo.dlsname = null;
//snop
result = system.createSound(
(string)null,
(mode | FMOD.MODE.CREATESTREAM),
ref createsoundexinfo,
ref sound);
长度,频率......无关紧要。
编辑:我已经确认 SPC 播放器可以正常工作,至少就初始化而言,并且 FMOD 附带的示例可以正常构建和运行。除了调整设置以使其运行之外,唯一特别有意义的更改是以 4.0 风格编写。