// Set flags to determine how it will be played.\r
mode = FMOD.MODE.SOFTWARE | // Need software processing for all the features\r
FMOD.MODE._3D | // Need 3D effects for placement\r
- FMOD.MODE.OPENMEMORY | // Use sound data in memory\r
- FMOD.MODE.NONBLOCKING;\r
+ FMOD.MODE.OPENMEMORY; // Use sound data in memory\r
\r
// Set coordinate space interpretation.\r
if (global)\r
\r
// Describe the data to FMOD\r
extraInfo.length = (uint)data.Length;\r
- extraInfo.nonblockcallback = loadCallback;\r
extraInfo.cbsize = Marshal.SizeOf(extraInfo);\r
\r
invoke(new SoundDelegate(delegate\r
{\r
- // Create an FMOD sound of this Ogg data.\r
- FMODExec(system.createSound(\r
- data,\r
- mode,\r
- ref extraInfo,\r
- ref sound));\r
-\r
- // Register for callbacks.\r
- RegisterSound(sound);\r
- }));\r
- }\r
- else\r
- {\r
- Logger.Log("Failed to download sound: " + transfer.Status.ToString(),\r
- Helpers.LogLevel.Error);\r
- }\r
- }\r
-\r
- protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
- {\r
- // Check if we killed the sound before it was decoded\r
- if (sound == null) return RESULT.OK;\r
-\r
- if (instatus != RESULT.OK)\r
- {\r
- Logger.Log("Error opening sound: " + instatus, Helpers.LogLevel.Error);\r
- return RESULT.OK;\r
- }\r
-\r
- invoke(new SoundDelegate(delegate\r
- {\r
- try\r
- {\r
- // If looping is requested, loop the entire thing.\r
- if (loopSound)\r
+ try\r
{\r
- uint soundlen = 0;\r
- FMODExec(sound.getLength(ref soundlen, TIMEUNIT.PCM));\r
- FMODExec(sound.setLoopPoints(0, TIMEUNIT.PCM, soundlen - 1, TIMEUNIT.PCM));\r
- FMODExec(sound.setLoopCount(-1));\r
- }\r
-\r
- // Allocate a channel and set initial volume. Initially paused.\r
- FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
+ // Create an FMOD sound of this Ogg data.\r
+ FMODExec(system.createSound(\r
+ data,\r
+ mode,\r
+ ref extraInfo,\r
+ ref sound));\r
+\r
+ // Register for callbacks.\r
+ RegisterSound(sound);\r
+\r
+\r
+ // If looping is requested, loop the entire thing.\r
+ if (loopSound)\r
+ {\r
+ uint soundlen = 0;\r
+ FMODExec(sound.getLength(ref soundlen, TIMEUNIT.PCM));\r
+ FMODExec(sound.setLoopPoints(0, TIMEUNIT.PCM, soundlen - 1, TIMEUNIT.PCM));\r
+ FMODExec(sound.setLoopCount(-1));\r
+ }\r
+\r
+ // Allocate a channel and set initial volume. Initially paused.\r
+ FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
#if TRACE_SOUND\r
Logger.Log(\r
String.Format("Channel {0} for {1} assigned to {2}",\r
Id),\r
Helpers.LogLevel.Debug);\r
#endif\r
- lock (allChannels)\r
- allChannels[channel.getRaw()] = this;\r
+ RegisterChannel(channel);\r
\r
- FMODExec(channel.setVolume(volumeSetting * AllObjectVolume));\r
+ FMODExec(channel.setVolume(volumeSetting * AllObjectVolume));\r
\r
- // Take note of when the sound is finished playing.\r
- FMODExec(channel.setCallback(endCallback));\r
+ // Take note of when the sound is finished playing.\r
+ FMODExec(channel.setCallback(endCallback));\r
\r
- // Set attenuation limits.\r
- FMODExec(sound.set3DMinMaxDistance(\r
- 1.2f, // Any closer than this gets no louder\r
- 100.0f)); // Further than this gets no softer.\r
+ // Set attenuation limits.\r
+ FMODExec(sound.set3DMinMaxDistance(\r
+ 1.2f, // Any closer than this gets no louder\r
+ 100.0f)); // Further than this gets no softer.\r
\r
- // Set the sound point of origin. This is in SIM coordinates.\r
- FMODExec(channel.set3DAttributes(ref position, ref ZeroVector));\r
+ // Set the sound point of origin. This is in SIM coordinates.\r
+ FMODExec(channel.set3DAttributes(ref position, ref ZeroVector));\r
\r
- // Turn off pause mode. The sound will start playing now.\r
- FMODExec(channel.setPaused(false));\r
- }\r
- catch (Exception ex)\r
- {\r
- Logger.Log("Error starting sound: ", Helpers.LogLevel.Error, ex);\r
- }\r
- }));\r
-\r
- return RESULT.OK;\r
+ // Turn off pause mode. The sound will start playing now.\r
+ FMODExec(channel.setPaused(false));\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ Logger.Log("Error playing sound: ", Helpers.LogLevel.Error, ex);\r
+ }\r
+ }));\r
+ }\r
+ else\r
+ {\r
+ Logger.Log("Failed to download sound: " + transfer.Status.ToString(),\r
+ Helpers.LogLevel.Error);\r
+ }\r
}\r
\r
/// <summary>\r