Example #1
0
        internal OpenTKAudioCue(Stream data, AudioContext ac)
        {
            this.ac = ac;

            buffer = AL.GenBuffer();
            ac.CheckErrors();

            source = AL.GenSource();
            ac.CheckErrors();

            AL.Source(source, ALSourcef.Gain, (float)this.Volume);
            ac.CheckErrors();

            using (AudioReader ar = new AudioReader(data))
            {
                SoundData d = ar.ReadToEnd();
                AL.BufferData(source, d);
                ac.CheckErrors();
            }

            AL.Source(source, ALSourcei.Buffer, buffer);
            ac.CheckErrors();

            this.VolumeChanged += new VolumeChangedEventHandler(OpenTKAudioCue_VolumeChanged);
            this.BalanceChanged += new BalanceChangedEventHandler(OpenTKAudioCue_BalanceChanged);
            this.FadeChanged += new FadeChangedEventHandler(OpenTKAudioCue_FadeChanged);
        }
Example #2
0
        public override IAudioBuffer InitAudioBuffer(Resources.Resource handle)
        {
            var bufferId = AL.GenBuffer();
            var sourceId = AL.GenSource();

            var reader = new AudioReader(handle.Stream);
            //Read
            var soundData = reader.ReadToEnd();
            AL.BufferData(bufferId, soundData);
            var error = AL.GetError();
            if (error != ALError.NoError)
            {
                Logger.Error("Could not read Audio, {0}", error);
                return null;
            }

            var audioBuffer = new OpenAlAudioBuffer(bufferId,sourceId,soundData.Data.Length, handle);

            //Prepare
            AL.Source(sourceId, ALSourcei.Buffer, (int)bufferId);

            //Add
            AllSamples.Add(audioBuffer);
            return audioBuffer;
        }
Example #3
0
		internal SoundEffect(string fileName)
		{
			AudioEngine.EnsureInit();

			buffer = AL.GenBuffer(); 
		
			var error = AL.GetError();
			if (error != ALError.NoError)
			{
				throw new OpenALException(error, "borked generation. ALError: " + error.ToString());
			}

			XRamExtension XRam = new XRamExtension();
			if (XRam.IsInitialized) 
				XRam.SetBufferMode(1, ref buffer, XRamExtension.XRamStorage.Hardware); 
			
			
			
			AudioReader sound = new AudioReader(fileName);
			var sounddata = sound.ReadToEnd();
			AL.BufferData(buffer, sounddata.SoundFormat.SampleFormatAsOpenALFormat, sounddata.Data, sounddata.Data.Length, sounddata.SoundFormat.SampleRate);
			error = AL.GetError();
			if ( error != ALError.NoError )
			{
			   throw new OpenALException(error, "unable to read " + fileName);
			}			
			
			_name = Path.GetFileNameWithoutExtension(fileName);
		}
Example #4
0
 /// <summary>
 /// When overriden in a derived class, reads and decodes the sound stream.
 /// </summary>
 /// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
 public virtual SoundData ReadToEnd()
 {
     if (implementation != null)
     {
         return(implementation.ReadToEnd());
     }
     throw new NotImplementedException();
 }