Exemplo n.º 1
0
        public void Initialize(Xstream f)
        {
            _window = f;
            _hwnd   = f.GetHandle();

            Initialize(SDL_RendererFlags.SDL_RENDERER_ACCELERATED
                       | SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
        }
Exemplo n.º 2
0
        /*
         * 这个samples是指样本帧中音频缓存区的大小。
         * 样本帧是一块音频数据,其大小指定为 format * channels
         * 其中format指的是每个样本的位数,这里使用WAVE_FORMAT_IEEE_FLOAT即4字节(32位)浮点型。
         * 在PCM中format等同于sampleSize
         *
         * @see: https://my.oschina.net/u/4365632/blog/3319770
         *       https://wiki.libsdl.org/SDL_AudioSpec#Remarks
         */
        public int Initialize(Xstream f, int samples)
        {
            _window  = f;
            _samples = samples;

            _shutdown = false;// just in case.
            _paused   = true;
            _enabled  = true;

            try
            {
                OpenDevice();

                // pool a few packets to start. Enough for two callbacks.
                _queue = DataQueuePacket.NewDataQueue(SDL_AUDIOBUFFERQUEUE_PACKETLEN, (size_t)(_bufferSize * 2));

                // Allocate a scratch audio buffer
                _worklen = _bufferSize;
                _workbuf = (byte *)Marshal.AllocHGlobal(_worklen);

                _thread = new Thread(RunAudio);

                // The audio mixing is always a high priority thread
                _thread.Priority = ThreadPriority.Highest;

                // Start the audio thread
                _thread.Start();
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Failed to open audio: {e.Message}");
                Close();
                return(1);
            }

            Pause(0);// start audio playing.

            return(0);
        }
Exemplo n.º 3
0
 public bool Initialize(Xstream f)
 {
     _hwnd = f.GetHandle();
     return(Initialize());
 }