@@ -385,9 +385,10 @@ class GeneratorFromArray : public SoundGenerator<T> {
385
385
public:
386
386
387
387
template <size_t arrayLen>
388
- GeneratorFromArray (T(&array)[arrayLen], int repeat=0 ) {
388
+ GeneratorFromArray (T(&array)[arrayLen], int repeat=0 , bool setInactiveAtEnd= true ) {
389
389
LOGD (LOG_METHOD);
390
- this ->maxRepeat = repeat;
390
+ this ->max_repeat = repeat;
391
+ this ->inactive_at_end = setInactiveAtEnd;
391
392
setArray (array, arrayLen);
392
393
}
393
394
@@ -398,49 +399,60 @@ class GeneratorFromArray : public SoundGenerator<T> {
398
399
}
399
400
400
401
void setArray (T*array, size_t size){
401
- this ->tableLength = size;
402
+ this ->table_length = size;
402
403
this ->table = array;
403
- LOGI (" tableLength : %d" , (int )size);
404
+ LOGI (" table_length : %d" , (int )size);
404
405
}
405
406
406
407
// / Starts the generation of samples
407
408
void begin () override {
408
409
LOGI (LOG_METHOD);
409
410
SoundGenerator<T>::begin ();
410
- soundIndex = 0 ;
411
- repeatCounter = 0 ;
411
+ sound_index = 0 ;
412
+ repeat_counter = 0 ;
413
+ is_running = true ;
412
414
}
413
415
414
416
// / Provides a single sample
415
417
T readSample () override {
416
418
// at end deactivate output
417
- if (soundIndex >= tableLength ) {
418
- // LOGD("reset index - soundIndex : %d, tableLength : %d",soundIndex,tableLength );
419
- soundIndex = 0 ;
419
+ if (sound_index >= table_length ) {
420
+ // LOGD("reset index - sound_index : %d, table_length : %d",sound_index,table_length );
421
+ sound_index = 0 ;
420
422
// deactivate when count has been used up
421
- if (maxRepeat>=1 && ++repeatCounter>=maxRepeat){
422
- this ->active = false ;
423
- LOGD (" active: false" );
423
+ if (max_repeat>=1 && ++repeat_counter>=max_repeat){
424
+ LOGD (" atEnd" );
425
+ this ->is_running = false ;
426
+ if (inactive_at_end){
427
+ this ->active = false ;
428
+ }
424
429
}
425
430
}
426
431
427
- // LOGD("index: %d - active: %d", soundIndex , this->active);
432
+ // LOGD("index: %d - active: %d", sound_index , this->active);
428
433
T result = 0 ;
429
- if (this ->active ) {
430
- result = table[soundIndex ];
431
- soundIndex ++;
434
+ if (this ->is_running ) {
435
+ result = table[sound_index ];
436
+ sound_index ++;
432
437
}
433
438
434
439
return result;
435
440
}
436
441
442
+ // Similar like
443
+ bool isRunning () {
444
+ return is_running;
445
+ }
446
+
437
447
438
448
protected:
439
- int soundIndex = 0 ;
440
- int maxRepeat = 0 ;
441
- int repeatCounter = 0 ;
449
+ int sound_index = 0 ;
450
+ int max_repeat = 0 ;
451
+ int repeat_counter = 0 ;
452
+ bool inactive_at_end;
453
+ bool is_running = false ;
442
454
T *table;
443
- size_t tableLength = 0 ;
455
+ size_t table_length = 0 ;
444
456
445
457
};
446
458
0 commit comments