-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetAudio.h
More file actions
48 lines (38 loc) · 1.62 KB
/
NetAudio.h
File metadata and controls
48 lines (38 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <Arduino.h>
#include "AudioLink.h"
// ---------------------------------------------------------------------------
// NetAudio (Core2): receives the StickS3 wireless-mic stream over ESP-NOW,
// decodes the IMA-ADPCM frames into a PSRAM ring buffer, and hands samples to
// the AudioEngine. Also sends deck status back to the stick.
//
// Producer = ESP-NOW receive callback (Wi-Fi task); consumer = main loop.
// Single-producer / single-consumer ring with volatile head/tail.
// ---------------------------------------------------------------------------
class NetAudio {
public:
bool begin();
// Stick has sent any frame (audio or idle heartbeat) recently.
bool connected() const;
// Stick is currently streaming a recording (KEY1 held).
bool remoteRecActive() const;
// Drain up to maxSamples decoded samples into dst. Returns count copied.
size_t pull(int16_t* dst, size_t maxSamples);
// Heartbeat / mirror to the stick display.
void sendStatus(uint8_t deckState, uint8_t selTrack, bool remoteRec);
// Called from the static ESP-NOW receive callback.
void onRecvPacket(const uint8_t* data, int len);
private:
void push(const int16_t* s, size_t n);
void pushSilence(size_t n);
static constexpr uint32_t RING_SAMPLES = 16384; // ~1 s at 16 kHz, PSRAM
int16_t* _ring = nullptr;
volatile uint32_t _head = 0; // producer
volatile uint32_t _tail = 0; // consumer
volatile uint32_t _lastFrameMs = 0;
volatile uint32_t _lastRecMs = 0;
volatile uint16_t _lastSeq = 0;
volatile bool _haveSeq = false;
volatile bool _lastWasRec = false;
};
extern NetAudio Net;