2022-11-02 18:23:41 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "SinglePortModule.h"
|
2022-12-01 17:47:04 +01:00
|
|
|
#include "concurrency/NotifiedWorkerThread.h"
|
2022-11-02 18:23:41 +01:00
|
|
|
#include "configuration.h"
|
2022-11-29 14:35:46 +01:00
|
|
|
#if defined(ARCH_ESP32)
|
2022-11-02 18:23:41 +01:00
|
|
|
#include "NodeDB.h"
|
|
|
|
|
#include <Arduino.h>
|
2022-11-29 17:19:10 +01:00
|
|
|
#include <driver/i2s.h>
|
2022-12-02 00:30:31 +01:00
|
|
|
// #include <driver/adc.h>
|
2022-11-02 18:23:41 +01:00
|
|
|
#include <functional>
|
|
|
|
|
#include <codec2.h>
|
|
|
|
|
#include <ButterworthFilter.h>
|
|
|
|
|
#include <FastAudioFIFO.h>
|
|
|
|
|
|
2022-12-02 00:30:31 +01:00
|
|
|
#define ADC_BUFFER_SIZE_MAX 320
|
2022-11-29 11:22:18 +01:00
|
|
|
|
2022-12-02 00:30:31 +01:00
|
|
|
enum RadioState { standby, rx, tx };
|
2022-11-02 18:23:41 +01:00
|
|
|
|
|
|
|
|
class AudioModule : public SinglePortModule, private concurrency::OSThread
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-12-01 17:47:04 +01:00
|
|
|
unsigned char rx_encode_frame[Constants_DATA_PAYLOAD_LEN] = {};
|
|
|
|
|
unsigned char tx_encode_frame[Constants_DATA_PAYLOAD_LEN] = {};
|
2022-12-02 00:30:31 +01:00
|
|
|
int16_t speech[ADC_BUFFER_SIZE_MAX] = {};
|
|
|
|
|
int16_t output_buffer[ADC_BUFFER_SIZE_MAX] = {};
|
|
|
|
|
uint16_t adc_buffer[ADC_BUFFER_SIZE_MAX] = {};
|
|
|
|
|
int adc_buffer_size = 0;
|
|
|
|
|
uint16_t adc_buffer_index = 0;
|
|
|
|
|
int tx_encode_frame_index = 0;
|
|
|
|
|
int rx_encode_frame_index = 0;
|
|
|
|
|
int encode_codec_size = 0;
|
|
|
|
|
int encode_frame_size = 0;
|
|
|
|
|
volatile RadioState radio_state = RadioState::rx;
|
|
|
|
|
FastAudioFIFO fifo;
|
|
|
|
|
struct CODEC2* codec2 = NULL;
|
|
|
|
|
int16_t sample;
|
|
|
|
|
adc1_channel_t mic_chan = (adc1_channel_t)0;
|
|
|
|
|
uint8_t rx_raw_audio_value = 127;
|
2022-11-29 11:22:18 +01:00
|
|
|
|
2022-11-02 18:23:41 +01:00
|
|
|
AudioModule();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send our payload into the mesh
|
|
|
|
|
*/
|
|
|
|
|
void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
|
|
|
|
|
|
|
|
|
protected:
|
2022-12-02 00:30:31 +01:00
|
|
|
int encode_frame_num = 0;
|
|
|
|
|
bool firstTime = true;
|
|
|
|
|
|
2022-11-02 18:23:41 +01:00
|
|
|
|
2022-12-02 00:30:31 +01:00
|
|
|
virtual int32_t runOnce() override;
|
2022-11-02 18:23:41 +01:00
|
|
|
|
|
|
|
|
virtual MeshPacket *allocReply() override;
|
|
|
|
|
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
* @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
|
*/
|
|
|
|
|
virtual ProcessMessage handleReceived(const MeshPacket &mp) override;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern AudioModule *audioModule;
|
2022-11-29 11:22:18 +01:00
|
|
|
|
2022-11-29 14:35:46 +01:00
|
|
|
#endif
|