summaryrefslogtreecommitdiff
path: root/kon/konmic.h
blob: c3eaab59895634d297848c9a3d273eff62322148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* SPDX-License-Identifier: MIT */
/*
 * konmic.h
 *
 * Copyright (c) 2026 KonAki
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef KONMIC_H
#define KONMIC_H

#include <stdint.h>

#include "konassets.h"

#ifdef __cplusplus
extern "C" {
#endif

/*** definition ***/

typedef struct kon_mic kon_mic_t;

/* opens the default capture device in mono. keeps the last historySeconds of sound around.
   returns NULL when there is no mic or the system says no */
kon_mic_t *kon_micCreate(uint32_t sampleRate, float historySeconds);

/* no device. you push samples yourself with kon_micFeed, for tests or recorded input */
kon_mic_t *kon_micCreateOffline(uint32_t sampleRate, float historySeconds);
void kon_micDestroy(kon_mic_t *mic);

uint32_t kon_micRate(const kon_mic_t *mic);

/* mono float samples. the device calls this, offline you call it */
void kon_micFeed(kon_mic_t *mic, const float *samples, uint32_t count);

/* multiplies what comes in, 1 by default */
void kon_micSetGain(kon_mic_t *mic, float gain);

/* a muted mic hears silence, level and talking drop to zero */
void kon_micMute(kon_mic_t *mic, int muted);

/* talking is true while the sound is over threshold, and for holdSeconds after it drops.
   defaults are 0.02 and 0.25 */
void kon_micSetTalking(kon_mic_t *mic, float threshold, float holdSeconds);

/* how loud it is right now, 0 to 1. rises fast and falls slowly so it works for a mouth */
float kon_micLevel(kon_mic_t *mic);
int kon_micTalking(kon_mic_t *mic);

/* the last few seconds as a sound you can hand to konaudio. NULL when nothing was heard yet.
   it is a single allocation, free() it when you are done */
kon_sound_t *kon_micSnapshot(kon_mic_t *mic, float seconds);


#ifdef __cplusplus
}
#endif
#endif