1
0
mirror of https://github.com/JvanKatwijk/dab-cmdline synced 2025-10-06 08:02:52 +02:00
Files
SDR-DAB_dab-cmdline/library/dab-api.cpp

125 lines
3.6 KiB
C++
Raw Permalink Normal View History

2017-05-19 15:20:19 +02:00
#
/*
2025-06-22 19:12:39 +02:00
* Copyright (C) 2016, 2025
2017-05-19 15:20:19 +02:00
* Jan van Katwijk (J.vanKatwijk@gmail.com)
2017-08-21 20:22:52 +02:00
* Lazy Chair Computing
2017-05-19 15:20:19 +02:00
*
* This file is the C/C++implementation of the DAB-API
*
* DAB-library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DAB-library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DAB-library, if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//
#include "dab-api.h"
#include "ringbuffer.h"
2018-08-12 12:25:20 +02:00
#include "dab-processor.h"
2017-05-19 15:20:19 +02:00
void *dabInit (deviceHandler *theDevice,
2021-04-22 14:55:13 +02:00
API_struct *theParameters,
2018-08-12 12:25:20 +02:00
RingBuffer<std::complex<float>> *spectrumBuffer,
RingBuffer<std::complex<float>> *iqBuffer,
2017-05-19 15:20:19 +02:00
void *userData) {
2018-08-12 12:25:20 +02:00
dabProcessor *theClass = new dabProcessor (theDevice,
2021-04-22 14:55:13 +02:00
theParameters,
2018-08-12 12:25:20 +02:00
spectrumBuffer,
iqBuffer,
userData);
2017-05-19 15:20:19 +02:00
return (void *)theClass;
}
void dabExit (void *Handle) {
2018-08-12 12:25:20 +02:00
delete (dabProcessor *)Handle;
2017-05-19 15:20:19 +02:00
}
2017-05-28 12:06:43 +02:00
void dabStartProcessing (void *Handle) {
2018-08-12 12:25:20 +02:00
((dabProcessor *)Handle) -> start ();
2017-05-19 15:20:19 +02:00
}
2018-08-12 12:25:20 +02:00
void dabReset (void *Handle) {
((dabProcessor *)Handle) -> reset ();
2017-05-19 15:20:19 +02:00
}
2018-08-12 12:25:20 +02:00
void dabStop (void *Handle) {
((dabProcessor *)Handle) -> stop ();
2017-05-19 15:20:19 +02:00
}
2018-08-12 12:25:20 +02:00
void dabReset_msc (void *Handle) {
((dabProcessor *)Handle) -> reset_msc ();
}
2025-06-22 19:12:39 +02:00
bool is_audioService (void *Handle, const std::string &name) {
return ((dabProcessor *)Handle) -> serviceType (name) ==
2018-08-12 12:25:20 +02:00
AUDIO_SERVICE;
}
2025-06-22 19:12:39 +02:00
bool is_dataService (void *Handle, const std::string &name) {
return ((dabProcessor *)Handle) -> serviceType (name) ==
2018-08-12 12:25:20 +02:00
PACKET_SERVICE;
}
2025-06-22 19:12:39 +02:00
void dataforAudioService (void *Handle, const std::string &name,
audiodata &d, int o) {
2018-08-12 12:25:20 +02:00
((dabProcessor *)Handle) -> dataforAudioService (name, d, o);
}
2025-06-22 19:12:39 +02:00
void dataforDataService (void *Handle, const std::string &name,
packetdata &pd, int o) {
2018-08-12 12:25:20 +02:00
((dabProcessor *)Handle) -> dataforDataService (name, pd, o);
}
2025-06-22 19:12:39 +02:00
void set_audioChannel (void *Handle, audiodata &ad) {
2018-08-12 12:25:20 +02:00
((dabProcessor *)Handle) -> set_audioChannel (ad);
2017-05-19 15:20:19 +02:00
}
2018-08-12 12:25:20 +02:00
2025-06-22 19:12:39 +02:00
void set_dataChannel (void *Handle, packetdata &pd) {
2018-08-12 12:25:20 +02:00
((dabProcessor *)Handle) -> set_dataChannel (pd);
}
2025-06-22 19:12:39 +02:00
int32_t dab_getSId (void *Handle, const std::string &c_s) {
return ((dabProcessor *)Handle) -> get_SId (c_s);
}
//
std::string dab_getserviceName (void *Handle, uint32_t SId) {
return ((dabProcessor *)Handle) -> get_serviceName (SId);
2017-05-19 15:20:19 +02:00
}
2025-06-22 19:12:39 +02:00
std::string get_ensembleName (void *Handle) {
return ((dabProcessor *)Handle) -> get_ensembleName ();
2017-05-19 15:20:19 +02:00
}
2021-04-16 20:27:00 +01:00
#ifdef _MSC_VER
#include <windows.h>
extern "C" {
2025-06-22 19:12:39 +02:00
void usleep(int usec) {
2021-04-16 20:27:00 +01:00
HANDLE timer;
LARGE_INTEGER ft;
ft.QuadPart = -(10*usec); // Convert to 100 nanosecond interval, negative value indicates relative time
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
}
2025-06-22 19:12:39 +02:00
void sleep(int seconds) {
Sleep (seconds * 1000);
2021-04-16 20:27:00 +01:00
}
}
2025-06-22 19:12:39 +02:00
2021-04-16 20:27:00 +01:00
#endif
2025-06-22 19:12:39 +02:00