File tree 11 files changed +10
-12
lines changed
BluetoothHIDMaster/examples
11 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ int ADCInput::available() {
156
156
if (!_running) {
157
157
return 0 ;
158
158
} else {
159
- return _arb->available ();
159
+ return _arb->available () + _isHolding ? sizeof ( int16_t ) : 0 ;
160
160
}
161
161
}
162
162
Original file line number Diff line number Diff line change @@ -259,12 +259,12 @@ int AudioBufferManager::available() {
259
259
return 0 ;
260
260
}
261
261
262
- int avail = _wordsPerBuffer - _userOff; // Currently available in this buffer
262
+ int avail = ( _wordsPerBuffer - _userOff) * sizeof ( uint32_t ) ; // Currently available in this buffer
263
263
264
264
// Each add'l buffer has wpb spaces...
265
265
auto x = p->next ;
266
266
while (x) {
267
- avail += _wordsPerBuffer;
267
+ avail += _wordsPerBuffer * sizeof ( uint32_t ) ;
268
268
x = x->next ;
269
269
}
270
270
return avail;
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ void setup() {
80
80
}
81
81
82
82
void loop () {
83
- while ((size_t )a2dp.availableForWrite () > sizeof (pcm)) {
83
+ while ((size_t )a2dp.availableForWrite () >= sizeof (pcm)) {
84
84
fillPCM ();
85
85
a2dp.write ((const uint8_t *)pcm, sizeof (pcm));
86
86
}
Original file line number Diff line number Diff line change @@ -262,7 +262,6 @@ int A2DPSource::availableForWrite() {
262
262
} else {
263
263
avail = _pcmBufferSize - _pcmWriter + _pcmReader - 1 ;
264
264
}
265
- avail /= sizeof (uint32_t ); // availableForWrite always 32b sample pairs in this core...
266
265
return avail;
267
266
}
268
267
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ void BluetoothAudioConsumerI2S::close() {
69
69
}
70
70
71
71
void BluetoothAudioConsumerI2S::fill () {
72
- int num_samples = _i2s->availableForWrite () / 2 ;
72
+ int num_samples = _i2s->availableForWrite () / ( 2 * sizeof ( int16_t )) ;
73
73
int16_t buff[32 * 2 ];
74
74
while (num_samples > 63 ) {
75
75
_a2dpSink->playback_handler ((int16_t *) buff, 32 );
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ void BluetoothAudioConsumerPWM::close() {
70
70
}
71
71
72
72
void BluetoothAudioConsumerPWM::fill () {
73
- int num_samples = _pwm->availableForWrite () / 2 ;
73
+ int num_samples = _pwm->availableForWrite () / ( 2 * sizeof ( int16_t )) ;
74
74
int16_t buff[32 * 2 ];
75
75
while (num_samples > 63 ) {
76
76
_a2dpSink->playback_handler ((int16_t *) buff, 32 );
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ void silenceOscillators() {
46
46
47
47
// PWM callback, generates sum of online oscillators
48
48
void fill () {
49
- int num_samples = pwm.availableForWrite () / 2 ;
49
+ int num_samples = pwm.availableForWrite () / ( 2 * sizeof ( int16_t )) ;
50
50
int16_t buff[32 * 2 ];
51
51
52
52
while (num_samples > 63 ) {
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ void silenceOscillators() {
46
46
47
47
// PWM callback, generates sum of online oscillators
48
48
void fill () {
49
- int num_samples = pwm.availableForWrite () / 2 ;
49
+ int num_samples = pwm.availableForWrite () / ( 2 * sizeof ( int16_t ) ;
50
50
int16_t buff[32 * 2 ];
51
51
52
52
while (num_samples > 63 ) {
Original file line number Diff line number Diff line change @@ -307,7 +307,6 @@ int I2S::available() {
307
307
return 0 ;
308
308
} else {
309
309
auto avail = _arb->available ();
310
- avail *= 4 ; // 4 samples per 32-bits
311
310
if (_bps < 24 && !_isOutput) {
312
311
avail += _isHolding / 8 ;
313
312
}
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ PWMAudio pwm(1);
17
17
unsigned int count = 0 ;
18
18
19
19
void cb () {
20
- while (pwm.availableForWrite ()) {
20
+ while (pwm.availableForWrite () > sizeof ( int16_t ) ) {
21
21
pwm.write (*p++);
22
22
count += 2 ;
23
23
if (count >= sizeof (out_raw)) {
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ double sineTable[128]; // Precompute sine wave in 128 steps
24
24
25
25
unsigned int cnt = 0 ;
26
26
void cb () {
27
- while (pwm.availableForWrite ()) {
27
+ while (pwm.availableForWrite () >= 2 * sizeof ( int16_t ) ) {
28
28
double now = ((double )cnt) / (double )freq;
29
29
int fl = freqL << 7 ; // Prescale by 128 to avoid FP math later on
30
30
int fr = freqR << 7 ; // Prescale by 128 to avoid FP math later on
You can’t perform that action at this time.
0 commit comments