private void PlatformSetIsLooped(bool value)
        {
            _looped = value;

            if (HasSourceId)
            {
                AL.Source(SourceId, ALSourceb.Looping, _looped);
                ALHelper.CheckError("Failed to set source loop state.");
            }
        }
Beispiel #2
0
 public OALSoundBuffer()
 {
     try
     {
         AL.GenBuffers(1, out openAlDataBuffer);
         ALHelper.CheckError("Failed to generate OpenAl data buffer");
     }
     catch (DllNotFoundException e)
     {
     }
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataBuffer"></param>
        /// <param name="format"></param>
        /// <param name="size"></param>
        /// <param name="sampleRate"></param>
        /// <param name="alignment"></param>
        public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate, int alignment = 0)
        {
            openAlFormat    = format;
            dataSize        = size;
            this.sampleRate = sampleRate;
            int unpackedSize = 0;

            AL.BufferData(openAlDataBuffer, openAlFormat, dataBuffer, size, this.sampleRate);
            ALHelper.CheckError("Failed to fill buffer");

            int bits, channels;

            AL.GetBuffer(openAlDataBuffer, ALGetBufferi.Bits, out bits);
            ALError alError = AL.GetError();

            if (alError != ALError.NoError)
            {
                Console.WriteLine("Failed to get bufer bits: {0},format = {1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate);
                Duration = -1;
            }
            else
            {
                AL.GetBuffer(openAlDataBuffer, ALGetBufferi.Channels, out channels);

                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    Console.WriteLine("Failed to get bufer bits: {0},format = {1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate);
                    Duration = -1;
                }
                else
                {
                    AL.GetBuffer(openAlDataBuffer, ALGetBufferi.Size, out unpackedSize);
                    alError = AL.GetError();
                    if (alError != AL.GetError())
                    {
                        Console.WriteLine("Failed to get bufer bits: {0},format = {1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate);
                        Duration = -1;
                    }
                    else
                    {
                        Duration = (float)(unpackedSize / ((bits / 8) * channels)) / (float)sampleRate;
                    }
                }
            }
        }
Beispiel #4
0
        private OpenAlSoundController()
        {
            if (!OpenSoundController())
            {
                return;
            }

            _bSoundAvailable = true;

            allSourcesArray = new int[MAX_NUMBER_OF_SOURCES];

            AL.GenSources(allSourcesArray);

            ALHelper.CheckError("Failed to generate sources");

            availableSourcesCollection = new List <int>(allSourcesArray);
            inUseSourcesCollection     = new List <int>();
        }
        /// <summary>
        ///
        /// </summary>
        private void PlatformPlay()
        {
            SourceId    = 0;
            HasSourceId = false;
            SourceId    = controller.ReserveSource();

            HasSourceId = true;

            int bufferId = _effect.SoundBuffer.OpenALDataBuffer;

            AL.Source(SourceId, ALSourcei.Buffer, bufferId);
            ALHelper.CheckError("Failed to bind buffer to source");

            if (!HasSourceId)
            {
                return;
            }

            //Distance Model
            AL.DistanceModel(ALDistanceModel.InverseDistanceClamped);
            ALHelper.CheckError("Failed set source distance");

            //Pan
            AL.Source(SourceId, ALSource3f.Position, _pan, 0, 0);
            ALHelper.CheckError("Failed to set Source pan.");

            //Volume
            AL.Source(SourceId, ALSourcef.Gain, _alVolume);
            ALHelper.CheckError("Failed to set source volume");


            //Looping
            AL.Source(SourceId, ALSourceb.Looping, IsLooped);
            ALHelper.CheckError("Failed to set source loop state");

            //Pitch
            AL.Source(SourceId, ALSourcef.Pitch, ToAlPitch(_pitch));
            ALHelper.CheckError("Failed to set source pitch");

            AL.SourcePlay(SourceId);
            ALHelper.CheckError("Failed to play source");
            SoundState = SoundState.Playing;
        }
Beispiel #6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                if (disposing)
                {
                    //Clean up managed objects
                }

                //Release unmanaged resources
                if (AL.IsBuffer(openAlDataBuffer))
                {
                    ALHelper.CheckError("Failed to fetch buffer state.");
                    AL.DeleteBuffers(1, ref openAlDataBuffer);
                    ALHelper.CheckError("Failed to delete buffer");
                }
                _isDisposed = true;
            }
        }
Beispiel #7
0
 void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         if (disposing)
         {
             if (_bSoundAvailable)
             {
                 for (int i = 0; i < allSourcesArray.Length; i++)
                 {
                     AL.DeleteSource(allSourcesArray[i]);
                     ALHelper.CheckError("Failed to delete source");
                 }
                 CleanUpOpenAl();
             }
         }
         _isDisposed = true;
     }
 }