示例#1
0
                public ProactiveAudioStreamSourceOpenTk(
                    IDiscardableNode parent,
                    Action <byte[]> populateFunc,
                    int channels,
                    int bytesPerSample,
                    int frequency,
                    int numBuffers,
                    int bufferSize)
                {
                    this.node_            = parent.CreateChild();
                    this.node_.OnDiscard += _ => this.Destroy_();

                    this.sourceId_ = AL.GenSource();

                    this.bufferIds_    = AL.GenBuffers(numBuffers).ToImmutableArray();
                    this.populateFunc_ = populateFunc;

                    this.format_ = PcmHelperOpenTk.GetPcmFormat(channels, bytesPerSample);

                    this.frequency_  = frequency;
                    this.bufferSize_ = bufferSize;

                    this.currentBufferIndex_ =
                        new CircularRangedInt(0, 0, numBuffers);

                    // TODO: Delay this until the observable has returned some value. Stream
                    // should remember stop/play/paused state as expected in the meantime.
                    this.readyBuffersIds_ = new Queue <int>();
                    foreach (var bufferId in this.bufferIds_)
                    {
                        this.readyBuffersIds_.Enqueue(bufferId);
                    }
                    this.PopulateAndQueueReadyBuffers_();
                }
                public void FillWithPcm(IPcmData pcm)
                {
                    this.pcm_ = pcm;

                    var channels       = pcm.Channels;
                    var bytesPerSample = pcm.BytesPerSample;
                    var format         = PcmHelperOpenTk.GetPcmFormat(channels, bytesPerSample);

                    var bytes = pcm.Pcm;

                    AL.BufferData(this.Id,
                                  format,
                                  bytes,
                                  bytes.Length,
                                  pcm.SampleRate);
                }