#include "audio_ring_buffer.h" #include "linear_resampler.h" #include "native_smoke.h" #include "session_rules.h" #include "timing_metrics.h" #include "video_buffer.h" #include int main() { using neslite::SessionState; if (neslite::native_protocol_version() != neslite::kNativeProtocolVersion) return 1; if (!neslite::command_allowed(SessionState::Paused, "run")) return 2; if (neslite::command_allowed(SessionState::Running, "run")) return 3; if (!neslite::command_allowed(SessionState::Running, "pause")) return 4; if (neslite::command_allowed(SessionState::Loading, "reset")) return 5; if (!neslite::command_targets_active_session(9, 9)) return 6; if (neslite::command_targets_active_session(10, 9)) return 7; if (neslite::command_targets_active_session(0, 0)) return 8; if (!neslite::required_host_capabilities_available(1, 1, true)) return 16; if (neslite::required_host_capabilities_available(2, 1, true)) return 17; if (neslite::required_host_capabilities_available(1, 1, false)) return 18; neslite::VideoBuffer video; const unsigned char padded[] = {1, 2, 3, 4, 99, 99, 5, 6, 7, 8, 99, 99}; if (!video.submit(padded, 2, 2, 6, 2, 2)) return 9; neslite::VideoFrame frame; if (!video.latest(&frame) || frame.pitch != 4 || frame.bytes.size() != 8) return 10; if (static_cast(frame.bytes[4]) != 5) return 11; const auto first_sequence = frame.sequence; if (video.submit(nullptr, 2, 2, 4, 2, 2)) return 12; if (!video.latest(&frame) || frame.sequence != first_sequence) return 13; const unsigned char replacement[] = {9, 10, 11, 12}; if (!video.submit(replacement, 2, 1, 4, 2, 2)) return 14; if (!video.latest(&frame) || frame.sequence != first_sequence + 1 || frame.height != 1) return 15; neslite::AudioRingBuffer ring(4); const float audio_in[] = {0.5F, -0.5F, 0.25F, -0.25F, 1.0F, -1.0F}; if (ring.push(audio_in, 3) != 3 || ring.level_frames() != 3) return 19; float audio_out[8]{}; if (ring.pop(audio_out, 2, 0.5F, false) != 2) return 20; if (std::abs(audio_out[0] - 0.25F) > 0.0001F || ring.level_frames() != 1) return 21; if (ring.push(audio_in, 3) != 3 || ring.level_frames() != 4) return 22; float wrapped_out[12]{}; if (ring.pop(wrapped_out, 6, 1.0F, false) != 4 || ring.underrun_frames() != 2) return 23; if (wrapped_out[8] != 0.0F || wrapped_out[10] != 0.0F) return 24; if (ring.push(audio_in, 3) != 3) return 25; float muted_out[6]{}; if (ring.pop(muted_out, 3, 1.0F, true) != 3 || muted_out[0] != 0.0F) return 26; const float overflow_in[12]{}; if (ring.push(overflow_in, 6) != 4 || ring.overflow_frames() != 2) return 27; neslite::LinearStereoResampler resampler; const std::int16_t pcm[] = {0, 0, 16384, -16384, 32767, -32768}; resampler.configure(48000.0, 48000.0); const auto same_rate = resampler.process(pcm, 3); if (same_rate.size() != 6 || std::abs(same_rate[2] - 0.5F) > 0.0001F) return 28; resampler.configure(24000.0, 48000.0); const auto first_resampled = resampler.process(pcm, 2); if (first_resampled.size() != 6 || std::abs(first_resampled[2] - 0.25F) > 0.0001F) return 29; const float previous_resampled_left = first_resampled[4]; const auto second_resampled = resampler.process(pcm + 4, 1); if (second_resampled.size() != 4 || second_resampled[0] <= previous_resampled_left) return 30; resampler.configure(48000.0, 44100.0); std::int16_t long_pcm[960]{}; if (resampler.process(long_pcm, 480).size() / 2U != 441U) return 31; neslite::TimingMetrics metrics; metrics.reset(0); metrics.record_load(500'000'000); metrics.transition(neslite::TimingMode::Normal, 0); metrics.record_frame(1.0, 2'000'000); metrics.transition(neslite::TimingMode::Fast, 1'000'000'000); metrics.record_frame(2.0, 4'000'000); metrics.transition(neslite::TimingMode::Paused, 2'000'000'000); const auto measured = metrics.snapshot(3'000'000'000); if (measured.frames != 2 || std::abs(measured.speed_ratio - 1.5) > 0.0001) return 32; if (std::abs(measured.normal_simulated_seconds - 1.0) > 0.0001 || std::abs(measured.fast_simulated_seconds - 2.0) > 0.0001) return 39; if (std::abs(measured.paused_wall_seconds - 1.0) > 0.0001 || std::abs(measured.load_wall_seconds - 0.5) > 0.0001) return 33; if (std::abs(measured.average_frame_work_ms - 3.0) > 0.0001 || std::abs(measured.maximum_frame_work_ms - 4.0) > 0.0001) return 34; if (std::abs(neslite::scheduler_period_scale(0, 100, false, false) - 1.0) > 0.0001) return 35; if (neslite::scheduler_period_scale(0, 100, true, false) >= 1.0) return 36; if (neslite::scheduler_period_scale(200, 100, true, false) <= 1.0) return 37; if (std::abs(neslite::scheduler_period_scale(100, 100, true, true) - 0.5) > 0.0001) return 38; return 0; }