<commit_before>#include "soundeffect.h"

#include <AL/al.h>
#include <AL/alc.h>

#include <Tempest/SoundDevice>
#include <Tempest/Except>
#include <Tempest/Log>

#include <thread>
#include <atomic>

using namespace Tempest;

struct SoundEffect::Impl {
  enum {
    NUM_BUF = 3,
    BUFSZ   = 4096
    };

  Impl()=default;

  Impl(SoundDevice &dev, const Sound &src)
    :dev(&dev), data(src.data) {
    if(data==nullptr)
      return;
    ALCcontext* ctx = context();
    alGenSourcesCt(ctx, 1, &source);
    alSourceBufferCt(ctx, source, reinterpret_cast<ALbuffer*>(data->buffer));
    }

  Impl(SoundDevice &dev, std::unique_ptr<SoundProducer> &&src)
    :dev(&dev), data(nullptr), producer(std::move(src)) {
    ALCcontext* ctx = context();
    alGenSourcesCt(ctx, 1, &source);

    threadFlag.store(true);
    producerThread = std::thread([this](){
      soundThreadFn();
      });
    }

  ~Impl(){
    if(source==0)
      return;

    ALCcontext* ctx = context();
    if(threadFlag.load()) {
      threadFlag.store(false);
      producerThread.join();
      producer.reset();
      } else {
      alDeleteSourcesCt(ctx, 1, &source);
      }
    }

  void soundThreadFn() {
    SoundProducer& src  = *producer;
    ALsizei        freq = src.frequency;
    ALenum         frm  = src.channels==2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
    auto           ctx  = context();
    ALbuffer*      qBuffer[NUM_BUF]={};
    int16_t        bufData[BUFSZ*2]={};
    ALint          zero=0;

    for(size_t i=0;i<NUM_BUF;++i){<commit_msg>noexcept sound thread<commit_after>#include "soundeffect.h"

#include <AL/al.h>
#include <AL/alc.h>

#include <Tempest/SoundDevice>
#include <Tempest/Except>
#include <Tempest/Log>

#include <thread>
#include <atomic>

using namespace Tempest;

struct SoundEffect::Impl {
  enum {
    NUM_BUF = 3,
    BUFSZ   = 4096
    };

  Impl()=default;

  Impl(SoundDevice &dev, const Sound &src)
    :dev(&dev), data(src.data) {
    if(data==nullptr)
      return;
    ALCcontext* ctx = context();
    alGenSourcesCt(ctx, 1, &source);
    alSourceBufferCt(ctx, source, reinterpret_cast<ALbuffer*>(data->buffer));
    }

  Impl(SoundDevice &dev, std::unique_ptr<SoundProducer> &&src)
    :dev(&dev), data(nullptr), producer(std::move(src)) {
    ALCcontext* ctx = context();
    alGenSourcesCt(ctx, 1, &source);

    threadFlag.store(true);
    producerThread = std::thread([this]() noexcept {
      soundThreadFn();
      });
    }

  ~Impl(){
    if(source==0)
      return;

    ALCcontext* ctx = context();
    if(threadFlag.load()) {
      threadFlag.store(false);
      producerThread.join();
      producer.reset();
      } else {
      alDeleteSourcesCt(ctx, 1, &source);
      }
    }

  void soundThreadFn() {
    SoundProducer& src  = *producer;
    ALsizei        freq = src.frequency;
    ALenum         frm  = src.channels==2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
    auto           ctx  = context();
    ALbuffer*      qBuffer[NUM_BUF]={};
    int16_t        bufData[BUFSZ*2]={};
    ALint          zero=0;

    for(size_t i=0;i<NUM_BUF;++i){
{'fraction_non_alphanumeric': 0.15314730694354314, 'fraction_numerical': 0.012329656067488644, 'mean_word_length': 2.967824967824968, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '747018', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1084, 'n_words': 202}