MCPcopy Create free account
hub / github.com/OpenEarable/open-earable / provide

Method provide

src/audio_pdm/BLEStream.cpp:57–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57int BLEStream::provide(int max_cont) {
58 if (!_stream) return 0;
59
60 int cont = min((*stream)->get_contiguous_blocks(), max_cont);
61
62 if (!cont) return 0;
63
64 if (initial_drop > 0) {
65 const int n = min(initial_drop, cont);
66 (*stream)->provide(n);
67 initial_drop -= n;
68 cont -= n;
69
70 if (!cont) return n;
71 }
72
73 uint8_t *read_pointer = (*stream)->buffer.getReadPointer();
74 const int block_size = (*stream)->buffer.getBlockSize();
75
76 for (int i = 0; i<cont; i++) {
77 for (int k = 0; k < block_size; k+=down_sample * sizeof(int16_t)) {
78 memcpy(sos_buffer, read_pointer + i * block_size + k, down_sample * sizeof(int16_t));
79 filter->update((int16_t *) sos_buffer, down_sample);
80 ble_buffer[index_ble++] = sos_buffer[0];
81 if (index_ble == AUDIO_STREAM_PACKAGE_SIZE) {
82 index_ble = 0;
83
84 sensorProvider.update_manager();
85 pdm_sensor.setBuffer((uint8_t*) ble_buffer);
86 sensorProvider.update_sensor(PDM_MIC, true);
87 bleHandler_G.update();
88
89 delay(8);
90 }
91 }
92 }
93
94 // Serial.print("PDM: ");
95 // Serial.println(recorder.available() ? (*recorder.target->stream)->remaining() : -1);
96
97 (*stream)->provide(cont);
98
99 return cont;
100}
101
102void BLEStream::start() {
103 if (_stream) return;

Callers 1

update_audioMethod · 0.45

Calls 5

getReadPointerMethod · 0.80
getBlockSizeMethod · 0.80
get_contiguous_blocksMethod · 0.45
updateMethod · 0.45
setBufferMethod · 0.45

Tested by

no test coverage detected