private FMODAudioEngine() { FMODErr.Check(Factory.System_Create(ref _system)); uint version = 0; FMODErr.Check(_system.getVersion(ref version)); if (version < VERSION.number) { throw new ApplicationException( "Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + VERSION.number.ToString("X") + "."); } FMODErr.Check(_system.init(16, INITFLAG.NORMAL, IntPtr.Zero)); ChannelGroup channelGroup = null; FMODErr.Check(_system.getMasterChannelGroup(ref channelGroup)); _masterChannelGroup = new FMODGrouping(this, channelGroup); _scheduler = new EventLoopScheduler("AudioEngine"); _updateTimer = Observable.Interval(TimeSpan.FromMilliseconds(UpdateInterval), _scheduler).Do(_ => Update()); }
/// <summary> /// Plays the sound on a free channel /// </summary> /// <param name="system">The system.</param> public void Play(PlaybackEnd_Callback callback = null) { try { lock (_engine.Lock) { _endCallback = callback; FMODErr.Check( _engine.System.playSound( CHANNELINDEX.FREE, _sound, true, ref _channel)); if (_group != null) { FMODErr.Check(_channel.setChannelGroup(_group.ChannelGroup)); } Volume = _volume; _channel.setCallback(CHANNEL_CALLBACKTYPE.END, _channelCallbackDelegate, 0); IsPaused = false; } } catch (Exception e) { GameLog.Client.Audio.Error(e); } }
internal FMODGrouping([NotNull] FMODAudioEngine engine, string name) { if (engine == null) { throw new ArgumentNullException("engine"); } _engine = engine; FMODErr.Check(engine.System.createChannelGroup(name, ref _channelGroup)); }
/// <summary> /// Initializes a new instance of the <see cref="FMODAudioTrack"/> class. /// Loads the file and creates sound and channel /// </summary> internal FMODAudioTrack([NotNull] FMODAudioEngine engine, string filePath) { _engine = engine; MODE creationMode = MODE.HARDWARE | MODE.CREATESTREAM | MODE.LOOP_OFF; FMODErr.Check(_engine.System.createSound(filePath, creationMode, ref _sound)); // keep a reference on the callback delegate for passing to unmanaged code _channelCallbackDelegate = new CHANNEL_CALLBACK(OnPlaybackEnd); }
/// <summary> /// Stops the playing of the sound on this channel. /// </summary> public void Stop() { try { lock (_engine.Lock) { if (_channel != null) { FMODErr.Check(_channel.stop()); _channel = null; GameLog.Client.Audio.DebugFormat("No problem at AudioTrack.Stop"); } } } catch (Exception e) { GameLog.Client.Audio.Error(e); } }