예제 #1
0
		public bool BindToBuffer(Sound bufferToBindTo)
		{
			if (m_SourceHandle == -1)
			{
				return false;
			}

			// Bind the buffer with the source.
#if USE_OPENAL
            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;
            }
#endif

			return false;
		}
예제 #2
0
		public new static GameObject Load(String PathName)
		{
			// First we load up the Data In the Serialization file.
			String gameDataObjectXMLPath = Path.Combine(PathName, "Sound.xml");
			Sound soundLoaded = new Sound();// 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 + "'.");
			}

			Sound loadingBuffer = new Sound();
#if USE_OPENAL
            // 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.s_LoadedSounds.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)
#endif
			{
				return loadingBuffer;
			}

			return null;
		}
예제 #3
0
		private static Sound LoadSerializationFileForFolder(String gameDataObjectXMLPath)
		{
			Sound soundLoaded;
			try
			{
				soundLoaded = (Sound)GameObject.Load(gameDataObjectXMLPath);
			}
			catch (FileNotFoundException)
			{
				soundLoaded = new Sound();
				soundLoaded.SaveXML(gameDataObjectXMLPath);
			}

			return soundLoaded;
		}