This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next 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 19:54] – [Processing Audio and Sending to Class D Board via A2B] Chad Wentworth | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | The Class D Fin contains two stereo class D amplifiers providing four channels of output. | ||
- | ==== Generating Digital Filter Coefficients ==== | + | The SSM3582 has an option to combine a two channels into a single channel with more power. |
- | To generate our digital filter coefficients for the low-pass filter | + | We will send the incoming stereo audio from the 1/8" jacks to the first SSM3582 on the Class D board. |
- | Also, if you don't have Python installed, you can use an online interpreter such as this one: https:// | + | Connect a set of standard speakers to the speaker terminals for the first stereo pair on the Class D board, and connect |
- | <code python> | + | Connect your Class D amp board via the A2B cable to the SHARC Audio Module. |
- | from scipy import signal | + | |
- | import numpy as np | + | |
- | from pprint import * | + | |
- | fs = 48000.0 | + | Configure the baremetal framework to use A2B and select the SAM-> |
- | nyq = 0.5*fs | + | |
- | # Cutoff frequency | + | <code c> |
- | cutoff = 300 | + | #define ENABLE_A2B |
- | filter_order = 8 | + | |
- | # Genearte filter coefficients | + | #if (ENABLE_A2B) |
- | b, a = signal.butter(filter_order, cutoff/nyq) | + | /** |
+ | * 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 | ||
- | # Flip order of A coefficients and drop the first normalized 1.0 coefficient | ||
- | a = np.flipud(a) | ||
- | a = np.delete(a, | ||
- | # Generate C code | + | /** |
- | print(" | + | * If this SHARC Audio Module board is a master, select an A2B topology |
- | indx = 0 | + | * |
- | for coeff in a: | + | * Note that these topologies are created in SigmaStudio and stored |
- | line = "\t " | + | * within drivers/ |
- | if indx < filter_order - 1: | + | * full description of these configurations. |
- | line += "," | + | * NOTE: SET ONLY ONE TO TRUE |
- | | + | */ |
- | 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(" | + | |
- | </ | + | |
+ | // Add your own pre-processor variables for custom A2B topologies here | ||
+ | # | ||
- | ==== Implementing the Digital Filter ==== | + | # |
+ | </ | ||
- | CCES also comes with a set of libraries | + | ==== Setting up our Biquad filters ==== |
+ | We'll use a fourth order low-pass IIR filter | ||
- | For the IIR we' | + | First, |
- | We'll start by using the software library since we have plenty of MIPS and IIR filters are small and efficient. | + | <code c> |
+ | BIQUAD_FILTER lpf_stage1, lpf_stage2; | ||
+ | float pm coeffs_stage1[6], | ||
+ | </ | ||
- | The filters library in CCES includes a function called iir() that we'll be using. | + | Next, we' |
- | + | ||
- | Just like in the other tutorials, 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) { |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | | ||
+ | // Finally, we'll copy our input buffers to the first two A2B channels, and our filtered data to our second two A2B channels. | ||
| | ||
- | float pm lowpass_b_coeffs[9]={ | + | // Original stereo audio to our stereo speakers |
- | | + | |
- | 1.5997872384052218e-13, | + | |
- | | + | |
- | 1.1198510668836553e-12, | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | 1.9997340480065266e-14 | + | |
- | }; | + | |
- | float lowpass_state[9] = {0}; | ||
</ | </ | ||
- | + | ---- | |
+ | {{navigation SHARC Audio Module# |