#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
#ifdef _WIN32
#include <fcntl.h> 
#endif
 
 
int main(int argc, char **argv) {
        FILE* file;
        double length = 2; 
        double fps = 25;
        double sample_rate = 48000;
        char *filename;
 
        int vframe_cnt;
        int vframe_last;
 
        int total = 0;
 
 
        
        const char timezone[6] = "+0100";
 
 
        
        if (argc > 1) {
                filename = argv[1];
                if (argc > 2) {
                        sample_rate = atof(argv[2]);
                }
                if (argc > 3) {
                        fps = atof(argv[3]);
                }
                if (argc > 4) {
                        length = atof(argv[4]);
                }
        } else {
                printf("ltc-encoder - test/example application to encode LTC to a file\n\n");
                printf("Usage: ltc-encoder <filename> [sample rate [frame rate [duration in s]]]\n\n");
                printf("default-values:\n");
                printf(" sample rate: 48000.0 [SPS], frame rate: 25.0 [fps], duration: 2.0 [sec]\n");
                printf("Report bugs to Robin Gareus <robin@gareus.org>\n");
                return 1;
        }
 
#ifdef _WIN32
        
        
        _set_fmode(_O_BINARY);
#endif
 
        
        file = fopen(filename, "wb");
        if (!file) {
                fprintf(stderr, "Error: can not open file '%s' for writing.\n", filename);
                return 1;
        }
 
        
 
#ifdef USE_LOCAL_BUFFER
        if (!buf) {
                return -1;
        }
#endif
 
        
 
        printf("sample rate: %.2f\n", sample_rate);
        printf("frames/sec: %.2f\n", fps);
        printf("secs to write: %.2f\n", length);
        printf("sample format: 8bit unsigned mono\n");
 
        vframe_cnt = 0;
        vframe_last = length * fps;
 
        while (vframe_cnt++ < vframe_last) {
#if 1 
                int byte_cnt;
                for (byte_cnt = 0 ; byte_cnt < 10 ; byte_cnt++) {
 
#ifdef USE_LOCAL_BUFFER
#else
                        int len;
#endif
                        if (len > 0) {
                                total+=len;
                        }
                }
#else 
 
#ifdef USE_LOCAL_BUFFER
#else
                int len;
#endif
 
                if (len > 0) {
                        total+=len;
                }
#endif
 
        }
        fclose(file);
 
        printf("Done: wrote %d samples to '%s'\n", total, filename);
 
#ifdef USE_LOCAL_BUFFER
        free(buf);
#endif
 
        return 0;
}