// 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
this.Instance = instance;
manager = this;
-
- loadCallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);
endCallback = new FMOD.CHANNEL_CALLBACK(DispatchEndCallback);
allBuffers = new Dictionary<UUID, BufferSound>();
// Additional info for callbacks goes here.
protected FMOD.CREATESOUNDEXINFO extraInfo;
protected static FMOD.CHANNEL_CALLBACK endCallback;
- protected static FMOD.SOUND_NONBLOCKCALLBACK loadCallback;
// Vectors used for orienting spatial axes.
protected static FMOD.VECTOR UpVector;
/// <returns></returns>
// Subclasses override these methods to handle callbacks.
- protected virtual FMOD.RESULT NonBlockCallbackHandler( RESULT result ) { return RESULT.OK; }
protected virtual FMOD.RESULT EndCallbackHandler() { return RESULT.OK; }
/// <summary>
- /// Main handler for sound-loading callback.
- /// </summary>
- /// <param name="soundraw"></param>
- /// <param name="result"></param>
- /// <returns></returns>
- public RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
- {
- if (allSounds.ContainsKey(soundraw))
- {
- MediaObject sndobj = allSounds[soundraw];
- return sndobj.NonBlockCallbackHandler( result );
- }
-
- return FMOD.RESULT.OK;
- }
-
- /// <summary>
/// Main handler for playback-end callback.
/// </summary>
/// <param name="channelraw"></param>
return RESULT.OK;
}
- public delegate RESULT SOUND_NONBLOCKCALLBACK(IntPtr soundraw, RESULT result);
-
protected static void FMODExec(FMOD.RESULT result)
{
if (result != FMOD.RESULT.OK)
/// </summary>\r
/// <param name="system">Sound system</param>\r
public Speech()\r
- :base()\r
- {\r
- extraInfo.format = SOUND_FORMAT.PCM16;\r
- }\r
+ : base()\r
+ {\r
+ extraInfo.format = SOUND_FORMAT.PCM16;\r
+ }\r
\r
\r
/// <summary>\r
filename = speakfile;\r
\r
// Set flags to determine how it will be played.\r
- FMOD.MODE mode = FMOD.MODE.SOFTWARE | FMOD.MODE._3D | MODE.NONBLOCKING;\r
+ FMOD.MODE mode = FMOD.MODE.SOFTWARE | FMOD.MODE._3D;\r
\r
// Set coordinate space interpretation.\r
if (global)\r
else\r
mode |= FMOD.MODE._3D_HEADRELATIVE;\r
\r
- extraInfo.nonblockcallback = loadCallback;\r
-\r
invoke(new SoundDelegate(\r
- delegate {\r
- FMODExec(\r
+ delegate\r
+ {\r
+ try\r
+ {\r
+ FMODExec(\r
system.createSound(filename,\r
mode,\r
ref extraInfo,\r
ref sound));\r
\r
- // Register for callbacks.\r
- RegisterSound(sound);\r
- }));\r
- }\r
+ // Register for callbacks.\r
+ RegisterSound(sound);\r
\r
- /// <summary>\r
- /// Callback when a stream has been loaded\r
- /// </summary>\r
- /// <param name="instatus"></param>\r
- /// <returns></returns>\r
- protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
- {\r
- extraInfo.nonblockcallback = null;\r
-\r
- if (instatus != RESULT.OK)\r
- {\r
- Logger.Log("FMOD error opening speech file " +\r
- filename +\r
- ": " + instatus,\r
- Helpers.LogLevel.Error);\r
- return RESULT.OK;\r
- }\r
-\r
- invoke(new SoundDelegate(\r
- delegate\r
- {\r
- try\r
- {\r
// Allocate a channel, initially paused.\r
FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
\r
\r
// SET a handler for when it finishes.\r
FMODExec(channel.setCallback(endCallback));\r
- RegisterChannel( channel );\r
+ RegisterChannel(channel);\r
\r
// Un-pause the sound.\r
FMODExec(channel.setPaused(false));\r
Logger.Log("Error playing speech: ", Helpers.LogLevel.Error, ex);\r
}\r
}));\r
-\r
- return RESULT.OK;\r
}\r
\r
/// <summary>\r
\r
return RESULT.OK;\r
}\r
- }\r
+ }\r
}\r
// Stop old stream first.\r
StopStream();\r
\r
- extraInfo.nonblockcallback = loadCallback;\r
extraInfo.format = SOUND_FORMAT.PCM16;\r
\r
invoke(new SoundDelegate(\r
delegate\r
{\r
- FMODExec(\r
- system.createSound(url,\r
- (MODE.HARDWARE | MODE._2D | MODE.CREATESTREAM | MODE.NONBLOCKING),\r
- ref extraInfo,\r
- ref sound), "Stream load");\r
- // Register for callbacks.\r
- RegisterSound(sound);\r
- }));\r
- }\r
-\r
- /// <summary>\r
- /// Callback when a stream has been loaded\r
- /// </summary>\r
- /// <param name="instatus"></param>\r
- /// <returns></returns>\r
- protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
- {\r
- if (instatus != RESULT.OK)\r
- {\r
- Logger.Log("Error opening audio stream: " + instatus,\r
- Helpers.LogLevel.Debug);\r
- return RESULT.OK;\r
- }\r
-\r
- invoke(new SoundDelegate(\r
- delegate\r
- {\r
try\r
{\r
+ FMODExec(\r
+ system.createSound(url,\r
+ (MODE.HARDWARE | MODE._2D | MODE.CREATESTREAM),\r
+ ref extraInfo,\r
+ ref sound), "Stream load");\r
+ // Register for callbacks.\r
+ RegisterSound(sound);\r
+\r
// Allocate a channel and set initial volume.\r
FMODExec(system.playSound(\r
CHANNELINDEX.FREE,\r
Logger.Log("Error playing stream: ", Helpers.LogLevel.Debug, ex);\r
}\r
}));\r
-\r
- Logger.Log("Stream playing", Helpers.LogLevel.Info);\r
- return RESULT.OK;\r
}\r
\r
+\r
#if GET_STREAM_TAGS\r
private void CheckTags(object sender)\r
{\r