示例#1
0
        public void Clear()
        {
            recorder?.Stop();
            recorder?.Release();
            recorder?.Dispose();
            recorder = null;

            audioTrack?.Stop();
            audioTrack?.Release();
            audioTrack?.Dispose();
            audioTrack = null;
        }
示例#2
0
        /// <summary>
        /// Stops the currently playing audio
        /// </summary>
        public void StopPlaying()
        {
            //This lock is used to ensure that starting and stopping of songs do not happen at the same time.
            lock (startStopSyncObject)
            {
                if (!IsPlaying)
                {
                    throw new InvalidOperationException("Audio is not playing");
                }
#if __ANDROID__
                //We use pause instead of stop because pause stops playing immediately
                playingTrack.Pause();

                //Lock track disposal so the track is never in a state where it is disposed/released but not null
                lock (trackDisposedOfSyncObject)
                {
                    playingTrack.Release();
                    playingTrack.Dispose();
                    playingTrack = null;
                }
#endif
#if __IOS__
                //Pass true to stop immediately
                audioQueue.Stop(true);

                //Lock track disposal so the track is never in a state where it is disposed but not null
                lock (trackDisposedOfSyncObject)
                {
                    audioQueue.Dispose();
                    audioQueue = null;
                }
#endif
            }
        }
示例#3
0
 protected override void Dispose(bool isDisposing)
 {
     base.Dispose(isDisposing);
     audioTrack?.Dispose();
     audioTrackStream?.Dispose();
     effectController?.Dispose();
 }
示例#4
0
    public void stop()
    {
        if (!running)
        {
            return;
        }

        running = false;

        MainActivity.Instance.VolumeControlStream = Stream.NotificationDefault;

        if (audioPlayer != null)
        {
            try
            {
                audioPlayer.Stop();
                audioPlayer.Release();
            }
            catch (Exception)
            {
            }

            audioPlayer.Dispose();
            audioPlayer = null;
        }

        if (audioDecoder != null)
        {
            audioDecoder.stop();
            audioDecoder.Dispose();
            audioDecoder = null;
        }

        bufferSize = 0;
    }
示例#5
0
        void IDualityBackend.Shutdown()
        {
            // Shut down the streaming thread
            if (streamWorker != null)
            {
                streamWorkerEnd = true;
                if (!streamWorker.Join(1000))
                {
                    streamWorker.Abort();
                }
                streamWorkerQueueEvent.Dispose();
                streamWorkerEnd        = false;
                streamWorkerQueueEvent = null;
                streamWorkerQueue      = null;
                streamWorker           = null;
            }

            if (masterTrack != null)
            {
                masterTrack.Stop();
                masterTrack.Dispose();
                masterTrack = null;
            }

            if (activeInstance == this)
            {
                activeInstance = null;
            }
        }
        /// <summary>
        /// Plays a single note. Separate from the rest of the song playing code
        /// </summary>
        public static void PlayNote(Instrument.Note note)
        {
            lock (syncObj)
            {
#if __ANDROID__
                if (playingTrack != null)
                {
                    //We use pause instead of stop because pause stops playing immediately
                    playingTrack.Pause();
                    playingTrack.Release();
                    playingTrack.Dispose();
                }
#endif
#if __IOS__
                if (audioQueue != null)
                {
                    //Pass true to stop immediately
                    audioQueue.Stop(true);
                    audioQueue.Dispose();
                }
#endif

#if __ANDROID__
                playingTrack = new AudioTrack(
                    // Stream type
                    Android.Media.Stream.Music,
                    // Frequency
                    SongPlayer.PLAYBACK_RATE,
                    // Mono or stereo
                    ChannelOut.Mono,
                    // Audio encoding
                    Android.Media.Encoding.Pcm16bit,
                    // Length of the audio clip in bytes
                    (note.data.Length * 2),
                    // Mode. Stream or static.
                    AudioTrackMode.Static);

                playingTrack.Write(note.data, 0, note.data.Length);
                playingTrack.Play();
#endif
#if __IOS__
                audioQueue = new OutputAudioQueue(AudioStreamBasicDescription.CreateLinearPCM(SongPlayer.PLAYBACK_RATE, 1, 16, false));
                unsafe
                {
                    AudioQueueBuffer *buffer;
                    audioQueue.AllocateBuffer(note.data.Length * 2, out buffer);

                    fixed(short *beatData = note.data)
                    {
                        buffer->CopyToAudioData((IntPtr)beatData, note.data.Length * 2);
                    }

                    audioQueue.EnqueueBuffer((IntPtr)buffer, note.data.Length * 2, null);
                }

                audioQueue.Start();
#endif
            }
        }
示例#7
0
        public void Dispose()
        {
            Stop();
            StopImmediate();

            audioTrack.Release();
            audioTrack.Dispose();
            audioTrack = null;
        }
示例#8
0
 public void Stop()
 {
     if (Track != null)
     {
         Track.Stop();
         Track.Dispose();
         Track = null;
     }
 }
示例#9
0
 protected virtual void Dispose(bool disposing)
 {
     if (!isDisposed)
     {
         track?.Dispose();
         reader?.Dispose();
         isDisposed = true;
     }
 }
示例#10
0
 protected virtual void Dispose(bool disposing)
 {
     if (!isDisposed)
     {
         track?.Dispose();
         background?.Dispose();
         isDisposed = true;
     }
 }
 public void Close()
 {
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
         audioTrack.Dispose();
     }
 }
示例#12
0
 private void StopImmediate()
 {
     if (audioTrackImmediate != null)
     {
         audioTrackImmediate.Stop();
         audioTrackImmediate.Release();
         audioTrackImmediate.Dispose();
         audioTrackImmediate = null;
     }
 }
示例#13
0
 internal virtual void InternalDispose()
 {
     Mixer.m_sounds.Remove(this);
     if (m_audioTrack != null)
     {
         m_audioTrack.Pause();
         m_audioTrack.Release();
         m_audioTrack.Dispose();
         m_audioTrack = null;
         Mixer.m_audioTracksDestroyed++;
     }
 }
示例#14
0
 public void stop()
 {
     if (audioPlayer == null)
     {
         return;
     }
     audioPlayer.Stop();
     audioPlayer.Release();
     audioPlayer.Dispose();
     audioPlayer = null;
     running     = false;
 }
示例#15
0
        private void StopStreamingAudio()
        {
#if __ANDROID__
            if (playingTrack == null || playingTrack.PlayState != PlayState.Playing)
            {
                throw new InvalidOperationException("Audio is not playing");
            }

            playingTrack.Pause();
            //playingTrack.Flush();
            playingTrack.Release();
            playingTrack.Dispose();
#endif
        }
示例#16
0
        private static void ResetAudioPreview()
        {
            if (sampleTrack != null)
            {
                sampleTrack.Dispose();
                sampleTrack = null;

                if (WasPlayingAudio && GameBase.Mode != OsuModes.OnlineSelection && GameBase.Mode != OsuModes.Play)
                {
                    AudioEngine.AllowRandomSong = true;
                    AudioEngine.TogglePause();
                }
            }
        }
示例#17
0
        /// <summary>
        /// Stop the audio
        /// </summary>
        public static void Stop()
        {
            if (active)
            {
                Pause();

                if (song.IsPlaying)
                {
                    song.Stop();
                }

                song.Dispose();
                song = null;

                Reset();
            }
        }
示例#18
0
 public void Stop()
 {
     if (State == SoundStates.Stopped)
     {
         return;
     }
     if (instance == null)
     {
         return;
     }
     instance.Stop();
     instance.Release();
     instance.Dispose();
     instance = null;
     audio.removeinstance();
     State = SoundStates.Stopped;
 }
示例#19
0
    public void stop()
    {
        running = false;

        lock (pendingFrames)
        {
            pendingFrames.Clear();
            availableBuffers.Clear();
        }

        if (audioPlayer != null)
        {
            try
            {
                audioPlayer.Stop();
                audioPlayer.Release();
            }
            catch (Exception)
            {
            }

            audioPlayer.Dispose();
            audioPlayer = null;
        }

        if (audioDecoder != null)
        {
            try
            {
                audioDecoder.Stop();
                audioDecoder.Release();
            }
            catch (Exception)
            {
            }
            audioDecoder.Dispose();
            audioDecoder = null;
        }

        bufferSize = 0;
    }
示例#20
0
        private void OnPlayButton(string koe, int speed)
        {
            var wav = new AquesTalk().synthe(koe, speed);

            if (wav.Length == 1)
            {
                return;
            }

            if (_audioTrack != null)
            {
                _audioTrack.Stop();
                _audioTrack.Release();
                _audioTrack.Dispose();
            }

            _audioTrack =
                new AudioTrack(Stream.Music, 8000, ChannelOut.Mono, Encoding.Pcm16bit, wav.Length - 44,
                               AudioTrackMode.Static);

            _audioTrack.Write(wav, 44, wav.Length - 44);
            _audioTrack.Play();
        }
 public void Dispose()
 {
     Track.Release();
     Track.Dispose();
     JNIEnv.DeleteGlobalRef(javaDataBuffer);
 }
示例#22
0
 /// <summary>
 /// Called to dispose of the object
 /// </summary>
 public void Dispose()
 {
     _audioTrack?.Release();
     _audioTrack?.Dispose();
 }