c, python : add option to query encode size

This commit is contained in:
Georgi Gerganov
2021-01-23 17:13:13 +02:00
parent 0c746c1b15
commit ba8e0cd2b1
8 changed files with 58 additions and 21 deletions

View File

@@ -73,8 +73,11 @@ extern "C" {
// txProtocolId - the protocol to use for encoding
// volume - the volume of the generated waveform [0, 100]
// outputBuffer - the generated audio waveform. must be big enough to fit the generated data
// query - if != 0, do not perform encoding.
// if == 1, return waveform size in bytes
// if != 1, return waveform size in samples
//
// returns the number of generated samples
// returns the number of generated bytes or samples (see query)
//
// returns -1 if there was an error
//
@@ -87,7 +90,8 @@ extern "C" {
int dataSize,
ggwave_TxProtocolId txProtocolId,
int volume,
char * outputBuffer);
char * outputBuffer,
int query);
// Decode an audio waveform into data
// instance - the GGWave instance to use
@@ -182,24 +186,39 @@ public:
static const Parameters & getDefaultParameters();
// set Tx data to encode
//
// This prepares the GGWave instance for transmission.
// To perform the actual encoding, the encode() method must be called
//
// returns false upon invalid parameters or failure to initialize
//
bool init(const std::string & text, const int volume = kDefaultVolume);
bool init(const std::string & text, const TxProtocol & txProtocol, const int volume = kDefaultVolume);
bool init(int dataSize, const char * dataBuffer, const int volume = kDefaultVolume);
bool init(int dataSize, const char * dataBuffer, const TxProtocol & txProtocol, const int volume = kDefaultVolume);
// expected waveform size of the encoded Tx data
// expected waveform size of the encoded Tx data in bytes
uint32_t encodeSize_bytes() const;
// expected waveform size of the encoded Tx data in samples
uint32_t encodeSize_samples() const;
// encode Tx data into an audio waveform
//
// The generated waveform is returned by calling the cbWaveformOut callback.
//
// returns false if the encoding fails
//
bool encode(const CBWaveformOut & cbWaveformOut);
// decode an audio waveform
//
// This methods calls cbWaveformInp multiple times (at least once) until it returns 0.
// Use the Rx methods to check if any data was decoded successfully.
//
void decode(const CBWaveformInp & cbWaveformInp);
// instance state
const bool & hasTxData() const { return m_hasNewTxData; }
const bool & isReceiving() const { return m_receivingData; }
const bool & isAnalyzing() const { return m_analyzingData; }
@@ -215,17 +234,22 @@ public:
const float & getSampleRateInp() const { return m_sampleRateInp; }
const float & getSampleRateOut() const { return m_sampleRateOut; }
// Tx
static TxProtocolId getDefaultTxProtocolId() { return GGWAVE_TX_PROTOCOL_AUDIBLE_FAST; }
static const TxProtocol & getDefaultTxProtocol() { return getTxProtocols().at(getDefaultTxProtocolId()); }
static const TxProtocol & getTxProtocol(int id) { return getTxProtocols().at(TxProtocolId(id)); }
static const TxProtocol & getTxProtocol(TxProtocolId id) { return getTxProtocols().at(id); }
int takeTxAmplitudeDataI16(AmplitudeDataI16 & dst);
// Rx
const TxRxData & getRxData() const { return m_rxData; }
const TxProtocol & getRxProtocol() const { return m_rxProtocol; }
const TxProtocolId & getRxProtocolId() const { return m_rxProtocolId; }
int takeRxData(TxRxData & dst);
int takeTxAmplitudeDataI16(AmplitudeDataI16 & dst);
bool takeSpectrum(SpectrumData & dst);
private: