/// <summary> /// Allow the device to react to the completion of a frame /// </summary> public void OnFrameCompleted() { if (LastSampleTact < _frameBegins + _frameTacts) { // --- Expand the samples till the end of the frame CreateSamples(_frameBegins + _frameTacts); } if (HostVm.Cpu.Tacts > _frameBegins + _frameTacts) { // --- Sign overflow tacts Overflow = (int)(HostVm.Cpu.Tacts - _frameBegins - _frameTacts); } _beeperProvider?.AddSoundFrame(AudioSamples); _frameBegins += _frameTacts; }
/// <summary> /// Allow the device to react to the completion of a frame /// </summary> public void OnFrameCompleted() { if (LastPulseTact <= _frameTacts - 1) { // --- We have to store the last pulse information Pulses.Add(new EarBitPulse { EarBit = LastEarBit, Lenght = _frameTacts - LastPulseTact }); } // --- Create the array for the samples var firstSampleOffset = _frameBegins % _tactsPerSample == 0 ? 0 : _tactsPerSample - (_frameBegins + _tactsPerSample) % _tactsPerSample; var samplesInFrame = (_frameTacts - firstSampleOffset - 1) / _tactsPerSample + 1; var samples = new float[samplesInFrame]; // --- Convert pulses to samples var sampleIndex = 0; var currentEnd = _frameBegins; foreach (var pulse in Pulses) { var firstSample = currentEnd % _tactsPerSample == 0 ? currentEnd : currentEnd + _tactsPerSample - currentEnd % _tactsPerSample; for (var i = firstSample; i < currentEnd + pulse.Lenght; i += _tactsPerSample) { samples[sampleIndex++] = pulse.EarBit ? 1.0F : 0.0F; } currentEnd += pulse.Lenght; } _beeperProvider?.AddSoundFrame(samples); _frameBegins += _frameTacts; }