@@ -43,7 +43,7 @@ class MyStreamRecording : public DataSink
4343
4444 public:
4545 uint8_t *dest;
46- size_t dest_pos ;
46+ size_t *dest_pos_ptr ;
4747 size_t dest_max;
4848 bool request_stop;
4949
@@ -65,18 +65,18 @@ int MyStreamRecording::pullRequest()
6565{
6666 ManagedBuffer data = this ->upStream .pull ();
6767
68- size_t n = MIN ((size_t )data.length (), this ->dest_max - this ->dest_pos );
68+ size_t n = MIN ((size_t )data.length (), this ->dest_max - * this ->dest_pos_ptr );
6969 if (n == 0 || this ->request_stop ) {
7070 this ->upStream .disconnect ();
7171 this ->request_stop = false ;
7272 } else {
7373 // Copy and convert signed 8-bit to unsigned 8-bit data.
7474 const uint8_t *src = data.getBytes ();
75- uint8_t *dest = this ->dest + this ->dest_pos ;
75+ uint8_t *dest = this ->dest + * this ->dest_pos_ptr ;
7676 for (size_t i = 0 ; i < n; ++i) {
7777 *dest++ = *src++ + 128 ;
7878 }
79- this ->dest_pos += n;
79+ * this ->dest_pos_ptr += n;
8080 }
8181
8282 return DEVICE_OK;
@@ -110,7 +110,7 @@ int microbit_hal_microphone_get_level(void) {
110110 return value;
111111}
112112
113- void microbit_hal_microphone_start_recording (uint8_t *buf, size_t len , int rate) {
113+ void microbit_hal_microphone_start_recording (uint8_t *buf, size_t max_len, size_t *cur_len , int rate) {
114114 if (splitterChannel == NULL ) {
115115 splitterChannel = uBit.audio .splitter ->createChannel ();
116116 splitterChannel->setFormat (DATASTREAM_FORMAT_8BIT_UNSIGNED);
@@ -131,8 +131,9 @@ void microbit_hal_microphone_start_recording(uint8_t *buf, size_t len, int rate)
131131 }
132132
133133 recording->dest = buf;
134- recording->dest_pos = 0 ;
135- recording->dest_max = len;
134+ recording->dest_pos_ptr = cur_len;
135+ *recording->dest_pos_ptr = 0 ;
136+ recording->dest_max = max_len;
136137 recording->request_stop = false ;
137138
138139 splitterChannel->connect (*recording);
0 commit comments