1
- /* ByteBeat@1.0.8 , license MIT */
1
+ /* ByteBeat@1.0.9 , license MIT */
2
2
class WrappingStack {
3
3
constructor ( stackSize = 256 ) {
4
4
let sp = 0 ;
@@ -270,7 +270,6 @@ class ByteBeatCompiler {
270
270
tiltX : 0 ,
271
271
tiltY : 0 ,
272
272
compass : 0 ,
273
- sampleRate : 0 ,
274
273
} ;
275
274
}
276
275
@@ -417,26 +416,29 @@ class ByteBeatProcessor {
417
416
array : [
418
417
// case 0: // bytebeat
419
418
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
419
+ const sampleRate = extra ?. sampleRate || 8000 ;
420
420
for ( let i = 0 ; i < lastSample ; ++ i ) {
421
- const s = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
421
+ const s = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
422
422
buffer0 [ time % buffer0 . length ] = ( s [ 0 ] & 255 ) / 127 - 1 ;
423
423
buffer1 [ time % buffer1 . length ] = ( s [ 1 ] & 255 ) / 127 - 1 ;
424
424
++ time ;
425
425
}
426
426
} ,
427
427
// case 1: // floatbeat
428
428
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
429
+ const sampleRate = extra ?. sampleRate || 8000 ;
429
430
for ( let i = 0 ; i < lastSample ; ++ i ) {
430
- const s = fn0 . call ( ctx0 , ( time / divisor ) , undefined , stack0 , ctx0 , extra ) ;
431
+ const s = fn0 . call ( ctx0 , ( time / divisor ) , sampleRate , stack0 , ctx0 , extra ) ;
431
432
buffer0 [ time % buffer0 . length ] = Number . isNaN ( s [ 0 ] ) ? 0 : s [ 0 ] ;
432
433
buffer1 [ time % buffer1 . length ] = Number . isNaN ( s [ 1 ] ) ? 0 : s [ 1 ] ;
433
434
++ time ;
434
435
}
435
436
} ,
436
437
// case 2: // signed bytebeat
437
438
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
439
+ const sampleRate = extra ?. sampleRate || 8000 ;
438
440
for ( let i = 0 ; i < lastSample ; ++ i ) {
439
- const s = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
441
+ const s = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
440
442
int8 [ 0 ] = s [ 0 ] ;
441
443
buffer0 [ time % buffer0 . length ] = int8 [ 0 ] / 128 ;
442
444
int8 [ 0 ] = s [ 1 ] ;
@@ -448,27 +450,30 @@ class ByteBeatProcessor {
448
450
twoChannels : [
449
451
// case 0: // bytebeat
450
452
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
453
+ const sampleRate = extra ?. sampleRate || 8000 ;
451
454
for ( let i = 0 ; i < lastSample ; ++ i ) {
452
- buffer0 [ time % buffer0 . length ] = ( fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) & 255 ) / 127 - 1 ;
453
- buffer1 [ time % buffer1 . length ] = ( fn1 . call ( ctx1 , ( time ) / divisor , undefined , stack1 , ctx1 , extra ) & 255 ) / 127 - 1 ;
455
+ buffer0 [ time % buffer0 . length ] = ( fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) & 255 ) / 127 - 1 ;
456
+ buffer1 [ time % buffer1 . length ] = ( fn1 . call ( ctx1 , ( time ) / divisor , sampleRate , stack1 , ctx1 , extra ) & 255 ) / 127 - 1 ;
454
457
++ time ;
455
458
}
456
459
} ,
457
460
// case 1: // floatbeat
458
461
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
462
+ const sampleRate = extra ?. sampleRate || 8000 ;
459
463
for ( let i = 0 ; i < lastSample ; ++ i ) {
460
- const s0 = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
464
+ const s0 = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
461
465
buffer0 [ time % buffer0 . length ] = Number . isNaN ( s0 ) ? 0 : s0 ;
462
- const s1 = fn1 . call ( ctx1 , ( time ) / divisor , undefined , stack1 , ctx1 , extra ) ;
466
+ const s1 = fn1 . call ( ctx1 , ( time ) / divisor , sampleRate , stack1 , ctx1 , extra ) ;
463
467
buffer1 [ time % buffer1 . length ] = Number . isNaN ( s1 ) ? 0 : s1 ;
464
468
}
465
469
} ,
466
470
// case 2: // signed bytebeat
467
471
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
472
+ const sampleRate = extra ?. sampleRate || 8000 ;
468
473
for ( let i = 0 ; i < lastSample ; ++ i ) {
469
- int8 [ 0 ] = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
474
+ int8 [ 0 ] = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
470
475
buffer0 [ time % buffer0 . length ] = int8 [ 0 ] / 128 ;
471
- int8 [ 0 ] = fn1 . call ( ctx1 , ( time ) / divisor , undefined , stack1 , ctx1 , extra ) ;
476
+ int8 [ 0 ] = fn1 . call ( ctx1 , ( time ) / divisor , sampleRate , stack1 , ctx1 , extra ) ;
472
477
buffer1 [ time % buffer1 . length ] = int8 [ 0 ] / 128 ;
473
478
++ time ;
474
479
}
@@ -477,23 +482,26 @@ class ByteBeatProcessor {
477
482
oneChannel : [
478
483
// case 0: // bytebeat
479
484
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
485
+ const sampleRate = extra ?. sampleRate || 8000 ;
480
486
for ( let i = 0 ; i < lastSample ; ++ i ) {
481
- buffer0 [ time % buffer0 . length ] = ( fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) & 255 ) / 127 - 1 ;
487
+ buffer0 [ time % buffer0 . length ] = ( fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) & 255 ) / 127 - 1 ;
482
488
++ time ;
483
489
}
484
490
} ,
485
491
// case 1: // floatbeat
486
492
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
493
+ const sampleRate = extra ?. sampleRate || 8000 ;
487
494
for ( let i = 0 ; i < lastSample ; ++ i ) {
488
- const s = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
495
+ const s = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
489
496
buffer0 [ time % buffer0 . length ] = Number . isNaN ( s ) ? 0 : s ;
490
497
++ time ;
491
498
}
492
499
} ,
493
500
// case 2: // signed bytebeat
494
501
function ( buffer0 , buffer1 , fn0 , fn1 , time , divisor , stack0 , stack1 , ctx0 , ctx1 , extra , lastSample ) {
502
+ const sampleRate = extra ?. sampleRate || 8000 ;
495
503
for ( let i = 0 ; i < lastSample ; ++ i ) {
496
- int8 [ 0 ] = fn0 . call ( ctx0 , ( time ) / divisor , undefined , stack0 , ctx0 , extra ) ;
504
+ int8 [ 0 ] = fn0 . call ( ctx0 , ( time ) / divisor , sampleRate , stack0 , ctx0 , extra ) ;
497
505
buffer0 [ time % buffer0 . length ] = int8 [ 0 ] / 128 ;
498
506
++ time ;
499
507
}
@@ -532,8 +540,8 @@ class ByteBeatProcessor {
532
540
this . expressionType = 0 ;
533
541
this . functions = [
534
542
{
535
- f : function ( t ) {
536
- return Math . sin ( t ) * 0.1 ;
543
+ f : function ( ) {
544
+ return 0 ;
537
545
} ,
538
546
array : false ,
539
547
} ,
@@ -571,7 +579,6 @@ class ByteBeatProcessor {
571
579
572
580
setDesiredSampleRate ( rate ) {
573
581
this . desiredSampleRate = rate ;
574
- this . extra . sampleRate = rate ;
575
582
}
576
583
577
584
getDesiredSampleRate ( ) {
@@ -624,7 +631,7 @@ class ByteBeatProcessor {
624
631
const buffer0 = this . buffer0 ;
625
632
const buffer1 = ( fn0Array || fn1 ) ? this . buffer1 : buffer0 ;
626
633
const extra = this . extra ;
627
- const divisor = 1 ; // this.expressionType === 3 ? this.getDesiredSampleRate() : 1;
634
+ const divisor = this . expressionType === 3 ? this . getDesiredSampleRate ( ) : 1 ;
628
635
629
636
const startSrcId = Math . max ( this . srcSampleCount , neededSrcStartSampleId ) ;
630
637
const numSrcSampleToGenerate = neededSrcEndSampleId - startSrcId ;
@@ -688,7 +695,7 @@ class ByteBeatProcessor {
688
695
}
689
696
690
697
getSampleForTime ( time , context , stack , channel = 0 ) {
691
- const divisor = 1 ; // this.expressionType === 3 ? this.getDesiredSampleRate() : 1;
698
+ const divisor = this . expressionType === 3 ? this . getDesiredSampleRate ( ) : 1 ;
692
699
let s = 0 ;
693
700
try {
694
701
if ( this . functions [ 0 ] . array ) {
0 commit comments