~andreafeletto/dsp-dtmf

fcb84c353a31dd3bee80f04950449951ce541cbb — Andrea Feletto a month ago 5e2cf61 main
added key_exists function to generator
2 files changed, 22 insertions(+), 0 deletions(-)

M generator.c
M generator.h
M generator.c => generator.c +15 -0
@@ 28,6 28,21 @@ static struct dtmf_gen_key dtmf_gen_keys[] = {
};

int
dtmf_gen_key_exist(char key) {
	char key_norm;
	struct dtmf_gen_key *k;

	key_norm = isalpha(key) ? tolower(key) : key;

	for (k = dtmf_gen_keys; k->key != '\0'; k++) {
		if (k->key == key_norm) {
			return 1;
		}
	}
	return 0;
}

int
dtmf_gen_get_freqs(double *fst, double *snd, char key) {
	assert(fst != NULL && snd != NULL);


M generator.h => generator.h +7 -0
@@ 12,6 12,13 @@ struct dtmf_gen_key {
};

/*
 * Checks if `key` is present in `dtmf_gen_keys`
 *
 * Returns 1 if found, 0 otherwise.
 */
int dtmf_gen_key_exist(char key);

/*
 * Retrieves the two frequencies assigned to the given `key`.
 *
 * The search is case-insensitive for letters.