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

@@ -69,7 +69,7 @@ encode()
.. code:: python
encode(payload, [txProtocolId], [volume], [instance])
encode(payload, [protocolId], [volume], [instance])
Encodes ``payload`` into an audio waveform.
@@ -138,7 +138,7 @@ Usage
p = pyaudio.PyAudio()
# generate audio waveform for string "hello python"
waveform = ggwave.encode("hello python", txProtocolId = 1, volume = 20)
waveform = ggwave.encode("hello python", protocolId = 1, volume = 20)
print("Transmitting text 'hello python' ...")
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=48000, output=True, frames_per_buffer=4096)

View File

@@ -8,27 +8,27 @@ cdef extern from "ggwave.h" nogil:
GGWAVE_SAMPLE_FORMAT_I16,
GGWAVE_SAMPLE_FORMAT_F32
ctypedef enum ggwave_TxProtocolId:
GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL,
GGWAVE_TX_PROTOCOL_AUDIBLE_FAST,
GGWAVE_TX_PROTOCOL_AUDIBLE_FASTEST,
GGWAVE_TX_PROTOCOL_ULTRASOUND_NORMAL,
GGWAVE_TX_PROTOCOL_ULTRASOUND_FAST,
GGWAVE_TX_PROTOCOL_ULTRASOUND_FASTEST,
GGWAVE_TX_PROTOCOL_DT_NORMAL,
GGWAVE_TX_PROTOCOL_DT_FAST,
GGWAVE_TX_PROTOCOL_DT_FASTEST,
ctypedef enum ggwave_ProtocolId:
GGWAVE_PROTOCOL_AUDIBLE_NORMAL,
GGWAVE_PROTOCOL_AUDIBLE_FAST,
GGWAVE_PROTOCOL_AUDIBLE_FASTEST,
GGWAVE_PROTOCOL_ULTRASOUND_NORMAL,
GGWAVE_PROTOCOL_ULTRASOUND_FAST,
GGWAVE_PROTOCOL_ULTRASOUND_FASTEST,
GGWAVE_PROTOCOL_DT_NORMAL,
GGWAVE_PROTOCOL_DT_FAST,
GGWAVE_PROTOCOL_DT_FASTEST,
GGWAVE_TX_PROTOCOL_CUSTOM_0,
GGWAVE_TX_PROTOCOL_CUSTOM_1,
GGWAVE_TX_PROTOCOL_CUSTOM_2,
GGWAVE_TX_PROTOCOL_CUSTOM_3,
GGWAVE_TX_PROTOCOL_CUSTOM_4,
GGWAVE_TX_PROTOCOL_CUSTOM_5,
GGWAVE_TX_PROTOCOL_CUSTOM_6,
GGWAVE_TX_PROTOCOL_CUSTOM_7,
GGWAVE_TX_PROTOCOL_CUSTOM_8,
GGWAVE_TX_PROTOCOL_CUSTOM_9
GGWAVE_PROTOCOL_CUSTOM_0,
GGWAVE_PROTOCOL_CUSTOM_1,
GGWAVE_PROTOCOL_CUSTOM_2,
GGWAVE_PROTOCOL_CUSTOM_3,
GGWAVE_PROTOCOL_CUSTOM_4,
GGWAVE_PROTOCOL_CUSTOM_5,
GGWAVE_PROTOCOL_CUSTOM_6,
GGWAVE_PROTOCOL_CUSTOM_7,
GGWAVE_PROTOCOL_CUSTOM_8,
GGWAVE_PROTOCOL_CUSTOM_9
ctypedef enum ggwave_OperatingMode:
GGWAVE_OPERATING_MODE_RX,
@@ -58,22 +58,25 @@ cdef extern from "ggwave.h" nogil:
int ggwave_encode(
ggwave_Instance instance,
const char * dataBuffer,
int dataSize,
ggwave_TxProtocolId txProtocolId,
const void * payloadBuffer,
int payloadSize,
ggwave_ProtocolId protocolId,
int volume,
char * outputBuffer,
void * waveformBuffer,
int query);
int ggwave_decode(
ggwave_Instance instance,
const char * dataBuffer,
int dataSize,
char * outputBuffer);
const void * waveformBuffer,
int waveformSize,
void * payloadBuffer);
void ggwave_setLogFile(void * fptr);
void ggwave_toggleRxProtocol(
ggwave_Instance instance,
ggwave_TxProtocolId rxProtocolId,
void ggwave_rxToggleProtocol(
ggwave_ProtocolId protocolId,
int state);
void ggwave_txToggleProtocol(
ggwave_ProtocolId protocolId,
int state);

View File

@@ -19,7 +19,7 @@ def init(parameters = None):
def free(instance):
return cggwave.ggwave_free(instance)
def encode(payload, txProtocolId = 1, volume = 10, instance = None):
def encode(payload, protocolId = 1, volume = 10, instance = None):
""" Encode payload into an audio waveform.
@param {string} payload, the data to be encoded
@return Generated audio waveform bytes representing 16-bit signed integer samples.
@@ -33,12 +33,12 @@ def encode(payload, txProtocolId = 1, volume = 10, instance = None):
own = True
instance = init(getDefaultParameters())
n = cggwave.ggwave_encode(instance, cdata, len(data_bytes), txProtocolId, volume, NULL, 1)
n = cggwave.ggwave_encode(instance, cdata, len(data_bytes), protocolId, volume, NULL, 1)
cdef bytes output_bytes = bytes(n)
cdef char* coutput = output_bytes
n = cggwave.ggwave_encode(instance, cdata, len(data_bytes), txProtocolId, volume, coutput, 0)
n = cggwave.ggwave_encode(instance, cdata, len(data_bytes), protocolId, volume, coutput, 0)
if (own):
free(instance)
@@ -70,5 +70,8 @@ def disableLog():
def enableLog():
cggwave.ggwave_setLogFile(stderr);
def toggleRxProtocol(instance, rxProtocolId, state):
cggwave.ggwave_toggleRxProtocol(instance, rxProtocolId, state);
def rxToggleProtocol(protocolId, state):
cggwave.ggwave_rxToggleProtocol(protocolId, state);
def txToggleProtocol(protocolId, state):
cggwave.ggwave_txToggleProtocol(protocolId, state);