/// <summary>
        ///     This method is called when Sample load is requested, if you return a Sample
        ///     it will return it from the user else it will keep trying all the other SampleLoaders
        ///     until it does get one
        /// </summary>
        /// <param name="path">File path of the sound to load.</param>
        /// <param name="streamed">If set to true the sound will be loaded in piece by piece rather than all at once.</param>
        /// <returns>New Sample instance or NULL if this factory can't load the given audio sample file format.</returns>
        protected override Sample RequestLoad(object path, bool streamed)
        {
            // Load in the audio file's data.
            Stream stream = StreamFactory.RequestStream(path, StreamMode.Open);

            if (stream == null)
            {
                return(null);
            }
            if (stream.ReadByte() != 'O' || stream.ReadByte() != 'g' || stream.ReadByte() != 'g' || stream.ReadByte() != 'S')
            {
                stream.Close();
                return(null);
            }
            stream.Position = 0;

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, (int)stream.Length);
            stream.Close();

            // Create an audiere memory file to place our data into.
            ManagedAudiere.File file          = Audiere.CreateMemoryFile(new MemoryFileBuffer(data, data.Length));
            SampleSource        audiereSample = Audiere.OpenSampleSource(file);
            SampleFormatData    sampleFormat  = audiereSample.GetFormat();

            int size = audiereSample.Length * (Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count);
            MemoryFileBuffer audiereBuffer = new MemoryFileBuffer(new byte[size], size);

            audiereSample.Read(audiereSample.Length, audiereBuffer);

            // Put the audiere audio buffer into a new sample buffer.
            byte[] pcmBuffer = audiereBuffer.GetBuffer();
            Sample sample    = null;

            if (sampleFormat.channel_count == 1)
            {
                sample = new Sample(SampleFormat.MONO16LE, pcmBuffer.Length);
            }
            else
            {
                sample = new Sample(SampleFormat.STEREO16LE, pcmBuffer.Length);
            }

            sample.SampleRate    = sampleFormat.sample_rate;
            sample.ChannelCount  = sampleFormat.channel_count;
            sample.BlockAlign    = Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count;
            sample.ByteRate      = sample.SampleRate * sample.BlockAlign;
            sample.BitsPerSample = Audiere.GetSampleSize(sampleFormat.sample_format) * 8;

            for (int i = 0; i < pcmBuffer.Length; i++)
            {
                sample.Data[i] = pcmBuffer[i];
            }

            return(sample);
        }
        /// <summary>
        ///     This method is called when Sample load is requested, if you return a Sample
        ///     it will return it from the user else it will keep trying all the other SampleLoaders
        ///     until it does get one
        /// </summary>
        /// <param name="path">File path of the sound to load.</param>
        /// <param name="streamed">If set to true the sound will be loaded in piece by piece rather than all at once.</param>
        /// <returns>New Sample instance or NULL if this factory can't load the given audio sample file format.</returns>
        protected override Sample RequestLoad(object path, bool streamed)
        {
            // Load in the audio file's data.
            Stream stream = StreamFactory.RequestStream(path, StreamMode.Open);
            if (stream == null) return null;
            if (stream.ReadByte() != 'O' || stream.ReadByte() != 'g' || stream.ReadByte() != 'g' || stream.ReadByte() != 'S')
            {
                stream.Close();
                return null;
            }
            stream.Position = 0;

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, (int)stream.Length);
            stream.Close();

            // Create an audiere memory file to place our data into.
            ManagedAudiere.File file = Audiere.CreateMemoryFile(new MemoryFileBuffer(data, data.Length));
            SampleSource audiereSample = Audiere.OpenSampleSource(file);
            SampleFormatData sampleFormat = audiereSample.GetFormat();

            int size = audiereSample.Length * (Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count);
            MemoryFileBuffer audiereBuffer = new MemoryFileBuffer(new byte[size], size);
            audiereSample.Read(audiereSample.Length, audiereBuffer);

            // Put the audiere audio buffer into a new sample buffer.
            byte[] pcmBuffer = audiereBuffer.GetBuffer();
            Sample sample = null;

            if (sampleFormat.channel_count == 1)
                sample = new Sample(SampleFormat.MONO16LE, pcmBuffer.Length);
            else
                sample = new Sample(SampleFormat.STEREO16LE, pcmBuffer.Length);

            sample.SampleRate = sampleFormat.sample_rate;
            sample.ChannelCount = sampleFormat.channel_count;
            sample.BlockAlign = Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count;
            sample.ByteRate = sample.SampleRate * sample.BlockAlign;
            sample.BitsPerSample = Audiere.GetSampleSize(sampleFormat.sample_format) * 8;

            for (int i = 0; i < pcmBuffer.Length; i++)
                sample.Data[i] = pcmBuffer[i];

            return sample;
        }