Mercurial > hg > dmlib
comparison jssmix.c @ 134:1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
in the mixer.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 02:47:36 +0300 |
parents | 2edda27f951c |
children | 111f3e4b57ad |
comparison
equal
deleted
inserted
replaced
133:92cc5e1fa180 | 134:1ba202b448e0 |
---|---|
383 | 383 |
384 if (mixer->cbFunction) | 384 if (mixer->cbFunction) |
385 { | 385 { |
386 if (mixer->cbCounter <= 0) | 386 if (mixer->cbCounter <= 0) |
387 { | 387 { |
388 for (i = 0; i < jsetNChannels; i++) | |
389 { | |
390 JSSChannel *chn = &(mixer->channels[i]); | |
391 if (chn->chPlaying && !chn->chMute) | |
392 chn->chDeltaV.dw = chn->chDeltaP.dw = 0; | |
393 } | |
388 mixer->cbFunction(mixer, mixer->cbData); | 394 mixer->cbFunction(mixer, mixer->cbData); |
389 mixer->cbCounter = mixer->cbFreq; | 395 mixer->cbCounter = mixer->cbFreq; |
390 } | 396 } |
391 | 397 |
392 if (mixer->cbCounter < blockLength) | 398 if (mixer->cbCounter < blockLength) |
457 | 463 |
458 int jvmSetCallbackFreq(JSSMixer * mixer, const int cbFreq) | 464 int jvmSetCallbackFreq(JSSMixer * mixer, const int cbFreq) |
459 { | 465 { |
460 assert(mixer); | 466 assert(mixer); |
461 | 467 |
462 if ((cbFreq < 1) || (cbFreq >= mixer->outFreq)) | 468 if (cbFreq < 1 || cbFreq >= mixer->outFreq) |
463 JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS, | 469 JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS, |
464 "Invalid callback frequency given (%i / %i)\n", cbFreq, mixer->outFreq); | 470 "Invalid callback frequency given (%i / %i)\n", cbFreq, mixer->outFreq); |
465 | 471 |
466 JSS_LOCK(mixer); | 472 JSS_LOCK(mixer); |
467 | 473 |
468 mixer->cbFreq = (mixer->outFreq / cbFreq); | 474 mixer->cbFreq = mixer->outFreq / cbFreq; |
469 mixer->cbCounter = 0; | 475 mixer->cbCounter = 0; |
470 | 476 |
471 //fprintf(stderr, "set(outFreq = %d, cbFreq = %d) = %d\n", mixer->outFreq, cbFreq, mixer->cbFreq); | 477 //fprintf(stderr, "set(outFreq = %d, cbFreq = %d) = %d\n", mixer->outFreq, cbFreq, mixer->cbFreq); |
472 | 478 |
473 JSS_UNLOCK(mixer); | 479 JSS_UNLOCK(mixer); |
551 | 557 |
552 | 558 |
553 void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume) | 559 void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume) |
554 { | 560 { |
555 JSS_LOCK(mixer); | 561 JSS_LOCK(mixer); |
556 mixer->channels[channel].chVolume = volume; | 562 FP_SETHL(mixer->channels[channel].chVolume, volume, 0); |
563 mixer->channels[channel].chDeltaV.dw = 0; | |
564 JSS_UNLOCK(mixer); | |
565 } | |
566 | |
567 | |
568 void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end) | |
569 { | |
570 DMFixedPoint a, b; | |
571 JSS_LOCK(mixer); | |
572 FP_SETHL(mixer->channels[channel].chVolume, start, 0); | |
573 | |
574 FP_SETHL(a, (end - start), 0); | |
575 FP_CONV(b, mixer->cbFreq); | |
576 FP_DIV_R(mixer->channels[channel].chDeltaV, a, b); | |
577 | |
557 JSS_UNLOCK(mixer); | 578 JSS_UNLOCK(mixer); |
558 } | 579 } |
559 | 580 |
560 | 581 |
561 int jvmGetVolume(JSSMixer * mixer, const int channel) | 582 int jvmGetVolume(JSSMixer * mixer, const int channel) |
562 { | 583 { |
563 int tmp; | 584 int tmp; |
564 | 585 |
565 JSS_LOCK(mixer); | 586 JSS_LOCK(mixer); |
566 tmp = mixer->channels[channel].chVolume; | 587 tmp = FP_GETH(mixer->channels[channel].chVolume); |
567 JSS_UNLOCK(mixer); | 588 JSS_UNLOCK(mixer); |
568 | 589 |
569 return tmp; | 590 return tmp; |
570 } | 591 } |
571 | 592 |
572 | 593 |
573 void jvmSetPos(JSSMixer * mixer, const int channel, const Sint32 pos) | 594 void jvmSetPos(JSSMixer * mixer, const int channel, const Sint32 pos) |
574 { | 595 { |
575 JSS_LOCK(mixer); | 596 JSS_LOCK(mixer); |
576 FP_SETH(mixer->channels[channel].chPos, pos); | 597 FP_SETHL(mixer->channels[channel].chPos, pos, 0); |
577 FP_SETL(mixer->channels[channel].chPos, 0); | |
578 JSS_UNLOCK(mixer); | 598 JSS_UNLOCK(mixer); |
579 } | 599 } |
580 | 600 |
581 | 601 |
582 Sint32 jvmGetPos(JSSMixer * mixer, const int channel) | 602 Sint32 jvmGetPos(JSSMixer * mixer, const int channel) |
592 | 612 |
593 | 613 |
594 void jvmSetPan(JSSMixer * mixer, const int channel, const int panning) | 614 void jvmSetPan(JSSMixer * mixer, const int channel, const int panning) |
595 { | 615 { |
596 JSS_LOCK(mixer); | 616 JSS_LOCK(mixer); |
597 mixer->channels[channel].chPanning = panning; | 617 FP_SETHL(mixer->channels[channel].chPanning, panning, 0); |
618 mixer->channels[channel].chDeltaP.dw = 0; | |
619 JSS_UNLOCK(mixer); | |
620 } | |
621 | |
622 | |
623 void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end) | |
624 { | |
625 DMFixedPoint a, b; | |
626 JSS_LOCK(mixer); | |
627 FP_SETHL(mixer->channels[channel].chPanning, start, 0); | |
628 FP_SETHL(a, (end - start), 0); | |
629 FP_CONV(b, mixer->cbFreq); | |
630 FP_DIV_R(mixer->channels[channel].chDeltaP, a, b); | |
598 JSS_UNLOCK(mixer); | 631 JSS_UNLOCK(mixer); |
599 } | 632 } |
600 | 633 |
601 | 634 |
602 int jvmGetPan(JSSMixer * mixer, const int channel) | 635 int jvmGetPan(JSSMixer * mixer, const int channel) |
603 { | 636 { |
604 int tmp; | 637 int tmp; |
605 | 638 |
606 JSS_LOCK(mixer); | 639 JSS_LOCK(mixer); |
607 tmp = mixer->channels[channel].chPanning; | 640 tmp = FP_GETH(mixer->channels[channel].chPanning); |
608 JSS_UNLOCK(mixer); | 641 JSS_UNLOCK(mixer); |
609 | 642 |
610 return tmp; | 643 return tmp; |
611 } | 644 } |
612 | 645 |