public void GetSamples(short[] samples) { short[] sampin; int numsamp; input.GetSamples(out sampin, out numsamp); buffer.enqueue_samples(sampin, numsamp); buffer.output_samples(samples, samples.Length / 2); }
void ISyncSoundProvider.GetSamples(out short[] samples, out int nsamp) { short[] sampin; int nsampin; syncinput.GetSamples(out sampin, out nsampin); short[] ret = new short[nsampin * 2]; PushThroughSamples(sampin, ret, nsampin * 2); samples = ret; nsamp = nsampin; }
public void GetSamples(out short[] samples, out int nsamp) { if (input != null) { short[] sampin; int nsampin; input.GetSamples(out sampin, out nsampin); EnqueueSamples(sampin, nsampin); } Flush(); nsamp = outbuf2pos / 2; samples = outbuf2; outbuf2pos = 0; }
public void DumpAV(IVideoProvider v, ISyncSoundProvider s, out short[] samples, out int samplesprovided) { VerifyParams(); s.GetSamples(out samples, out samplesprovided); exaudio_num += samplesprovided * (long)fpsnum; // todo: scan for duplicate frames (ie, video content exactly matches previous frame) and for them, skip the threshone step // this is a good idea, but expensive on time. is it worth it? if (exaudio_num >= threshone) { // add frame once w.AddFrame(v); exaudio_num -= threshtotal; } else { Console.WriteLine("Dropped Frame!"); } while (exaudio_num >= threshmore) { // add frame again! w.AddFrame(v); exaudio_num -= threshtotal; Console.WriteLine("Dupped Frame!"); } // a bit of hackey due to the fact that this api can't read a // usable buffer length separately from the actual length of the buffer if (samples.Length == samplesprovided * channels) { w.AddSamples(samples); } else { if (_samples.Length != samplesprovided * channels) { _samples = new short[samplesprovided * channels]; } Buffer.BlockCopy(samples, 0, _samples, 0, samplesprovided * channels * sizeof(short)); w.AddSamples(_samples); } }
public void DumpAV(IVideoProvider v, ISyncSoundProvider s, out short[] samples, out int samplesprovided) { VerifyParams(); s.GetSamples(out samples, out samplesprovided); exaudio_num += samplesprovided * (long)fpsnum; // todo: scan for duplicate frames (ie, video content exactly matches previous frame) and for them, skip the threshone step // this is a good idea, but expensive on time. is it worth it? if (exaudio_num >= threshone) { // add frame once w.AddFrame(v); exaudio_num -= threshtotal; } else { Console.WriteLine("Dropped Frame!"); } while (exaudio_num >= threshmore) { // add frame again! w.AddFrame(v); exaudio_num -= threshtotal; Console.WriteLine("Dupped Frame!"); } // a bit of hackey due to the fact that this api can't read a // usable buffer length separately from the actual length of the buffer if (samples.Length == samplesprovided * channels) { w.AddSamples(samples); } else { if (_samples.Length != samplesprovided * channels) _samples = new short[samplesprovided * channels]; Buffer.BlockCopy(samples, 0, _samples, 0, samplesprovided * channels * sizeof(short)); w.AddSamples(_samples); } }
public void UpdateSound(float atten) { if (!Global.Config.SoundEnabled || !IsStarted || _disposed) { if (_asyncSoundProvider != null) { _asyncSoundProvider.DiscardSamples(); } if (_syncSoundProvider != null) { _syncSoundProvider.DiscardSamples(); } if (_outputProvider != null) { _outputProvider.DiscardSamples(); } return; } if (atten < 0) { atten = 0; } if (atten > 1) { atten = 1; } _soundOutput.ApplyVolumeSettings(atten); short[] samples; int samplesNeeded = _soundOutput.CalculateSamplesNeeded(); int samplesProvided; if (atten == 0) { samples = new short[samplesNeeded * ChannelCount]; samplesProvided = samplesNeeded; if (_asyncSoundProvider != null) { _asyncSoundProvider.DiscardSamples(); } if (_syncSoundProvider != null) { _syncSoundProvider.DiscardSamples(); } if (_outputProvider != null) { _outputProvider.DiscardSamples(); } } else if (_syncSoundProvider != null) { if (Global.Config.SoundThrottle) { _syncSoundProvider.GetSamples(out samples, out samplesProvided); while (samplesNeeded < samplesProvided && !Global.DisableSecondaryThrottling) { Thread.Sleep((samplesProvided - samplesNeeded) / (SampleRate / 1000)); // Let the audio clock control sleep time samplesNeeded = _soundOutput.CalculateSamplesNeeded(); } } else { if (Global.DisableSecondaryThrottling) // This indicates rewind or fast-forward { _outputProvider.OnVolatility(); } _outputProvider.GetSamples(samplesNeeded, out samples, out samplesProvided); } } else if (_asyncSoundProvider != null) { samples = new short[samplesNeeded * ChannelCount]; _semiSync.GetSamples(samples); samplesProvided = samplesNeeded; } else { return; } _soundOutput.WriteSamples(samples, samplesProvided); }
public void UpdateSound() { if (Global.Config.SoundEnabled == false || disposed) { if (asyncsoundProvider != null) { asyncsoundProvider.DiscardSamples(); } if (syncsoundProvider != null) { syncsoundProvider.DiscardSamples(); } return; } int samplesNeeded = SNDDXGetAudioSpace() * 2; short[] samples; int samplesProvided; if (Muted) { if (samplesNeeded == 0) { return; } samples = new short[samplesNeeded]; samplesProvided = samplesNeeded; if (asyncsoundProvider != null) { asyncsoundProvider.DiscardSamples(); } if (syncsoundProvider != null) { syncsoundProvider.DiscardSamples(); } } else if (syncsoundProvider != null) { if (DSoundBuffer == null) { return; // can cause SNDDXGetAudioSpace() = 0 } int nsampgot; syncsoundProvider.GetSamples(out samples, out nsampgot); samplesProvided = 2 * nsampgot; if (!Global.ForceNoThrottle) { while (samplesNeeded < samplesProvided) { System.Threading.Thread.Sleep((samplesProvided - samplesNeeded) / 88); // let audio clock control sleep time samplesNeeded = SNDDXGetAudioSpace() * 2; } } } else if (asyncsoundProvider != null) { if (samplesNeeded == 0) { return; } samples = new short[samplesNeeded]; //if (asyncsoundProvider != null && Muted == false) //{ semisync.BaseSoundProvider = asyncsoundProvider; semisync.GetSamples(samples); //} //else asyncsoundProvider.DiscardSamples(); samplesProvided = samplesNeeded; } else { return; } int cursor = soundoffset; for (int i = 0; i < samplesProvided; i++) { short s = samples[i]; SoundBuffer[cursor++] = (byte)(s & 0xFF); SoundBuffer[cursor++] = (byte)(s >> 8); if (cursor >= SoundBuffer.Length) { cursor = 0; } } DSoundBuffer.Write(SoundBuffer, 0, LockFlags.EntireBuffer); soundoffset += samplesProvided * 2; soundoffset %= BufferSize; }