: base()
{
this.instance = instance;
+ manager = this;
// Start the background thread that does all the FMOD calls.
soundThread = new Thread(new ThreadStart(CommandLoop));
// Initialize the command queue.
queue = new Queue<SoundDelegate>();
- try
+ while (true)
{
- while (true)
+ // Wait for something to show up in the queue.
+ lock (queue)
{
- // Wait for something to show up in the queue.
- lock (queue)
+ while (queue.Count == 0)
{
- while (queue.Count == 0)
- {
- Monitor.Wait(queue);
- }
-
- action = queue.Dequeue();
+ Monitor.Wait(queue);
}
+ action = queue.Dequeue();
+ }
- // We have an action, so call it.
+ // We have an action, so call it.
+ try
+ {
action();
action = null;
}
- }
- catch (Exception e)
- {
- System.Console.WriteLine("Sound shutdown " + e.Message);
+ catch (Exception e)
+ {
+ Logger.Log("Error in sound action: " + e.Message,
+ Helpers.LogLevel.Error);
+ }
}
}
if (system != null)
{
+ Logger.Log("FMOD interface stopping", Helpers.LogLevel.Info);
system.release();
system = null;
}
{
invoke(new SoundDelegate(delegate
{
- system.update();
+ FMODExec(system.update());
}));
continue;
}
ref forward, // Facing direction
ref UpVector )); // Top of head
- system.update();
+ FMODExec(system.update());
}));
}
}
///
/// </summary>
protected static Queue<SoundDelegate> queue;
+ protected static MediaManager manager;
/// <summary>
/// FMOD channel controller, should not be used directly, add methods to Radegast.Media.Sound
{
extraInfo = new FMOD.CREATESOUNDEXINFO();
extraInfo.cbsize = Marshal.SizeOf(extraInfo);
-
}
protected bool Cloned = false;
invoke(new SoundDelegate(delegate
{
FMODExec(channel.setVolume(volume));
- system.update();
+// system.update();
}));
}
}
+ /// <summary>
+ /// Update the 3D position of a sound source.
+ /// </summary>
protected FMOD.VECTOR position = new FMOD.VECTOR();
public OpenMetaverse.Vector3 Position
{
FMODExec(channel.set3DAttributes(
ref position,
ref ZeroVector));
- system.update();
+// system.update();
}));
}
}
protected virtual FMOD.RESULT NonBlockCallbackHandler( RESULT result ) { return RESULT.OK; }
protected virtual FMOD.RESULT EndCallbackHandler() { return RESULT.OK; }
- protected RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
+ public RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
{
if (allSounds.ContainsKey(soundraw))
{
IntPtr commanddata1,
IntPtr commanddata2)
{
- // Ignore other callback types.
- if (type != CHANNEL_CALLBACKTYPE.END) return RESULT.OK;
-
- if (allChannels.ContainsKey(channelraw))
+ // There are several callback types
+ switch (type)
{
- MediaObject sndobj = allChannels[channelraw];
- return sndobj.EndCallbackHandler();
+ case CHANNEL_CALLBACKTYPE.END:
+ if (allChannels.ContainsKey(channelraw))
+ {
+ MediaObject sndobj = allChannels[channelraw];
+ return sndobj.EndCallbackHandler();
+ }
+ break;
}
return RESULT.OK;
public Speech()\r
:base()\r
{\r
- extraInfo.nonblockcallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);\r
extraInfo.format = SOUND_FORMAT.PCM16;\r
}\r
\r
else\r
mode |= FMOD.MODE._3D_HEADRELATIVE;\r
\r
- invoke( new SoundDelegate(\r
+ extraInfo.nonblockcallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);\r
+\r
+ invoke(new SoundDelegate(\r
delegate {\r
FMODExec(\r
system.createSound(filename,\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("Error opening speech file " +\r
// Un-pause the sound.\r
FMODExec(channel.setPaused(false));\r
\r
- system.update();\r
+// system.update();\r
}\r
catch (Exception ex)\r
{\r
invoke(new SoundDelegate(\r
delegate\r
{\r
+ // FMODExec(channel.setCallback(null));\r
UnRegisterChannel();\r
channel = null;\r
UnRegisterSound();\r