ggwave : big refactoring / renaming

This commit is contained in:
Georgi Gerganov
2022-06-05 11:05:34 +03:00
parent 05f1b4750b
commit 7c5b614c16
26 changed files with 1097 additions and 834 deletions

View File

@@ -45,41 +45,39 @@ void mainUpdate(void *) {
extern "C" {
EMSCRIPTEN_KEEPALIVE
int sendData(int textLength, const char * text, int protocolId, int volume) {
g_ggWave->init(textLength, text, g_ggWave->getTxProtocol(protocolId), volume);
g_ggWave->init(textLength, text, GGWave::TxProtocolId(protocolId), volume);
return 0;
}
EMSCRIPTEN_KEEPALIVE
int getText(char * text) {
std::copy(g_ggWave->getRxData().begin(), g_ggWave->getRxData().end(), text);
std::copy(g_ggWave->rxData().begin(), g_ggWave->rxData().end(), text);
return 0;
}
EMSCRIPTEN_KEEPALIVE
float getSampleRate() { return g_ggWave->getSampleRateInp(); }
float sampleRate() { return g_ggWave->sampleRateInp(); }
EMSCRIPTEN_KEEPALIVE
int getFramesToRecord() { return g_ggWave->getFramesToRecord(); }
int framesToRecord() { return g_ggWave->rxFramesToRecord(); }
EMSCRIPTEN_KEEPALIVE
int getFramesLeftToRecord() { return g_ggWave->getFramesLeftToRecord(); }
int framesLeftToRecord() { return g_ggWave->rxFramesLeftToRecord(); }
EMSCRIPTEN_KEEPALIVE
int getFramesToAnalyze() { return g_ggWave->getFramesToAnalyze(); }
int framesToAnalyze() { return g_ggWave->rxFramesToAnalyze(); }
EMSCRIPTEN_KEEPALIVE
int getFramesLeftToAnalyze() { return g_ggWave->getFramesLeftToAnalyze(); }
int framesLeftToAnalyze() { return g_ggWave->rxFramesLeftToAnalyze(); }
EMSCRIPTEN_KEEPALIVE
int hasDeviceOutput() { return g_devIdOut; }
int hasDeviceOutput() { return g_devIdOut; }
EMSCRIPTEN_KEEPALIVE
int hasDeviceCapture() { return g_devIdInp; }
int hasDeviceCapture() { return g_devIdInp; }
EMSCRIPTEN_KEEPALIVE
int doInit() {
return g_doInit();
}
int doInit() { return g_doInit(); }
}
void GGWave_setDefaultCaptureDeviceName(std::string name) {
@@ -253,16 +251,16 @@ bool GGWave_mainLoop() {
return false;
}
if (g_ggWave->hasTxData() == false) {
if (g_ggWave->txHasData() == false) {
SDL_PauseAudioDevice(g_devIdOut, SDL_FALSE);
static auto tLastNoData = std::chrono::high_resolution_clock::now();
auto tNow = std::chrono::high_resolution_clock::now();
if ((int) SDL_GetQueuedAudioSize(g_devIdOut) < g_ggWave->getSamplesPerFrame()*g_ggWave->getSampleSizeBytesOut()) {
if ((int) SDL_GetQueuedAudioSize(g_devIdOut) < g_ggWave->samplesPerFrame()*g_ggWave->sampleSizeOut()) {
SDL_PauseAudioDevice(g_devIdInp, SDL_FALSE);
const int nHave = (int) SDL_GetQueuedAudioSize(g_devIdInp);
const int nNeed = g_ggWave->getSamplesPerFrame()*g_ggWave->getSampleSizeBytesInp();
const int nNeed = g_ggWave->samplesPerFrame()*g_ggWave->sampleSizeInp();
if (::getTime_ms(tLastNoData, tNow) > 500.0f && nHave >= nNeed) {
static std::vector<uint8_t> dataInp(nNeed);
SDL_DequeueAudio(g_devIdInp, dataInp.data(), nNeed);
@@ -271,7 +269,7 @@ bool GGWave_mainLoop() {
fprintf(stderr, "Warning: failed to decode input data!\n");
} else {
GGWave::TxRxData rxData;
int n = g_ggWave->takeRxData(rxData);
int n = g_ggWave->rxTakeData(rxData);
if (n > 0) {
std::time_t timestamp = std::time(nullptr);
std::string tstr = std::asctime(std::localtime(&timestamp));
@@ -335,7 +333,8 @@ int main(int argc, char** argv) {
printf("\n");
#endif
const GGWave::TxProtocols protocols = {
auto & protocols = GGWave::Protocols::rx();
protocols = {
{ "[R2T2] Normal", 64, 9, 1, 2, true, },
{ "[R2T2] Fast", 64, 6, 1, 2, true, },
{ "[R2T2] Fastest", 64, 3, 1, 2, true, },
@@ -356,8 +355,6 @@ int main(int argc, char** argv) {
return false;
}
g_ggWave->setRxProtocols(protocols);
isInitialized = true;
printf("Listening for payload with length = %d bytes ..\n", payloadLength);