/* * Transform object test * * Compile with: * gcc -Wall -o transformtest transformtest.c transform.c -lsndfile -lfftw3f */ #include #include #include #include #include "transform.h" #define BLOCKSIZE 2048 static void transformed(fftwf_complex *freqdata, void *data) { } int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: infile outfile\n"); return 1; } SF_INFO info; info.format = 0; SNDFILE *infile = sf_open(argv[1], SFM_READ, &info); SNDFILE *outfile = sf_open(argv[2], SFM_WRITE, &info); int16_t *buffer = calloc(BLOCKSIZE, sizeof(*buffer)); Transform *transform = transform_new(BLOCKSIZE, transformed, NULL); while (1) { int read = sf_read_short(infile, buffer, BLOCKSIZE); if (read < BLOCKSIZE) { memset(buffer + read, 0, (BLOCKSIZE - read) * sizeof(*buffer)); } transform_push(transform, buffer); int16_t *processed; while ((processed = transform_pop(transform)) != NULL) { sf_write_short(outfile, processed, BLOCKSIZE / 2); } if (read < BLOCKSIZE) { // losing the last half block break; } } transform_destroy(transform); sf_close(outfile); sf_close(infile); return 0; }