#include "cgaborator.h"
#include <cstdio>

#define BLOCK_SIZE 8192

int main(int argc, char *argv[]) {
	if (argc < 2) {
		return 1;
	}

    auto fp = fopen(argv[1], "r");

    if (fp == nullptr){
        return 1;
    }

    auto ptr = gaborator_initialize(1024 * 64, 16000, 85, 110, 440, 7040, 128);

    float audioData[BLOCK_SIZE];


	size_t return_size, slice_size;
    while (true){
        auto read = fread(&audioData[0], sizeof(audioData[0]), sizeof(audioData) / sizeof(audioData[0]), fp);
        gaborator_transform(ptr, &audioData[0], sizeof(audioData) / sizeof(audioData[0]), &return_size, &slice_size);

        if (read < sizeof(audioData) / sizeof(audioData[0])) { //EOF
            break;
        }
    }

    gaborator_transform(ptr, nullptr, 0, &return_size, &slice_size);

    fclose(fp);

    gaborator_release(ptr);
    return 0;
}