Creating waveform using the lamda function and jmap

In the JUCE DSP Tutorial, different waveforms are created using a lamda function and the jmap function.

Can someone help me dig a little deeper to understand the relationship of the lamda function with jmap?

More importantly, how does the jmap function and its parameters help create the saw wave? Can someone walk me through that DSP concept/algorithm a little more than what the tutorial says?

Since we do not have access to a std version of a sawtooth function, we need to implement a manual mapping of values using the jmap function. To do this, map the range between -Pi … Pi to -1 … 1 providing a linear ramp from -1 to 1. Since a sawtooth only has 2 breakpoints, we need only supply 2 discrete points to the lookup table.

processorChain.template get<oscIndex>().initialise ([] (Type x)
            {
               return juce::jmap (x,
                                  Type (-juce::MathConstants<double>::pi),
                                  Type (juce::MathConstants<double>::pi),
                                  Type (-1),
                                  Type (1));
            }, 128);
            break;


I notice similar jmaps used in the next tutorial for waveshapers...

Thanks
-Mike

The jmap is simply used as a “straight line” (sawtooth) function in this case that is used for the oscillator wavetable. The jmap function does nothing special but is very useful when you need to convert values from one range into another range. In this case it used to map values in the range -pi to pi into the range -1.0 to 1.0.

If a sine wave was needed, the lambda could just do :

return std::sin(x);