Beispiel #1
0
        public new static GameObject <T> Load(String PathName)
        {
            // First we load up the Data In the Serialization file.
            String          gameDataObjectXMLPath = Path.Combine(PathName, "SoundBuffer.xml");
            SoundBuffer <T> soundBufferLoaded     = new SoundBuffer <T>();// LoadSerializationFileForFolder(gameDataObjectXMLPath);

            String[] wavFilesArray = Directory.GetFiles(PathName, "*.wav");
            if (wavFilesArray.Length > 1 || wavFilesArray.Length < 1)
            {
                throw new System.Exception("You must have at leas and at most 1 loadable adio file in the dirrectory '" + PathName + "'.");
            }

            SoundBuffer <T> loadingBuffer = new SoundBuffer <T>();
            // Variables to load into.
            int format;
            int size;

            byte[] data = null;
            int    frequency;

            // Generate an OpenAL buffer.
            Al.alGenBuffers(1, out loadingBuffer.m_BufferHandle);
            if (Al.alGetError() != Al.AL_NO_ERROR)
            {
                return(null);
            }

            AudioSystem <T> .s_LoadedSoundBuffers.Add(loadingBuffer);

            // Attempt to locate the file.
            string fileName = wavFilesArray[0];

            //string fileName = "../../GameData/AsteroidExplosion.Sound/11_AsteroidExplosion.wav";

            if (!File.Exists(fileName))
            {
                return(null);
            }

            // Load wav.
            Alut.alutLoadWAVFile(fileName, out format, out data, out size, out frequency, out loadingBuffer.m_Loop);
            if (data == null)
            {
                return(null);
            }

            // Load wav data into the generated buffer.
            Al.alBufferData(loadingBuffer.m_BufferHandle, format, data, size, frequency);
            Alut.alutUnloadWAV(format, out data, size, frequency);

            // Do a final error check and then return.
            if (Al.alGetError() == Al.AL_NO_ERROR)
            {
                return(loadingBuffer);
            }

            return(null);
        }
Beispiel #2
0
        private static SoundBuffer <T> LoadSerializationFileForFolder(String gameDataObjectXMLPath)
        {
            SoundBuffer <T> soundBufferLoaded;

            try
            {
                soundBufferLoaded = (SoundBuffer <T>) GameObject <T> .Load(gameDataObjectXMLPath);
            }
            catch (FileNotFoundException)
            {
                soundBufferLoaded = new SoundBuffer <T>();
                soundBufferLoaded.SaveXML(gameDataObjectXMLPath);
            }

            return(soundBufferLoaded);
        }
Beispiel #3
0
        public bool BindToBuffer(SoundBuffer <T> bufferToBindTo)
        {
            if (m_SourceHandle == -1)
            {
                return(false);
            }

            // Bind the buffer with the source.
            Al.alSourcei(m_SourceHandle, Al.AL_BUFFER, bufferToBindTo.m_BufferHandle);
            Al.alSourcef(m_SourceHandle, Al.AL_PITCH, 1.0f);
            Al.alSourcef(m_SourceHandle, Al.AL_GAIN, 1.0f);
            Al.alSourcefv(m_SourceHandle, Al.AL_POSITION, m_SourcePosition);
            Al.alSourcefv(m_SourceHandle, Al.AL_VELOCITY, m_SourceVelocity);
            Al.alSourcei(m_SourceHandle, Al.AL_LOOPING, bufferToBindTo.m_Loop);

            // Do a final error check and then return.
            if (Al.alGetError() == Al.AL_NO_ERROR)
            {
                return(true);
            }

            return(false);
        }