示例#1
0
        private long _soundRemainder;         // audio timekeeping for video dumping

        /// <exception cref="InvalidOperationException">
        /// <paramref name="asyncSoundProvider"/>'s mode is not <see cref="SyncSoundMode.Async"/>, or
        /// A/V parameters haven't been set (need to call <see cref="AVStretcher.SetAudioParameters"/> and <see cref="AVStretcher.SetMovieParameters"/>)
        /// </exception>
        public void DumpAV(IVideoProvider v, ISoundProvider asyncSoundProvider, out short[] samples, out int samplesProvided)
        {
            // Sound refactor TODO: we could try set it here, but we want the client to be responsible for mode switching? There may be non-trivial complications with when to switch modes that we don't want this object worrying about
            if (asyncSoundProvider.SyncMode != SyncSoundMode.Async)
            {
                throw new InvalidOperationException("Only async mode is supported, set async mode before passing in the sound provider");
            }

            if (!ASet || !VSet)
            {
                throw new InvalidOperationException("Must set params first!");
            }

            long nSampNum = Samplerate * (long)FpsDen + _soundRemainder;
            long nsamp    = nSampNum / FpsNum;

            // exactly remember fractional parts of an audio sample
            _soundRemainder = nSampNum % FpsNum;

            samples = new short[nsamp * Channels];
            asyncSoundProvider.GetSamplesAsync(samples);
            samplesProvided = (int)nsamp;

            W.AddFrame(v);
            W.AddSamples(samples);
        }
示例#2
0
        public void GetSamplesAsync(short[] samples)
        {
            int samplesToGenerate = SamplesInOneFrame;

            if (buffer.Count > samples.Length + MaxExcessSamples)
            {
                samplesToGenerate = 0;
            }
            if (buffer.Count - samples.Length < TargetExtraSamples)
            {
                samplesToGenerate += SamplesInOneFrame;
            }
            if (samplesToGenerate + buffer.Count < samples.Length)
            {
                samplesToGenerate = samples.Length - buffer.Count;
            }

            var mySamples = new short[samplesToGenerate];

            if (BaseSoundProvider.SyncMode != SyncSoundMode.Async)
            {
                throw new InvalidOperationException("Base sound provider must be in async mode.");
            }
            BaseSoundProvider.GetSamplesAsync(mySamples);

            foreach (short s in mySamples)
            {
                buffer.Enqueue(s);
            }

            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = buffer.Dequeue();
            }
        }
示例#3
0
 public void GetSamplesAsync(short[] samples)
 {
     _soundProvider.GetSamplesAsync(samples);
     PushThroughSamples(samples, samples.Length);
 }