Beispiel #1
0
        public WavePlayer(PlayerSettings settings)
        {
            OpenAL.AlutInit();
            this.settings = settings;

            this.baseStream = new RawWaveStream(this.settings.BitPerSample, this.settings.SamplingFrequency, this.settings.ChannelCount);
            this.audioSource = new AudioSource();

            this.baseStream.Reading += Generate;
        }
Beispiel #2
0
        public AudioStreamPlayer(AudioStream audioStream, AudioSource audioSource, int buffersize, int buffercount)
        {
            if (audioStream == null)
            {
                throw new ArgumentNullException("audioStream");
            }
            if (audioSource == null)
            {
                throw new ArgumentNullException("audioSource");
            }
            if (buffersize <= 0)
            {
                throw new ArgumentOutOfRangeException("buffersize", "the buffer's size must be greater then 0");
            }
            if (buffercount <= 0)
            {
                throw new ArgumentOutOfRangeException("buffercount", "the buffercount must be greater then 0");
            }
            if (Environment.OSVersion.Platform != PlatformID.Unix && !audioSource.IsValid)
            {
                throw new ArgumentException("The audioSource must be a valid source", "audioSource");
            }

            this.emptyBuffers = new Queue<AudioBuffer>();
            this.stream = audioStream;
            this.source = audioSource;
            this.buffer = new byte[buffersize];
            this.source.Stop();
            OpenAlException.CheckAl();
            buffers = AudioBuffer.CreateBuffers(buffercount);
            for (int pos = 0; pos < buffercount; ++pos)
            {
                FillBuffer(buffers[pos]);
            }
            audioSource.EnqueueBufferRange(buffers);
        }
Beispiel #3
0
 public static AudioSource[] CreateSources(int count)
 {
     int[] ids = new int[count];
     Al.alGenSources(count, ids);
     OpenAlException.CheckAl();
     AudioSource[] rv = new AudioSource[count];
     AudioContext context = AudioContext.CurrentContext;
     for (int pos = 0; pos < count; ++pos)
     {
         rv[pos] = new AudioSource(ids[pos], context);
     }
     return rv;
 }