Beispiel #1
0
 private void TimerTick(EngineContext context)
 {
     if (!_eventTimer.Enabled || _isStopping) {
         return;
     }
     context.TickCount = (context.SoundChannel != null) && context.SoundChannel.IsPlaying
         ? (int) context.SoundChannel.Position : context.StartOffset + ((int) context.Timekeeper.ElapsedMilliseconds);
     var num = context.TickCount / context.CurrentSequence.EventPeriod;
     if ((context.TickCount >= context.SequenceTickLength) || (num >= context.MaxEvent)) {
         _fmod.Stop(context.SoundChannel);
         context.Timekeeper.Stop();
         context.Timekeeper.Reset();
         if (IsLooping) {
             LogAudio(_engineContext.CurrentSequence);
             StartContextAudio(_engineContext);
             context.Timekeeper.Start();
             OnSequenceChange();
         }
         else {
             Host.Invoke(new MethodInvoker(Stop));
         }
     }
     else if (num != context.LastIndex) {
         context.LastIndex = num;
         FireEvent(context, context.LastIndex);
     }
 }
Beispiel #2
0
 private void StartAudio(EngineContext context)
 {
     if (((Mode != EngineMode.Asynchronous) && (context.SoundChannel != null)) && context.SoundChannel.Paused) {
         context.SoundChannel.Paused = false;
     }
 }
Beispiel #3
0
 private void StartContextAudio(EngineContext context)
 {
     if (context.CurrentSequence.Audio == null) {
         return;
     }
     if (Host.InvokeRequired) {
         MethodInvoker method = delegate {
             PrepareAudio(context, context.StartOffset);
             StartAudio(context);
         };
         Host.Invoke(method);
     }
     else {
         PrepareAudio(context, context.StartOffset);
         StartAudio(context);
     }
 }
Beispiel #4
0
 private void PrepareAudio(EngineContext context, int millisecondPosition)
 {
     if (((Mode == EngineMode.Asynchronous) || (context.SoundChannel == null)) || (millisecondPosition == -1)) {
         return;
     }
     _fmod.Play(context.SoundChannel, true);
     context.SoundChannel.Position = (uint) millisecondPosition;
     context.SoundChannel.Frequency = AudioSpeed;
 }
Beispiel #5
0
        private void InitEngineContext(ref EngineContext context, int sequenceIndex)
        {
            if (context == null) {
                return;
            }

            context.Timekeeper.Stop();
            if (Host.InvokeRequired) {
                Host.Invoke(new InitEngineContextDelegate(InitEngineContext), context, sequenceIndex);
            }
            else if ((sequenceIndex == -1) || (CurrentObject.EventSequences.Count <= sequenceIndex)) {
                FinalizeEngineContext(context);
            }
            else {
                var executableObject = CurrentObject.EventSequences[sequenceIndex].Sequence;
                if (context.RouterContext == null) {
                    context.RouterContext = _plugInRouter.CreateContext(new byte[executableObject.FullChannelCount],
                        _useSequencePluginData ? executableObject.PlugInData : CurrentObject.SetupData,
                        executableObject);
                }
                if (CurrentObject.Mask.Length > sequenceIndex) {
                    context.ChannelMask = CurrentObject.Mask[sequenceIndex];
                }
                context.TickCount = 0;
                context.LastIndex = -1;
                context.SequenceTickLength = executableObject.Time;
                context.StartOffset = 0;
                context.SoundChannel = executableObject.Audio != null ? _fmod.LoadSound(Path.Combine(Paths.AudioPath, executableObject.Audio.FileName), context.SoundChannel) : _fmod.LoadSound(null);
                context.CurrentSequence = executableObject;
                context.MaxEvent = context.CurrentSequence.TotalEventPeriods;
                context.LastPeriod = new byte[context.CurrentSequence.FullChannels.Count];
                for (var i = 0; i < context.LastPeriod.Length; i++) {
                    context.LastPeriod[i] = (byte) i;
                }
                context.Data = ReconfigureSourceData(executableObject);
            }
        }
Beispiel #6
0
        private void FireEvent(EngineContext context, int index)
        {
            if ((!context.Timekeeper.IsRunning || !_eventTimer.Enabled) || _isStopping) {
                return;
            }

            for (var i = 0; i < context.CurrentSequence.FullChannels.Count; i++) {
                context.RouterContext.EngineBuffer[i] = context.Data[i, index];
            }
            HardwareUpdate(context.RouterContext.EngineBuffer);
        }
Beispiel #7
0
        private void FinalizeEngineContext(EngineContext context, bool shutdownRouterContext = true)
        {
            if (context == null) {
                return;
            }

            if (shutdownRouterContext && (context.RouterContext != null)) {
                _plugInRouter.Shutdown(context.RouterContext);
                context.RouterContext = null;
            }
            if (context.SoundChannel != null) {
                _fmod.ReleaseSound(context.SoundChannel);
                context.SoundChannel = null;
            }
            if (!context.Timekeeper.IsRunning) {
                return;
            }
            context.Timekeeper.Stop();
            context.Timekeeper.Reset();
        }
Beispiel #8
0
 private void ConstructUsing(EngineMode mode, Host host, int audioDeviceIndex)
 {
     Mode = mode;
     _host = host;
     _plugInRouter = Host.Router;
     if (mode == EngineMode.Synchronous) {
         _eventTimer = new Timer(1.0);
         _eventTimer.Elapsed += EventTimerElapsed;
         _fmod = fmod.GetInstance(audioDeviceIndex);
     }
     else {
         _eventTimer = null;
         _fmod = null;
     }
     _engineContext = new EngineContext();
     InstanceList.Add(this);
 }