<commit_before>#pragma once

#include <thread>

#include "lib/chrono.hpp"
#include "lib/core/service.hpp"

#include "app/drivers/audio_driver.hpp"
#include "app/services/runtime.hpp"

namespace otto::stubs {
  struct NoProcessAudioDriver final : drivers::IAudioDriver {
    void set_callback(Callback&& cb) override
    {
      callback = std::move(cb);
    }
    void start() override {}
    void stop() override {}
    [[nodiscard]] std::size_t buffer_size() const override
    {
      return 64;
    }
    [[nodiscard]] std::size_t sample_rate() const override
    {
      return 44100;
    }

    Callback callback;
  };

  struct DummyAudioDriver final : drivers::IAudioDriver {
    DummyAudioDriver()
    {
      buffers_.resize(buffer_size() * 4);
    }
    void set_callback(Callback&& cb) override
    {
      callback_ = std::move(cb);
    }
    void start() override
    {
      thread_ = std::jthread([this](std::stop_token stopper) {
        auto input_buf = util::stereo_audio_buffer(
          util::audio_buffer(std::span(buffers_.data() + 0 * buffer_size(), buffer_size()), nullptr),
          util::audio_buffer(std::span(buffers_.data() + 1 * buffer_size(), buffer_size()), nullptr));
        auto output_buf = util::stereo_audio_buffer(
          util::audio_buffer(std::span(buffers_.data() + 2 * buffer_size(), buffer_size()), nullptr),
          util::audio_buffer(std::span(buffers_.data() + 3 * buffer_size(), buffer_size()), nullptr));
        CallbackData cbd = {
          .input = input_buf,
          .output = output_buf,
        };
        while (runtime->should_run() && !stopper.stop_requested()) {
          callback_(cbd);
          std::this_thread::sleep_for(chrono::nanoseconds((1ns / 1s) * buffer_size() / sample_rate()));
        }
      });
    }
    void stop() override
    {
      thread_.request_stop();
      thread_.join();
    }
    [[nodiscard]] std::size_t buffer_size() const override
    {
      return 64;
    }
    [[nodiscard]] std::size_t sample_rate() const override
    {
      return 44100;
    }

  private:
    std::vector<float> buffers_;<commit_msg>Fix DummyAudioDriver::stop<commit_after>#pragma once

#include <thread>

#include "lib/chrono.hpp"
#include "lib/core/service.hpp"

#include "app/drivers/audio_driver.hpp"
#include "app/services/runtime.hpp"

namespace otto::stubs {
  struct NoProcessAudioDriver final : drivers::IAudioDriver {
    void set_callback(Callback&& cb) override
    {
      callback = std::move(cb);
    }
    void start() override {}
    void stop() override {}
    [[nodiscard]] std::size_t buffer_size() const override
    {
      return 64;
    }
    [[nodiscard]] std::size_t sample_rate() const override
    {
      return 44100;
    }

    Callback callback;
  };

  struct DummyAudioDriver final : drivers::IAudioDriver {
    DummyAudioDriver()
    {
      buffers_.resize(buffer_size() * 4);
    }
    void set_callback(Callback&& cb) override
    {
      callback_ = std::move(cb);
    }
    void start() override
    {
      thread_ = std::jthread([this](std::stop_token stopper) {
        auto input_buf = util::stereo_audio_buffer(
          util::audio_buffer(std::span(buffers_.data() + 0 * buffer_size(), buffer_size()), nullptr),
          util::audio_buffer(std::span(buffers_.data() + 1 * buffer_size(), buffer_size()), nullptr));
        auto output_buf = util::stereo_audio_buffer(
          util::audio_buffer(std::span(buffers_.data() + 2 * buffer_size(), buffer_size()), nullptr),
          util::audio_buffer(std::span(buffers_.data() + 3 * buffer_size(), buffer_size()), nullptr));
        CallbackData cbd = {
          .input = input_buf,
          .output = output_buf,
        };
        while (runtime->should_run() && !stopper.stop_requested()) {
          callback_(cbd);
          std::this_thread::sleep_for(chrono::nanoseconds((1ns / 1s) * buffer_size() / sample_rate()));
        }
      });
    }
    void stop() override
    {
      thread_.request_stop();
      if (thread_.joinable()) thread_.join();
    }
    [[nodiscard]] std::size_t buffer_size() const override
    {
      return 64;
    }
    [[nodiscard]] std::size_t sample_rate() const override
    {
      return 44100;
    }

  private:
    std::vector<float> buffers_;
{'fraction_non_alphanumeric': 0.1442646023926812, 'fraction_numerical': 0.009852216748768473, 'mean_word_length': 2.959145775301764, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6572333', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1329, 'n_words': 256}