if (!audioOK)
{
+ res = system.setOutput(FMOD.OUTPUTTYPE.PULSEAUDIO);
+ if (res == RESULT.OK)
+ {
+ audioOK = true;
+ }
+ }
+
+ if (!audioOK)
+ {
res = system.setOutput(FMOD.OUTPUTTYPE.ALSA);
if (res == RESULT.OK)
{
try
{
// Get the capabilities of the driver.
- int minfrequency = 0, maxfrequency = 0;
+ int outputRate = 0;
FMODExec(system.getDriverCaps(0, ref caps,
- ref minfrequency,
- ref maxfrequency,
+ ref outputRate,
ref speakermode));
// Set FMOD speaker mode to what the driver supports.
FMODExec(system.setSpeakerMode(speakermode));
catch {}
// Try to initialize with all those settings, and Max 32 channels.
- FMOD.RESULT result = system.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);
+ FMOD.RESULT result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
{
// Can not handle surround sound - back to Stereo.
// And init again.
FMODExec(system.init(
32,
- FMOD.INITFLAG.NORMAL,
+ FMOD.INITFLAGS.NORMAL,
(IntPtr)null)
);
}
}
catch (Exception ex)
{
- Logger.Log("Failed to initialize the sound system: ", Helpers.LogLevel.Warning, ex);
+ Logger.Log("Failed to initialize the sound system: " + ex.ToString(), Helpers.LogLevel.Warning);
}
}
//
// $Id: Sound.cs 502 2010-03-14 23:13:46Z latifer $
//
-#define GET_STREAM_TAGS
using System;
using System.Runtime.InteropServices;
using System.Threading;
/// <summary>
/// Fired when a stream meta data is received
/// </summary>
-#pragma warning disable 0067
public event StreamInfoCallback OnStreamInfo;
-#pragma warning restore 0067
-#if GET_STREAM_TAGS
- Timer tagTimer = null;
- uint tagCheckInterval = 1000;
-#endif
+ Timer updateTimer = null;
+ uint updateIntervl = 500;
/// <summary>
/// Creates a new sound object
/// </summary>
public void StopStream()
{
-#if GET_STREAM_TAGS
- if (tagTimer != null)
+ if (updateTimer != null)
{
- tagTimer.Dispose();
- tagTimer = null;
+ updateTimer.Dispose();
+ updateTimer = null;
}
-#endif
if (channel != null)
{
try
{
FMODExec(
+ system.setStreamBufferSize(4 * 128 * 128, TIMEUNIT.RAWBYTES));
+
+ FMODExec(
system.createSound(url,
(MODE.HARDWARE | MODE._2D | MODE.CREATESTREAM),
ref extraInfo,
ref channel), "Stream channel");
FMODExec(channel.setVolume(volume), "Stream volume");
-#if GET_STREAM_TAGS
- if (Environment.OSVersion.Platform != PlatformID.Unix)
+ if (updateTimer == null)
{
- if (tagTimer == null)
- {
- tagTimer = new Timer(CheckTags);
- }
- tagTimer.Change(0, tagCheckInterval);
+ updateTimer = new Timer(Update);
}
-#endif
+ updateTimer.Change(0, updateIntervl);
}
catch (Exception ex)
{
- Logger.Log("Error playing stream: ", Helpers.LogLevel.Debug, ex);
+ Logger.Log("Error playing stream: " + ex.ToString(), Helpers.LogLevel.Debug);
}
}));
}
-#if GET_STREAM_TAGS
- private void CheckTags(object sender)
+ private void Update(object sender)
{
if (sound == null) return;
{
try
{
+ FMODExec(system.update());
+
TAG tag = new TAG();
- while (sound.getTag(null, -1, ref tag) == RESULT.OK)
+ int numTags = 0;
+ int numTagsUpdated = 0;
+
+ var res = sound.getNumTags(ref numTags, ref numTagsUpdated);
+
+ if (res == RESULT.OK && numTagsUpdated > 0)
{
- if (tag.datatype != TAGDATATYPE.STRING) continue;
+ for (int i=0; i < numTags; i++)
+ {
+ if (sound.getTag(null, i, ref tag) != RESULT.OK)
+ {
+ continue;
+ }
- // Tell listeners about the Stream tag. This can be
- // displayed to the user.
- if (OnStreamInfo != null)
- OnStreamInfo(this, new StreamInfoArgs(tag.name.ToLower(), Marshal.PtrToStringAnsi(tag.data)));
+ if (tag.type == TAGTYPE.FMOD && tag.name == "Sample Rate Change")
+ {
+ float newfreq = (float)Marshal.PtrToStructure(tag.data, typeof(float));
+ Logger.DebugLog("New stream frequency: " + newfreq.ToString("F" + 0));
+ channel.setFrequency(newfreq);
+ }
+
+ if (tag.datatype != TAGDATATYPE.STRING) continue;
+
+ // Tell listeners about the Stream tag. This can be
+ // displayed to the user.
+ if (OnStreamInfo != null)
+ OnStreamInfo(this, new StreamInfoArgs(tag.name.ToLower(), Marshal.PtrToStringAnsi(tag.data)));
+ }
}
}
catch (Exception ex)
}
}));
}
-#endif
}
}