/* 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 #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