Exemplo n.º 1
0
        public void Play()
        {
            dynamic ctx = _context;

            if (ctx.state == "suspended" || ctx.state == "interrupted")
            {
                ctx.resume();
            }

            // create an empty buffer source (silence)
            _buffer = _context.CreateBuffer(2, BufferSize, _context.SampleRate);

            // create a script processor node which will replace the silence with the generated audio
            _audioNode = _context.CreateScriptProcessor(BufferSize, 0, 2);
            _audioNode.OnAudioProcess = (Action <AudioProcessingEvent>)GenerateSound;

            _circularBuffer.Clear();

            RequestBuffers();
            _finished      = false;
            _source        = _context.CreateBufferSource();
            _source.Buffer = _buffer;
            _source.Loop   = true;
            _source.Connect(_audioNode, 0, 0);
            _source.Start(0);
            _audioNode.Connect(_context.Destination, 0, 0);
        }