This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
resources:tools-software:sharc-audio-module:baremetal:class-d-2-1-amp [11 Sep 2018 01:56] – Dan Ledger | resources:tools-software:sharc-audio-module:baremetal:class-d-2-1-amp [26 Feb 2019 20:03] (current) – Chad Wentworth | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Tutorial: Building a 2.1 Amplifier with the Class-D Module ====== | ||
- | ==== Generating Digital Filter Coefficients ==== | + | The Class D Fin contains two stereo class D amplifiers providing four channels of output. |
- | To generate our digital filter coefficients for the low-pass filter for our subwoofer | + | The SSM3582 has an option to combine a two channels into a single |
- | Also, if you don't have Python installed, you can use an online interpreter such as this one: https:// | + | We will send the incoming stereo audio from the 1/8" jacks to the first SSM3582 on the Class D board. |
- | <code python> | + | Connect a set of standard speakers to the speaker terminals for the first stereo pair on the Class D board, and connect a sub-woofer to either of the speaker terminals for the second stereo pair on the Class D board. |
- | from scipy import signal | + | |
- | import numpy as np | + | |
- | from pprint import * | + | |
- | fs = 48000.0 | + | Connect your Class D amp board via the A2B cable to the SHARC Audio Module. The SLAVE port of the SHARC Audio Module should be connected to the MASTER port of the Class D amp board. |
- | nyq = 0.5*fs | + | |
- | # Cutoff frequency | + | Configure the baremetal framework to use A2B and select the SAM-> |
- | cutoff = 300 | + | |
- | filter_order = 8 | + | |
- | # Genearte filter coefficients | + | <code c> |
- | b, a = signal.butter(filter_order, | + | #define ENABLE_A2B |
- | # Flip order of A coefficients and drop the first normalized 1.0 coefficient | + | #if (ENABLE_A2B) |
- | a = np.flipud(a) | + | /** |
- | a = np.delete(a, 8) | + | * If A2B is enabled, select the role that this SHARC Audio Module board |
+ | * will play (TRUE = master node, FALSE = slave node) | ||
+ | */ | ||
+ | #define A2B_ROLE_MASTER | ||
- | # Generate C code | ||
- | print(" | ||
- | indx = 0 | ||
- | for coeff in a: | ||
- | line = "\t " | ||
- | if indx < filter_order - 1: | ||
- | line += "," | ||
- | print(line) | ||
- | indx += 1 | ||
- | print(" | ||
- | print() | ||
- | print(" | ||
- | indx = 0 | ||
- | for coeff in b: | ||
- | line = "\t " | ||
- | if indx < filter_order: | ||
- | line += "," | ||
- | print(line) | ||
- | indx += 1 | ||
- | print(" | ||
- | print() | ||
- | print(" | ||
- | </ | ||
+ | /** | ||
+ | * If this SHARC Audio Module board is a master, select an A2B topology | ||
+ | | ||
+ | * Note that these topologies are created in SigmaStudio and stored | ||
+ | * within drivers/ | ||
+ | * full description of these configurations. | ||
+ | * NOTE: SET ONLY ONE TO TRUE | ||
+ | */ | ||
+ | #if (A2B_ROLE_MASTER) | ||
+ | #define A2B_TOPOLOGY_TDM8_SAM_to_SAM_2up_2down | ||
+ | #define A2B_TOPOLOGY_TDM8_SAM_to_SAM_to_SAM_4up_4down | ||
+ | #define A2B_TOPOLOGY_TDM8_SAM_to_CLASSD_4down | ||
+ | // Add your own pre-processor variables for custom A2B topologies here | ||
- | ==== Implementing the Digital Filter ==== | + | # |
- | CCES also comes with a set of libraries to perform efficient DSP processing on the SHARC processor. | + | # |
+ | </ | ||
- | For the IIR we' | + | ==== Setting up our Biquad filters ==== |
+ | We'll use a fourth order low-pass | ||
- | We' | + | First, we' |
- | The filters library in CCES includes a function called iir() that we'll be using. | + | <code c> |
+ | BIQUAD_FILTER lpf_stage1, lpf_stage2; | ||
+ | float pm coeffs_stage1[6], | ||
+ | </ | ||
- | Just like in the other tutorials, we' | + | Next, we' |
- | + | ||
- | At the top of this file, we'll include filter.h. | + | |
<code c> | <code c> | ||
- | #include <filter.h> | + | filter_setup(& |
+ | BIQUAD_TYPE_LPF, | ||
+ | BIQUAD_TRANS_MED, | ||
+ | coeffs_stage1, | ||
+ | 100.0, | ||
+ | 1.0, | ||
+ | 1.0, | ||
+ | AUDIO_SAMPLE_RATE); | ||
+ | filter_setup(& | ||
+ | BIQUAD_TYPE_LPF, | ||
+ | BIQUAD_TRANS_MED, | ||
+ | coeffs_stage2, | ||
+ | 100.0, | ||
+ | 1.0, | ||
+ | 1.0, | ||
+ | AUDIO_SAMPLE_RATE); | ||
</ | </ | ||
- | Above '' | + | ==== Processing Audio and Sending to Class D Board via A2B ==== |
- | The script generates code that looks like this: | + | Finally, in '' |
- | < | + | < |
- | float pm lowpass_a_coeffs[8]={ | + | void processaudio_callback(void) { |
- | 0.8176608028570787, | + | |
- | -6.705872978425353, | + | |
- | 24.06321770206317, | + | |
- | -49.346069358244485, | + | |
- | 63.251430120196574, | + | |
- | -51.89283337342353, | + | |
- | 26.611177558819215, | + | |
- | -7.798710473837536 }; | + | |
| | ||
- | float pm lowpass_b_coeffs[9]={ | + | // First we'll mix the L and R channels together |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | }; | + | |
- | + | | |
- | float lowpass_state[9] = {0}; | + | |
- | </ | + | |
+ | // Filtered audio to our sub speakers | ||
+ | copy_buffer(filter_mixed, | ||
+ | copy_buffer(filter_mixed, | ||
+ | </ | ||
+ | ---- | ||
+ | {{navigation SHARC Audio Module# |