Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Natural cross fading with fader component

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    13

    Natural cross fading with fader component

    Hi

    I'm trying to achieve some "natural sounding" cross fading between 2 speakers, with the aim of keeping the volume constant during the fading.

    For example:

    Click image for larger version. 

Name:	fade.PNG 
Views:	4 
Size:	5.5 KB 
ID:	27283

    In the loop:

    Code:
    AudioNoInterrupts();
    fader1.fadeIn(500);
    fader2.fadeOut(500);
    AudioInterrupts();
    delay(500);
    
    AudioNoInterrupts();
    fader2.fadeIn(500);
    fader1.fadeOut(500);
    AudioInterrupts();
    delay(500);
    Now the problem is that the fading seems to be using a linear mapping which makes the dynamic change a lot, when I'd like to keep the volume at the same level.

    Would there be an easy way to edit the fader code to change this, like using sine or log function for the mapping?

    I've tried another way, with mixers and adjusting the gain over time using a sine function instead of linear, which is fine when the cross time is high, as the volume is pretty constant then, but under a certain amount (e.g 250ms) there is a lot of audio clicking (and I'd like to do some very fast cross fading under 100ms).

    (On another note I've noticed that the fader object stops working when the duration is below 55ms).

    Thanks for your suggestions!

    Ben

  2. #2
    Junior Member
    Join Date
    Feb 2021
    Posts
    13
    I found the fader_table in data_waveforms.c and updated with sine mapping instead, works much better now (see below).

    Let me know if you have other ideas.

    Code:
    const int16_t fader_table[257] = {
    0,   201,   402,   603,   804,  1005,  1206,  1407,  1608,  1809,
      2009,  2210,  2410,  2611,  2811,  3012,  3212,  3412,  3612,  3811,
      4011,  4210,  4410,  4609,  4808,  5007,  5205,  5404,  5602,  5800,
      5998,  6195,  6393,  6590,  6786,  6983,  7179,  7375,  7571,  7767,
      7962,  8157,  8351,  8545,  8739,  8933,  9126,  9319,  9512,  9704,
      9896, 10087, 10278, 10469, 10659, 10849, 11039, 11228, 11417, 11605,
     11793, 11980, 12167, 12353, 12539, 12725, 12910, 13094, 13279, 13462,
     13645, 13828, 14010, 14191, 14372, 14553, 14732, 14912, 15090, 15269,
     15446, 15623, 15800, 15976, 16151, 16325, 16499, 16673, 16846, 17018,
     17189, 17360, 17530, 17700, 17869, 18037, 18204, 18371, 18537, 18703,
     18868, 19032, 19195, 19357, 19519, 19680, 19841, 20000, 20159, 20317,
     20475, 20631, 20787, 20942, 21096, 21250, 21403, 21554, 21705, 21856,
     22005, 22154, 22301, 22448, 22594, 22739, 22884, 23027, 23170, 23311,
     23452, 23592, 23731, 23870, 24007, 24143, 24279, 24413, 24547, 24680,
     24811, 24942, 25072, 25201, 25329, 25456, 25582, 25708, 25832, 25955,
     26077, 26198, 26319, 26438, 26556, 26674, 26790, 26905, 27019, 27133,
     27245, 27356, 27466, 27575, 27683, 27790, 27896, 28001, 28105, 28208,
     28310, 28411, 28510, 28609, 28706, 28803, 28898, 28992, 29085, 29177,
     29268, 29358, 29447, 29534, 29621, 29706, 29791, 29874, 29956, 30037,
     30117, 30195, 30273, 30349, 30424, 30498, 30571, 30643, 30714, 30783,
     30852, 30919, 30985, 31050, 31113, 31176, 31237, 31297, 31356, 31414,
     31470, 31526, 31580, 31633, 31685, 31736, 31785, 31833, 31880, 31926,
     31971, 32014, 32057, 32098, 32137, 32176, 32213, 32250, 32285, 32318,
     32351, 32382, 32412, 32441, 32469, 32495, 32521, 32545, 32567, 32589,
     32609, 32628, 32646, 32663, 32678, 32692, 32705, 32717, 32728, 32737,
     32745, 32752, 32757, 32761, 32765, 32766, 32767
     };
    Last edited by sonaben; 01-21-2022 at 12:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •