<commit_before>//
//
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "liquid.h"

#define DEBUG_FILENAME "fbasc_example.m"

int main() {
    // options
    unsigned int num_channels=16;
    unsigned int samples_per_frame=512;
    unsigned int bytes_per_frame=samples_per_frame + num_channels;

    unsigned int num_frames=2;

    // create fbasc codecs
    fbasc fbasc_encoder = fbasc_create(FBASC_ENCODER, num_channels, samples_per_frame, bytes_per_frame);
    fbasc fbasc_decoder = fbasc_create(FBASC_DECODER, num_channels, samples_per_frame, bytes_per_frame);

    fbasc_print(fbasc_encoder);

    // open debug file
    FILE * fid = fopen(DEBUG_FILENAME,"w");
    fprintf(fid,"%% %s: auto-generated file\n\n", DEBUG_FILENAME);
    fprintf(fid,"clear all\n");
    fprintf(fid,"close all\n");

    float phi=0.0f;
    float dphi=0.03f;
    unsigned int i, j;
    unsigned int n=0;   // output file sample counter
    float x[samples_per_frame], y[samples_per_frame];
    unsigned char framedata[bytes_per_frame];
    for (i=0; i<num_frames; i++) {
        for (j=0; j<samples_per_frame; j++) {
            x[j] = (i==0) ? 0.5f*cosf(2.0f*M_PI*phi) + 0.5f*cosf(2.0f*M_PI*phi*0.57f) : 0.0f;
            //x[j] = (i==0) ? cosf(2.0f*M_PI*phi) : 0.0f;
            phi += dphi;
            x[j] *= 0.5f*kaiser(j,samples_per_frame,10.0f,0);
            //x[j] = randnf()*0.1f;
        }

        fbasc_encode(fbasc_encoder, x, framedata);

        fbasc_decode(fbasc_decoder, framedata, y);

        // write data to file
        for (j=0; j<samples_per_frame; j++) {
            fprintf(fid, "x(%4u) = %8.4e;\n", n+1, x[j]);
            fprintf(fid, "y(%4u) = %8.4e;\n", n+1, y[j]);
            n++;
        }
    }

    // plot results
    fprintf(fid,"\n\n");
    fprintf(fid,"figure;\n");
    fprintf(fid,"subplot(2,1,1), plot(x);\n");
    fprintf(fid,"ylabel('input');\n");
    fprintf(fid,"axis([1 length(x) -0.5 0.5]);\n");
    fprintf(fid,"subplot(2,1,2), plot(y);\n");
    fprintf(fid,"ylabel('encoded/decoded');\n");
    fprintf(fid,"axis([1 length(y) -0.5 0.5]);\n");

    // close debug file
    fclose(fid);
    printf("results wrtten to %s\n", DEBUG_FILENAME);

    // destroy objects
    fbasc_destroy(fbasc_encoder);
    fbasc_destroy(fbasc_decoder);

    printf("done.\n");<commit_msg>fbasc: fixing bit alignment, gain<commit_after>//
//
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "liquid.h"

#define DEBUG_FILENAME "fbasc_example.m"

int main() {
    // options
    unsigned int num_channels=16;
    unsigned int samples_per_frame=512;
    unsigned int bytes_per_frame=samples_per_frame + num_channels;

    unsigned int num_frames=2;

    // create fbasc codecs
    fbasc fbasc_encoder = fbasc_create(FBASC_ENCODER, num_channels, samples_per_frame, bytes_per_frame);
    fbasc fbasc_decoder = fbasc_create(FBASC_DECODER, num_channels, samples_per_frame, bytes_per_frame);

    fbasc_print(fbasc_encoder);

    // open debug file
    FILE * fid = fopen(DEBUG_FILENAME,"w");
    fprintf(fid,"%% %s: auto-generated file\n\n", DEBUG_FILENAME);
    fprintf(fid,"clear all\n");
    fprintf(fid,"close all\n");

    float phi=0.0f;
    float dphi=0.03f;
    unsigned int i, j;
    unsigned int n=0;   // output file sample counter
    float x[samples_per_frame], y[samples_per_frame];
    unsigned char framedata[bytes_per_frame];
    for (i=0; i<num_frames; i++) {
        for (j=0; j<samples_per_frame; j++) {
            x[j] = (i==0) ? 0.5f*cosf(2.0f*M_PI*phi) + 0.5f*cosf(2.0f*M_PI*phi*0.57f) : 0.0f;
            //x[j] = (i==0) ? cosf(2.0f*M_PI*phi) : 0.0f;
            phi += dphi;
            x[j] *= 0.1f*kaiser(j,samples_per_frame,10.0f,0);
            //x[j] = randnf()*0.1f;
        }

        fbasc_encode(fbasc_encoder, x, framedata);

        fbasc_decode(fbasc_decoder, framedata, y);

        // write data to file
        for (j=0; j<samples_per_frame; j++) {
            fprintf(fid, "x(%4u) = %8.4e;\n", n+1, x[j]);
            fprintf(fid, "y(%4u) = %8.4e;\n", n+1, y[j]);
            n++;
        }
    }

    // plot results
    fprintf(fid,"\n\n");
    fprintf(fid,"figure;\n");
    fprintf(fid,"subplot(2,1,1), plot(x);\n");
    fprintf(fid,"ylabel('input');\n");
    //fprintf(fid,"axis([1 length(x) -0.5 0.5]);\n");
    fprintf(fid,"subplot(2,1,2), plot(y);\n");
    fprintf(fid,"ylabel('encoded/decoded');\n");
    //fprintf(fid,"axis([1 length(y) -0.5 0.5]);\n");

    // close debug file
    fclose(fid);
    printf("results wrtten to %s\n", DEBUG_FILENAME);

    // destroy objects
    fbasc_destroy(fbasc_encoder);
    fbasc_destroy(fbasc_decoder);

    printf("done.\n");
{'fraction_non_alphanumeric': 0.17768240343347638, 'fraction_numerical': 0.02832618025751073, 'mean_word_length': 2.9399830938292477, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1039813', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1857, 'n_words': 323}