int timecoder_init(struct timecoder_t *tc, const char *def_name, unsigned int sample_rate) { /* A definition contains a lookup table which can be shared * across multiple timecoders */ tc->def = find_definition(def_name); if (tc->def == NULL) { fprintf(stderr, "Timecode definition '%s' is not known.\n", def_name); return -1; } if (build_lookup(tc->def) == -1) return -1; tc->dt = 1.0 / sample_rate; tc->zero_alpha = tc->dt / (ZERO_RC + tc->dt); tc->forwards = 1; init_channel(&tc->primary); init_channel(&tc->secondary); pitch_init(&tc->pitch, tc->dt); tc->ref_level = 32768.0; tc->bitstream = 0; tc->timecode = 0; tc->valid_counter = 0; tc->timecode_ticker = 0; tc->mon = NULL; return 0; }
struct timecode_def* timecoder_find_definition(const char *name) { struct timecode_def *def, *end; def = &timecodes[0]; end = def + ARRAY_SIZE(timecodes); for (;;) { if (!strcmp(def->name, name)) break; def++; if (def == end) return NULL; } if (build_lookup(def) == -1) return NULL; return def; }