<commit_before>#include "aquila/source/generator/SineGenerator.h"
#include "aquila/source/generator/SquareGenerator.h"
#include "aquila/source/generator/PinkNoiseGenerator.h"
#include "aquila/source/generator/WhiteNoiseGenerator.h"
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <algorithm>
#include <iostream>


void convertSourceToBuffer(const Aquila::SignalSource& source,
                           sf::SoundBuffer& buffer)
{
    sf::Int16* samples = new sf::Int16[source.getSamplesCount()];
    std::copy(source.begin(), source.end(), samples);
    buffer.LoadFromSamples(samples,
                           source.getSamplesCount(),
                           1,
                           static_cast<unsigned int>(source.getSampleFrequency()));
    delete [] samples;
}


void handleGeneratorOptions(Aquila::Generator* generator)
{
    Aquila::FrequencyType frequency, maxFrequency = generator->getSampleFrequency() / 2;
    std::cout << "\nSignal frequency in Hz: \n"
                 "Enter a number (0-" << maxFrequency << "): ";
    std::cin >> frequency;
    if (frequency < 0 || frequency > maxFrequency)
    {
        frequency = 1000;
    }
    generator->setFrequency(frequency);
}


Aquila::Generator* createGenerator(unsigned int whichGenerator,
                                   Aquila::FrequencyType sampleFrequency)
{
    Aquila::Generator* generator;
    switch (whichGenerator)
    {
    case 1:
        generator = new Aquila::SineGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    case 2:
        generator = new Aquila::SquareGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    case 3:
        generator = new Aquila::PinkNoiseGenerator(sampleFrequency);
        break;
    case 4:
        generator = new Aquila::WhiteNoiseGenerator(sampleFrequency);
        break;
    default:
        generator = new Aquila::SineGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    }
    generator->setAmplitude(8192);
    return generator;
}


int main(int argc, char** argv)
{
    std::cout << "Choose which kind of signal to play: \n"
                 "\t 1: Sine wave \n"
                 "\t 2: Square wave \n"
                 "\t 3: Pink noise \n"
                 "\t 4: White noise \n"
                 "Enter a number (1-4): ";
    unsigned int whichGenerator = 1;
    std::cin >> whichGenerator;
    const Aquila::FrequencyType SAMPLE_FREQUENCY = 44100;
    Aquila::Generator* generator = createGenerator(whichGenerator, SAMPLE_FREQUENCY);

    generator->generate(5 * SAMPLE_FREQUENCY);
    sf::SoundBuffer buffer;
    convertSourceToBuffer(*generator, buffer);
    sf::Sound sound;
    sound.SetBuffer(buffer);
    sound.Play();
    std::cout << "Playing..." << std::endl;
    while (sound.GetStatus() == sf::Sound::Playing)
    {
        std::cout << ".";
        sf::Sleep(0.1f);
    }
    std::cout << "\nFinished." << std::endl;

    delete generator;

    return 0;
}
<commit_msg>Refactored the sfml_generator example to use the new wrapper class.<commit_after>#include "aquila/source/generator/SineGenerator.h"
#include "aquila/source/generator/SquareGenerator.h"
#include "aquila/source/generator/PinkNoiseGenerator.h"
#include "aquila/source/generator/WhiteNoiseGenerator.h"
#include "aquila/wrappers/SoundBufferAdapter.h"
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <iostream>


void handleGeneratorOptions(Aquila::Generator* generator)
{
    Aquila::FrequencyType frequency, maxFrequency = generator->getSampleFrequency() / 2;
    std::cout << "\nSignal frequency in Hz: \n"
                 "Enter a number (0-" << maxFrequency << "): ";
    std::cin >> frequency;
    if (frequency < 0 || frequency > maxFrequency)
    {
        frequency = 1000;
    }
    generator->setFrequency(frequency);
}


Aquila::Generator* createGenerator(unsigned int whichGenerator,
                                   Aquila::FrequencyType sampleFrequency)
{
    Aquila::Generator* generator;
    switch (whichGenerator)
    {
    case 1:
        generator = new Aquila::SineGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    case 2:
        generator = new Aquila::SquareGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    case 3:
        generator = new Aquila::PinkNoiseGenerator(sampleFrequency);
        break;
    case 4:
        generator = new Aquila::WhiteNoiseGenerator(sampleFrequency);
        break;
    default:
        generator = new Aquila::SineGenerator(sampleFrequency);
        handleGeneratorOptions(generator);
        break;
    }
    generator->setAmplitude(8192);
    return generator;
}


int main(int argc, char** argv)
{
    std::cout << "Choose which kind of signal to play: \n"
                 "\t 1: Sine wave \n"
                 "\t 2: Square wave \n"
                 "\t 3: Pink noise \n"
                 "\t 4: White noise \n"
                 "Enter a number (1-4): ";
    unsigned int whichGenerator = 1;
    std::cin >> whichGenerator;
    const Aquila::FrequencyType SAMPLE_FREQUENCY = 44100;
    Aquila::Generator* generator = createGenerator(whichGenerator, SAMPLE_FREQUENCY);
    generator->generate(5 * SAMPLE_FREQUENCY);

    Aquila::SoundBufferAdapter buffer(*generator);
    sf::Sound sound(buffer);
    sound.Play();
    std::cout << "Playing..." << std::endl;
    while (sound.GetStatus() == sf::Sound::Playing)
    {
        std::cout << ".";
        sf::Sleep(0.1f);
    }
    std::cout << "\nFinished." << std::endl;
    delete generator;

    return 0;
}

{'fraction_non_alphanumeric': 0.11968449931412894, 'fraction_numerical': 0.011488340192043896, 'mean_word_length': 2.45352279455299, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5823276', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1636, 'n_words': 360}