Пример #1
0
        // stream creation
        //-------------------------------------------------
        //  stream_alloc - allocate a new stream
        //-------------------------------------------------
        public sound_stream stream_alloc(device_t device, int inputs, int outputs, int sample_rate, stream_update_delegate callback = null)
        {
            var stream = new sound_stream(device, inputs, outputs, sample_rate, callback);

            m_stream_list.push_back(stream);
            return(stream);
        }
Пример #2
0
        stream_update_delegate m_callback;                    // callback function


        // construction/destruction
        //-------------------------------------------------
        //  sound_stream - constructor
        //-------------------------------------------------
        public sound_stream(device_t device, int inputs, int outputs, int sample_rate, stream_update_delegate callback)
        {
            m_device                 = device;
            m_next                   = null;
            m_sample_rate            = (UInt32)sample_rate;
            m_new_sample_rate        = 0xffffffff;
            m_attoseconds_per_sample = 0;
            m_max_samples_per_update = 0;
            m_input                  = new std.vector <stream_input>(); //(inputs)
            for (int i = 0; i < inputs; i++)
            {
                m_input.Add(new stream_input());
            }
            m_input_array       = new ListPointer <stream_sample_t> [inputs];
            m_resample_bufalloc = 0;
            m_output            = new std.vector <stream_output>(); //(outputs)
            for (int i = 0; i < outputs; i++)
            {
                m_output.Add(new stream_output());
            }
            m_output_array            = new ListPointer <stream_sample_t> [outputs];
            m_output_bufalloc         = 0;
            m_output_sampindex        = 0;
            m_output_update_sampindex = 0;
            m_output_base_sampindex   = 0;
            m_callback = callback;


            // get the device's sound interface
            device_sound_interface sound;

            if (!device.interface_(out sound))
            {
                throw new emu_fatalerror("Attempted to create a sound_stream with a non-sound device");
            }

            if (m_callback == null)
            {
                m_callback = sound.sound_stream_update;
            }

            // create a unique tag for saving
            string state_tag = string.Format("{0}", m_device.machine().sound().streams().size());

            m_device.machine().save().save_item(device, "stream", state_tag, 0, m_sample_rate, "m_sample_rate");
            m_device.machine().save().register_postload(postload);

            // save the gain of each input and output
            for (int inputnum = 0; inputnum < m_input.size(); inputnum++)
            {
                m_device.machine().save().save_item(device, "stream", state_tag, inputnum, m_input[inputnum].m_gain, "m_input[inputnum].m_gain");
                m_device.machine().save().save_item(device, "stream", state_tag, inputnum, m_input[inputnum].m_user_gain, "m_input[inputnum].m_user_gain");
            }

            for (int outputnum = 0; outputnum < m_output.size(); outputnum++)
            {
                m_output[outputnum].m_stream = this;
                m_device.machine().save().save_item(device, "stream", state_tag, outputnum, m_output[outputnum].m_gain, "m_output[outputnum].m_gain");
            }

            // Mark synchronous streams as such
            m_synchronous = (int)m_sample_rate == sound_global.STREAM_SYNC;
            if (m_synchronous)
            {
                m_sample_rate = 0;
                m_sync_timer  = m_device.machine().scheduler().timer_alloc(sync_update, this);
            }
            else
            {
                m_sync_timer = null;
            }

            // force an update to the sample rates; this will cause everything to be recomputed
            // and will generate the initial resample buffers for our inputs
            recompute_sample_rate_data();

            // set up the initial output buffer positions now that we have data
            m_output_base_sampindex = -m_max_samples_per_update;
        }