Esempio n. 1
0
        private void PlatformInitialize(string fileName)
        {
            stream = new OggStream(fileName, OnFinishedPlaying);
            stream.Prepare();

            _duration = stream.GetLength();
        }
Esempio n. 2
0
        public OggStream GetCue(string name, bool asyncPrecache = false)
        {
            OggStream oggStream = (OggStream)null;

            try
            {
                string str  = name.Replace(" ^ ", "\\");
                bool   flag = name.Contains("Ambience");
                oggStream = new OggStream(this.MusicAliases[str.ToLower(CultureInfo.InvariantCulture)], 6)
                {
                    Category = flag ? "Ambience" : "Music",
                    IsLooped = flag
                };
                oggStream.RealName = name;
                oggStream.Prepare(asyncPrecache);
                if (name.Contains("Gomez"))
                {
                    oggStream.LowPass = false;
                }
            }
            catch (Exception ex)
            {
                Logger.Log("SoundManager", LogSeverity.Error, ex.Message);
            }
            return(oggStream);
        }
Esempio n. 3
0
        private void PlatformInitialize(string fileName)
        {
            // init OpenAL if need be
            OpenALSoundController.EnsureInitialized();

            stream = new OggStream(fileName, OnFinishedPlaying);
            stream.Prepare();

            _duration = stream.GetLength();
        }
Esempio n. 4
0
        private void PlaySoundThread(string assetName, bool loop)
        {
            string fileName = this.GetAsset(assetName).fileName;
            string ext      = fileName.Substring(fileName.LastIndexOf(@".") + 1);

            if (ext == "wav")
            {
                int    channels, bits_per_sample, sample_rate;
                byte[] data = OpenTKUtils.LoadWave(fileName, out channels, out bits_per_sample, out sample_rate);

                int buffer = AL.GenBuffer();
                int source = AL.GenSource();
                AL.BufferData(buffer, OpenTKUtils.WaveFormat(channels, bits_per_sample), data, data.Length, sample_rate);

                AL.Source(source, ALSourcei.Buffer, buffer);
                AL.Source(source, ALSourceb.Looping, loop);


                AL.SourcePlay(source);

                int state;

                do
                {
                    Thread.Sleep(300);
                    AL.GetSource(source, ALGetSourcei.SourceState, out state);
                } while ((ALSourceState)state == ALSourceState.Playing);

                AL.SourceStop(source);
                AL.DeleteSource(source);
                AL.DeleteBuffer(buffer);
            }
            else if (ext == "ogg")
            {
                using (var streamer = new OggStreamer()) {
                    OggStream stream = new OggStream(fileName);
                    stream.Prepare();
                    stream.Play();
                }
            }
            else
            {
                throw new NotImplementedException($"Support for audio extension '{ext}' is not implemented.");
            }
        }
Esempio n. 5
0
        internal Song(string name, string file, AudioFormat format = AudioFormat.Ogg)
        {
            if (format != AudioFormat.Ogg)
            {
                throw new NotImplementedException("Support for formats other than ogg is not yet implemented.");
            }

            _name = name;
            _file = file;

            try
            {
                _stream = new OggStream(_file);
                _stream.Prepare();
            }
            catch (InvalidDataException)
            {
                _stream.Dispose();
                _stream = new OggStream(_file);
                _stream.Prepare();
            }
        }