Prepare() public method

public Prepare ( ) : void
return void
Ejemplo n.º 1
0
 public SoundItem(String sourcefile)
 {
     OggStream ostream = new OggStream(sourcefile);
     ostream.Prepare();
     useStream = ostream;
     //AL.BufferData(_Buffer,ostream.g)
 }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
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.");
            }
        }