<commit_before>#include <stdio.h>
#include <stdint.h>

#include <alsa/asoundlib.h>

int main()
{
        snd_pcm_t *pcm;
        snd_pcm_hw_params_t *hw;

        int st;
        unsigned int rrate = 48000;
        unsigned int nc = 1;
        snd_output_t *output;

        uint8_t buff[1024 * 16];
        int i, j;
        snd_pcm_sframes_t frames;

        st = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
        if (st) {
                fprintf(stderr, "Error opening pcm\n");
                return -1;
        }

        st = snd_output_stdio_attach(&output, stdout, 0);
        if (st < 0) {
                printf("Output failed: %s\n", snd_strerror(st));
                return -1;
        }

        st = snd_pcm_set_params(pcm, 
                                SND_PCM_FORMAT_S16, 
                                SND_PCM_ACCESS_RW_INTERLEAVED, 
                                nc, 
                                rrate,
                                1,
                                1000000);      
        if (st < 0) {
                printf("Output failed: %s\n", snd_strerror(st));
                return -1;
        }
        snd_pcm_dump(pcm, output);

        fprintf(stderr, "SND_PCM_FORMAT_U8 : %d\n", SND_PCM_FORMAT_U8);
        fprintf(stderr, "SND_PCM_FORMAT_S16 : %d\n", SND_PCM_FORMAT_S16);
        fprintf(stderr, "SND_PCM_FORMAT_FLOAT : %d\n", SND_PCM_FORMAT_FLOAT);
        fprintf(stderr, "SND_PCM_ACCESS_RW_INTERLEAVED : %d\n", SND_PCM_ACCESS_RW_INTERLEAVED);
        for (i = 0; i < 16; ++i) {
            for (j = 0; j < 1024 * 16; ++j) {
                buff[j] = random() & 0xff;
            }
            frames = snd_pcm_writei(pcm, buff, 1024 * 16); 
            fprintf(stderr, "%u\n", frames);
        }
        snd_output_close(output);
        snd_pcm_close(pcm);

        snd_config_update_free_global();

        return 0;
}<commit_msg>Improve simple example with pcm drain.<commit_after>#include <stdio.h>
#include <stdint.h>

#include <alsa/asoundlib.h>

int play(snd_pcm_t *pcm)
{
        int16_t buff[1024 * 16];
        int i, j;
        snd_pcm_uframes_t frames;

        for (i = 0; i < 4; ++i) {
            for (j = 0; j < 1024 * 16; ++j) {
                buff[j] = random() & 0xff;
            }
            frames = snd_pcm_writei(pcm, buff, 1024 * 16); 
            fprintf(stderr, "%lu\n", frames);
        }

        return 0;
}

int set(snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, 
        unsigned int channels, unsigned int samplerate)
{
        int st;

        st = snd_pcm_set_params(pcm, format, access, channels, samplerate,
                                1, 1000000);      
        if (st < 0) {
                printf("Output failed: %s\n", snd_strerror(st));
                return st;
        }

        return 0;
}

int main()
{
        snd_pcm_t *pcm;
        snd_pcm_hw_params_t *hw;

        int st;
        unsigned int rrate = 48000;
        unsigned int nc = 1;
        snd_output_t *output;

        int i, j;
        snd_pcm_sframes_t frames;

        st = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
        if (st) {
                fprintf(stderr, "Error opening pcm\n");
                return -1;
        }

        st = snd_output_stdio_attach(&output, stdout, 0);
        if (st < 0) {
                printf("Output failed: %s\n", snd_strerror(st));
                return -1;
        }

        set(pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 1, 44100);

        play(pcm);
        snd_pcm_drain(pcm);

        set(pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 1, 8000);

        play(pcm);

        //snd_pcm_dump(pcm, output);

        snd_output_close(output);
        snd_pcm_close(pcm);

        snd_config_update_free_global();

        return 0;
}
{'fraction_non_alphanumeric': 0.11212754835337167, 'fraction_numerical': 0.030318870883429168, 'mean_word_length': 1.5875591615956728, 'pattern_counts': {'":': 0, '<': 17, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4606781', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1275, 'n_words': 273}