Basic implementation
Assuming you have successfully implemented the passthrough, you can simply copy and paste that project from within the STM32CubeIDE environment. We recommend choosing a name with the current date and "alien_voice"
in it. Remember to delete the old binary (ELF) file inside the copied project.
Lookup table
Remember that in the passthrough we set up the system to work with a sampling frequency of 32KHz and a sample precision of 16 bits. Here we will use a modulation frequency of 400Hz for the frequency shifting, so that the digital frequency is a rational multiple of as in the previous example:
The values for one period of the digital sinusoid can be encoded in a circular lookup table of length 80, where each element is (in 16-bit precision)
The lookup table is provided here for your convenience. Begin by copying it between the USER CODE BEGIN PV
and USER CODE END PV
comment tags.
TASK 1: Write a short Python function that prints out the above table given a value for the period of the sinusoid.
Gain
Let's also define a gain factor to increase the output volume. As we said before, we will use a gain that is a power of two and therefore just define its exponent. If you find that the sound is distorted, you may want to reduce this number.
The processing function
In the following version of the main processing function you will need to provide a couple of lines yourself. In the meantime please note the following:
we are assuming that we're using the LEFT channel for the microphone and we go through the input buffer two samples at a time, while we duplicate the output to produce a signal to both ears.
ix
is the state variable that keeps track of our position in the lookup table. Since the alien voice is an instantaneous transformation, this is the only global time reference that we need to havethe function also implements a simple DC notch. Since this filter only requires memory of a single past input sample, there is no need to implement a circular buffer and we just use a single static variable in the function
the multiplications should be performed using 32-bit integers and the result is scaled back to 16 bits; we take the gain into account in this rescaling.
TASK 2: Complete the function to perform sinusoidal modulation.
Now place the function between the USER CODE BEGIN 4
and USER CODE END 4
comment tags and test the application!
Going further
You can now try changing the modulation frequency by creating your own lookup tables!
Solutions
Are you sure you are ready to see the solution? ;)
Last updated