mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-04-20 13:16:31 +08:00
wip : refactoring
This commit is contained in:
@@ -13,10 +13,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|||||||
include(cmake/BuildTypes.cmake)
|
include(cmake/BuildTypes.cmake)
|
||||||
|
|
||||||
# configure project version
|
# configure project version
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/README-tmpl.md ${CMAKE_SOURCE_DIR}/README.md @ONLY)
|
configure_file(${CMAKE_SOURCE_DIR}/README-tmpl.md ${CMAKE_SOURCE_DIR}/README.md @ONLY)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/bindings/python/setup-tmpl.py ${CMAKE_SOURCE_DIR}/bindings/python/setup.py @ONLY)
|
configure_file(${CMAKE_SOURCE_DIR}/bindings/python/setup-tmpl.py ${CMAKE_SOURCE_DIR}/bindings/python/setup.py @ONLY)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/bindings/javascript/package-tmpl.json ${CMAKE_SOURCE_DIR}/bindings/javascript/package.json @ONLY)
|
configure_file(${CMAKE_SOURCE_DIR}/bindings/javascript/package-tmpl.json ${CMAKE_SOURCE_DIR}/bindings/javascript/package.json @ONLY)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl ${CMAKE_SOURCE_DIR}/bindings/ios/Makefile @ONLY)
|
configure_file(${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl ${CMAKE_SOURCE_DIR}/bindings/ios/Makefile @ONLY)
|
||||||
else()
|
else()
|
||||||
set(GGWAVE_STANDALONE OFF)
|
set(GGWAVE_STANDALONE OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
EMSCRIPTEN_BINDINGS(ggwave) {
|
EMSCRIPTEN_BINDINGS(ggwave) {
|
||||||
emscripten::enum_<ggwave_SampleFormat>("SampleFormat")
|
emscripten::enum_<ggwave_SampleFormat>("SampleFormat")
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_UNDEFINED", GGWAVE_SAMPLE_FORMAT_UNDEFINED)
|
.value("GGWAVE_SAMPLE_FORMAT_UNDEFINED", GGWAVE_SAMPLE_FORMAT_UNDEFINED)
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_U8", GGWAVE_SAMPLE_FORMAT_U8)
|
.value("GGWAVE_SAMPLE_FORMAT_U8", GGWAVE_SAMPLE_FORMAT_U8)
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_I8", GGWAVE_SAMPLE_FORMAT_I8)
|
.value("GGWAVE_SAMPLE_FORMAT_I8", GGWAVE_SAMPLE_FORMAT_I8)
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_U16", GGWAVE_SAMPLE_FORMAT_U16)
|
.value("GGWAVE_SAMPLE_FORMAT_U16", GGWAVE_SAMPLE_FORMAT_U16)
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_I16", GGWAVE_SAMPLE_FORMAT_I16)
|
.value("GGWAVE_SAMPLE_FORMAT_I16", GGWAVE_SAMPLE_FORMAT_I16)
|
||||||
.value("GGWAVE_SAMPLE_FORMAT_F32", GGWAVE_SAMPLE_FORMAT_F32)
|
.value("GGWAVE_SAMPLE_FORMAT_F32", GGWAVE_SAMPLE_FORMAT_F32)
|
||||||
;
|
;
|
||||||
|
|
||||||
emscripten::enum_<ggwave_TxProtocolId>("TxProtocolId")
|
emscripten::enum_<ggwave_TxProtocolId>("TxProtocolId")
|
||||||
@@ -36,15 +36,23 @@ EMSCRIPTEN_BINDINGS(ggwave) {
|
|||||||
.value("GGWAVE_TX_PROTOCOL_CUSTOM_9", GGWAVE_TX_PROTOCOL_CUSTOM_9)
|
.value("GGWAVE_TX_PROTOCOL_CUSTOM_9", GGWAVE_TX_PROTOCOL_CUSTOM_9)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
emscripten::enum_<ggwave_OperatingMode>("OperatingMode")
|
||||||
|
.value("GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX", GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX)
|
||||||
|
.value("GGWAVE_OPERATING_MODE_ONLY_RX", GGWAVE_OPERATING_MODE_ONLY_RX)
|
||||||
|
.value("GGWAVE_OPERATING_MODE_ONLY_TX", GGWAVE_OPERATING_MODE_ONLY_TX)
|
||||||
|
;
|
||||||
|
|
||||||
emscripten::class_<ggwave_Parameters>("Parameters")
|
emscripten::class_<ggwave_Parameters>("Parameters")
|
||||||
.constructor<>()
|
.constructor<>()
|
||||||
.property("payloadLength", &ggwave_Parameters::payloadLength)
|
.property("payloadLength", & ggwave_Parameters::payloadLength)
|
||||||
.property("sampleRateInp", &ggwave_Parameters::sampleRateInp)
|
.property("sampleRateInp", & ggwave_Parameters::sampleRateInp)
|
||||||
.property("sampleRateOut", &ggwave_Parameters::sampleRateOut)
|
.property("sampleRateOut", & ggwave_Parameters::sampleRateOut)
|
||||||
.property("samplesPerFrame", &ggwave_Parameters::samplesPerFrame)
|
.property("sampleRate", & ggwave_Parameters::sampleRate)
|
||||||
.property("soundMarkerThreshold", &ggwave_Parameters::soundMarkerThreshold)
|
.property("samplesPerFrame", & ggwave_Parameters::samplesPerFrame)
|
||||||
.property("sampleFormatInp", &ggwave_Parameters::sampleFormatInp)
|
.property("soundMarkerThreshold", & ggwave_Parameters::soundMarkerThreshold)
|
||||||
.property("sampleFormatOut", &ggwave_Parameters::sampleFormatOut)
|
.property("sampleFormatInp", & ggwave_Parameters::sampleFormatInp)
|
||||||
|
.property("sampleFormatOut", & ggwave_Parameters::sampleFormatOut)
|
||||||
|
.property("operatingMode", & ggwave_Parameters::operatingMode)
|
||||||
;
|
;
|
||||||
|
|
||||||
emscripten::function("getDefaultParameters", &ggwave_getDefaultParameters);
|
emscripten::function("getDefaultParameters", &ggwave_getDefaultParameters);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
2
bindings/python/.gitignore
vendored
2
bindings/python/.gitignore
vendored
@@ -1,7 +1,7 @@
|
|||||||
ggwave.so
|
ggwave.so
|
||||||
README.rst
|
README.rst
|
||||||
ggwave.bycython.cpp
|
ggwave.bycython.cpp
|
||||||
ggwave.cpython-36m-x86_64-linux-gnu.so
|
ggwave.cpython-*-x86_64-linux-gnu.so
|
||||||
ggwave/
|
ggwave/
|
||||||
ggwave.egg-info/
|
ggwave.egg-info/
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
@@ -30,14 +30,21 @@ cdef extern from "ggwave.h" nogil:
|
|||||||
GGWAVE_TX_PROTOCOL_CUSTOM_8,
|
GGWAVE_TX_PROTOCOL_CUSTOM_8,
|
||||||
GGWAVE_TX_PROTOCOL_CUSTOM_9
|
GGWAVE_TX_PROTOCOL_CUSTOM_9
|
||||||
|
|
||||||
|
ctypedef enum ggwave_OperatingMode:
|
||||||
|
GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX,
|
||||||
|
GGWAVE_OPERATING_MODE_ONLY_RX,
|
||||||
|
GGWAVE_OPERATING_MODE_ONLY_TX,
|
||||||
|
|
||||||
ctypedef struct ggwave_Parameters:
|
ctypedef struct ggwave_Parameters:
|
||||||
int payloadLength
|
int payloadLength
|
||||||
float sampleRateInp
|
float sampleRateInp
|
||||||
float sampleRateOut
|
float sampleRateOut
|
||||||
|
float sampleRate
|
||||||
int samplesPerFrame
|
int samplesPerFrame
|
||||||
float soundMarkerThreshold
|
float soundMarkerThreshold
|
||||||
ggwave_SampleFormat sampleFormatInp
|
ggwave_SampleFormat sampleFormatInp
|
||||||
ggwave_SampleFormat sampleFormatOut
|
ggwave_SampleFormat sampleFormatOut
|
||||||
|
ggwave_OperatingMode operatingMode
|
||||||
|
|
||||||
ctypedef int ggwave_Instance
|
ctypedef int ggwave_Instance
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,9 @@ void loop() {
|
|||||||
p.payloadLength = 16;
|
p.payloadLength = 16;
|
||||||
p.operatingMode = GGWAVE_OPERATING_MODE_ONLY_RX;
|
p.operatingMode = GGWAVE_OPERATING_MODE_ONLY_RX;
|
||||||
GGWave instance(p);
|
GGWave instance(p);
|
||||||
instance.setRxProtocols({{GGWAVE_TX_PROTOCOL_DT_FASTEST, instance.getTxProtocol(GGWAVE_TX_PROTOCOL_DT_FASTEST)}});
|
instance.setRxProtocols({
|
||||||
|
{ GGWAVE_TX_PROTOCOL_DT_FASTEST, instance.getTxProtocol(GGWAVE_TX_PROTOCOL_DT_FASTEST) },
|
||||||
|
});
|
||||||
Serial.println("Instance initialized");
|
Serial.println("Instance initialized");
|
||||||
|
|
||||||
static GGWave::CBWaveformInp cbWaveformInp = [&](void * data, uint32_t nMaxBytes) {
|
static GGWave::CBWaveformInp cbWaveformInp = [&](void * data, uint32_t nMaxBytes) {
|
||||||
|
|||||||
@@ -57,10 +57,11 @@ extern "C" {
|
|||||||
GGWAVE_TX_PROTOCOL_CUSTOM_9,
|
GGWAVE_TX_PROTOCOL_CUSTOM_9,
|
||||||
} ggwave_TxProtocolId;
|
} ggwave_TxProtocolId;
|
||||||
|
|
||||||
|
// Operating modes of ggwave
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX,
|
GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX,
|
||||||
GGWAVE_OPERATING_MODE_ONLY_RX,
|
GGWAVE_OPERATING_MODE_ONLY_RX,
|
||||||
//GGWAVE_OPERATING_MODE_ONLY_TX, // Not supported yet
|
GGWAVE_OPERATING_MODE_ONLY_TX,
|
||||||
} ggwave_OperatingMode;
|
} ggwave_OperatingMode;
|
||||||
|
|
||||||
// GGWave instance parameters
|
// GGWave instance parameters
|
||||||
@@ -318,10 +319,11 @@ public:
|
|||||||
static constexpr auto kMaxSpectrumHistory = 4;
|
static constexpr auto kMaxSpectrumHistory = 4;
|
||||||
static constexpr auto kMaxRecordedFrames = 2048;
|
static constexpr auto kMaxRecordedFrames = 2048;
|
||||||
|
|
||||||
using Parameters = ggwave_Parameters;
|
using Parameters = ggwave_Parameters;
|
||||||
using SampleFormat = ggwave_SampleFormat;
|
using SampleFormat = ggwave_SampleFormat;
|
||||||
using TxProtocolId = ggwave_TxProtocolId;
|
using TxProtocolId = ggwave_TxProtocolId;
|
||||||
using RxProtocolId = ggwave_TxProtocolId;
|
using RxProtocolId = ggwave_TxProtocolId;
|
||||||
|
using OperatingMode = ggwave_OperatingMode;
|
||||||
|
|
||||||
struct TxProtocol {
|
struct TxProtocol {
|
||||||
const char * name; // string identifier of the protocol
|
const char * name; // string identifier of the protocol
|
||||||
@@ -518,14 +520,17 @@ private:
|
|||||||
|
|
||||||
const float m_soundMarkerThreshold;
|
const float m_soundMarkerThreshold;
|
||||||
|
|
||||||
// common
|
const bool m_isFixedPayloadLength;
|
||||||
|
const int m_payloadLength;
|
||||||
|
|
||||||
bool m_isFixedPayloadLength;
|
const bool m_isRxEnabled;
|
||||||
int m_payloadLength;
|
const bool m_isTxEnabled;
|
||||||
|
const bool m_needResampling;
|
||||||
|
|
||||||
|
// common
|
||||||
TxRxData m_dataEncoded;
|
TxRxData m_dataEncoded;
|
||||||
|
|
||||||
// Rx
|
// Rx
|
||||||
bool m_isRxEnabled;
|
|
||||||
bool m_receivingData;
|
bool m_receivingData;
|
||||||
bool m_analyzingData;
|
bool m_analyzingData;
|
||||||
|
|
||||||
@@ -566,7 +571,6 @@ private:
|
|||||||
std::vector<SpectrumData> m_spectrumHistoryFixed;
|
std::vector<SpectrumData> m_spectrumHistoryFixed;
|
||||||
|
|
||||||
// Tx
|
// Tx
|
||||||
bool m_isTxEnabled;
|
|
||||||
bool m_hasNewTxData;
|
bool m_hasNewTxData;
|
||||||
float m_sendVolume;
|
float m_sendVolume;
|
||||||
|
|
||||||
|
|||||||
@@ -343,7 +343,13 @@ int bytesForSampleFormat(GGWave::SampleFormat sampleFormat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct GGWave::Impl {
|
struct GGWave::Impl {
|
||||||
Resampler resampler;
|
Impl(bool needResampling) {
|
||||||
|
if (needResampling) {
|
||||||
|
resampler = std::unique_ptr<Resampler>(new Resampler());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Resampler> resampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
void GGWave::setLogFile(FILE * fptr) {
|
void GGWave::setLogFile(FILE * fptr) {
|
||||||
@@ -384,39 +390,40 @@ GGWave::GGWave(const Parameters & parameters) :
|
|||||||
m_nMarkerFrames (parameters.payloadLength > 0 ? 0 : kDefaultMarkerFrames),
|
m_nMarkerFrames (parameters.payloadLength > 0 ? 0 : kDefaultMarkerFrames),
|
||||||
m_encodedDataOffset (parameters.payloadLength > 0 ? 0 : kDefaultEncodedDataOffset),
|
m_encodedDataOffset (parameters.payloadLength > 0 ? 0 : kDefaultEncodedDataOffset),
|
||||||
m_soundMarkerThreshold(parameters.soundMarkerThreshold),
|
m_soundMarkerThreshold(parameters.soundMarkerThreshold),
|
||||||
|
|
||||||
// common
|
|
||||||
m_isFixedPayloadLength(parameters.payloadLength > 0),
|
m_isFixedPayloadLength(parameters.payloadLength > 0),
|
||||||
m_payloadLength (parameters.payloadLength),
|
m_payloadLength (parameters.payloadLength),
|
||||||
|
m_isRxEnabled (parameters.operatingMode == GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX ||
|
||||||
|
parameters.operatingMode == GGWAVE_OPERATING_MODE_ONLY_RX),
|
||||||
|
m_isTxEnabled (parameters.operatingMode == GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX),
|
||||||
|
m_needResampling (m_sampleRateInp != m_sampleRate || m_sampleRateOut != m_sampleRate),
|
||||||
|
|
||||||
|
// common
|
||||||
m_dataEncoded (kMaxDataSize),
|
m_dataEncoded (kMaxDataSize),
|
||||||
|
|
||||||
// Rx
|
// Rx
|
||||||
m_isRxEnabled(parameters.operatingMode == GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX ||
|
m_samplesNeeded (m_isRxEnabled ? m_samplesPerFrame : 0),
|
||||||
parameters.operatingMode == GGWAVE_OPERATING_MODE_ONLY_RX),
|
m_fftInp (m_isRxEnabled ? m_samplesPerFrame : 0),
|
||||||
|
m_fftOut (m_isRxEnabled ? 2*m_samplesPerFrame : 0),
|
||||||
m_samplesNeeded (m_samplesPerFrame),
|
|
||||||
m_fftInp (m_samplesPerFrame),
|
|
||||||
m_fftOut (2*m_samplesPerFrame),
|
|
||||||
m_hasNewSpectrum (false),
|
m_hasNewSpectrum (false),
|
||||||
m_hasNewAmplitude (false),
|
m_hasNewAmplitude (false),
|
||||||
m_sampleSpectrum (m_samplesPerFrame),
|
m_sampleSpectrum (m_isRxEnabled ? m_samplesPerFrame : 0),
|
||||||
m_sampleAmplitude (m_sampleRateInp == m_sampleRate ? m_samplesPerFrame : m_samplesPerFrame + 128), // small extra space because sometimes resampling needs a few more samples
|
m_sampleAmplitude (m_isRxEnabled ? m_sampleRateInp == m_sampleRate ? m_samplesPerFrame : m_samplesPerFrame + 128 : 0), // small extra space because sometimes resampling needs a few more samples
|
||||||
m_sampleAmplitudeResampled(m_sampleRateInp == m_sampleRate ? m_samplesPerFrame : 8*m_samplesPerFrame), // min input sampling rate is 0.125*m_sampleRate
|
m_sampleAmplitudeResampled(m_isRxEnabled ? m_sampleRateInp == m_sampleRate ? m_samplesPerFrame : 8*m_samplesPerFrame : 0), // min input sampling rate is 0.125*m_sampleRate
|
||||||
m_sampleAmplitudeTmp (m_sampleRateInp == m_sampleRate ? m_samplesPerFrame*m_sampleSizeBytesInp : 8*m_samplesPerFrame*m_sampleSizeBytesInp),
|
m_sampleAmplitudeTmp (m_isRxEnabled ? m_sampleRateInp == m_sampleRate ? m_samplesPerFrame*m_sampleSizeBytesInp : 8*m_samplesPerFrame*m_sampleSizeBytesInp : 0),
|
||||||
m_hasNewRxData (false),
|
m_hasNewRxData (false),
|
||||||
m_lastRxDataLength (0),
|
m_lastRxDataLength (0),
|
||||||
m_rxData (kMaxDataSize),
|
m_rxData (m_isRxEnabled ? kMaxDataSize : 0),
|
||||||
m_rxProtocol (getDefaultTxProtocol()),
|
m_rxProtocol (getDefaultTxProtocol()),
|
||||||
m_rxProtocolId (getDefaultTxProtocolId()),
|
m_rxProtocolId (getDefaultTxProtocolId()),
|
||||||
m_rxProtocols (getTxProtocols()),
|
m_rxProtocols (getTxProtocols()),
|
||||||
m_historyId (0),
|
m_historyId (0),
|
||||||
m_sampleAmplitudeAverage (parameters.payloadLength > 0 ? 0 : m_samplesPerFrame),
|
m_sampleAmplitudeAverage (m_isFixedPayloadLength ? 0 : m_samplesPerFrame),
|
||||||
m_sampleAmplitudeHistory (parameters.payloadLength > 0 ? 0 : kMaxSpectrumHistory),
|
m_sampleAmplitudeHistory (m_isFixedPayloadLength ? 0 : kMaxSpectrumHistory),
|
||||||
|
m_recordedAmplitude (0),
|
||||||
m_historyIdFixed (0),
|
m_historyIdFixed (0),
|
||||||
|
m_spectrumHistoryFixed (0),
|
||||||
|
|
||||||
// Tx
|
// Tx
|
||||||
m_isTxEnabled(parameters.operatingMode == GGWAVE_OPERATING_MODE_BOTH_RX_AND_TX),
|
|
||||||
|
|
||||||
m_hasNewTxData (false),
|
m_hasNewTxData (false),
|
||||||
m_sendVolume (0.1),
|
m_sendVolume (0.1),
|
||||||
m_txDataLength (0),
|
m_txDataLength (0),
|
||||||
@@ -425,7 +432,7 @@ GGWave::GGWave(const Parameters & parameters) :
|
|||||||
m_outputBlockResampled(m_isTxEnabled ? 2*m_samplesPerFrame : 0),
|
m_outputBlockResampled(m_isTxEnabled ? 2*m_samplesPerFrame : 0),
|
||||||
m_outputBlockTmp (m_isTxEnabled ? kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut : 0),
|
m_outputBlockTmp (m_isTxEnabled ? kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut : 0),
|
||||||
m_outputBlockI16 (m_isTxEnabled ? kMaxRecordedFrames*m_samplesPerFrame : 0),
|
m_outputBlockI16 (m_isTxEnabled ? kMaxRecordedFrames*m_samplesPerFrame : 0),
|
||||||
m_impl(new Impl()) {
|
m_impl(new Impl(m_needResampling)) {
|
||||||
|
|
||||||
if (m_payloadLength > 0) {
|
if (m_payloadLength > 0) {
|
||||||
// fixed payload length
|
// fixed payload length
|
||||||
@@ -576,7 +583,7 @@ uint32_t GGWave::encodeSize_samples() const {
|
|||||||
if (m_sampleRateOut != m_sampleRate) {
|
if (m_sampleRateOut != m_sampleRate) {
|
||||||
factor = m_sampleRate/m_sampleRateOut;
|
factor = m_sampleRate/m_sampleRateOut;
|
||||||
// note : +1 extra sample in order to overestimate the buffer size
|
// note : +1 extra sample in order to overestimate the buffer size
|
||||||
samplesPerFrameOut = m_impl->resampler.resample(factor, m_samplesPerFrame, m_outputBlock.data(), nullptr) + 1;
|
samplesPerFrameOut = m_impl->resampler->resample(factor, m_samplesPerFrame, m_outputBlock.data(), nullptr) + 1;
|
||||||
}
|
}
|
||||||
int nECCBytesPerTx = getECCBytesForLength(m_txDataLength);
|
int nECCBytesPerTx = getECCBytesForLength(m_txDataLength);
|
||||||
int sendDataLength = m_txDataLength + m_encodedDataOffset;
|
int sendDataLength = m_txDataLength + m_encodedDataOffset;
|
||||||
@@ -591,7 +598,9 @@ uint32_t GGWave::encodeSize_samples() const {
|
|||||||
bool GGWave::encode(const CBWaveformOut & cbWaveformOut) {
|
bool GGWave::encode(const CBWaveformOut & cbWaveformOut) {
|
||||||
int frameId = 0;
|
int frameId = 0;
|
||||||
|
|
||||||
m_impl->resampler.reset();
|
if (m_impl->resampler) {
|
||||||
|
m_impl->resampler->reset();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<double> phaseOffsets(kMaxDataBits);
|
std::vector<double> phaseOffsets(kMaxDataBits);
|
||||||
|
|
||||||
@@ -729,7 +738,7 @@ bool GGWave::encode(const CBWaveformOut & cbWaveformOut) {
|
|||||||
|
|
||||||
int samplesPerFrameOut = m_samplesPerFrame;
|
int samplesPerFrameOut = m_samplesPerFrame;
|
||||||
if (m_sampleRateOut != m_sampleRate) {
|
if (m_sampleRateOut != m_sampleRate) {
|
||||||
samplesPerFrameOut = m_impl->resampler.resample(factor, m_samplesPerFrame, m_outputBlock.data(), m_outputBlockResampled.data());
|
samplesPerFrameOut = m_impl->resampler->resample(factor, m_samplesPerFrame, m_outputBlock.data(), m_outputBlockResampled.data());
|
||||||
} else {
|
} else {
|
||||||
m_outputBlockResampled = m_outputBlock;
|
m_outputBlockResampled = m_outputBlock;
|
||||||
}
|
}
|
||||||
@@ -815,7 +824,7 @@ void GGWave::decode(const CBWaveformInp & cbWaveformInp) {
|
|||||||
|
|
||||||
if (m_sampleRateInp != m_sampleRate) {
|
if (m_sampleRateInp != m_sampleRate) {
|
||||||
// note : predict 4 extra samples just to make sure we have enough data
|
// note : predict 4 extra samples just to make sure we have enough data
|
||||||
nBytesNeeded = (m_impl->resampler.resample(1.0f/factor, m_samplesNeeded, m_sampleAmplitudeResampled.data(), nullptr) + 4)*m_sampleSizeBytesInp;
|
nBytesNeeded = (m_impl->resampler->resample(1.0f/factor, m_samplesNeeded, m_sampleAmplitudeResampled.data(), nullptr) + 4)*m_sampleSizeBytesInp;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t nBytesRecorded = 0;
|
uint32_t nBytesRecorded = 0;
|
||||||
@@ -901,11 +910,11 @@ void GGWave::decode(const CBWaveformInp & cbWaveformInp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reset resampler state every minute
|
// reset resampler state every minute
|
||||||
if (!m_receivingData && m_impl->resampler.nSamplesTotal() > 60.0f*factor*m_sampleRate) {
|
if (!m_receivingData && m_impl->resampler->nSamplesTotal() > 60.0f*factor*m_sampleRate) {
|
||||||
m_impl->resampler.reset();
|
m_impl->resampler->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int nSamplesResampled = offset + m_impl->resampler.resample(factor, nSamplesRecorded, m_sampleAmplitudeResampled.data(), m_sampleAmplitude.data() + offset);
|
int nSamplesResampled = offset + m_impl->resampler->resample(factor, nSamplesRecorded, m_sampleAmplitudeResampled.data(), m_sampleAmplitude.data() + offset);
|
||||||
nSamplesRecorded = nSamplesResampled;
|
nSamplesRecorded = nSamplesResampled;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < nSamplesRecorded; ++i) {
|
for (int i = 0; i < nSamplesRecorded; ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user