diff --git a/README.md b/README.md index bf83085..7059561 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ On the other side many of the modules are fairly easy to reverse engineer, and c ## Supported DSPs -Only the ADAU1701 is supported for now. I'm planing to add the ADAU1442/ADAU1445/ADAU1446 in the future. +Only the ADAU1701, ADAU1702 and ADAU1401 are supported. ## Exporting a SigmaStudio project for use with the SigmaDSP library diff --git a/examples/0_Template/0_Template.ino b/examples/0_Template/0_Template.ino index 5d1b6f2..7adca77 100644 --- a/examples/0_Template/0_Template.ino +++ b/examples/0_Template/0_Template.ino @@ -19,9 +19,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode diff --git a/examples/1_Volume/1_Volume.ino b/examples/1_Volume/1_Volume.ino index 7c97a0a..87266e7 100644 --- a/examples/1_Volume/1_Volume.ino +++ b/examples/1_Volume/1_Volume.ino @@ -19,9 +19,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode @@ -82,4 +82,4 @@ void loop() dsp.volume_slew(MOD_SWVOL1_ALG0_TARGET_ADDR, i); // Slew rate is default 12 delay(200); } -} \ No newline at end of file +} diff --git a/examples/2_First_order_EQ/2_First_order_EQ.ino b/examples/2_First_order_EQ/2_First_order_EQ.ino index 076a0f1..185d1eb 100644 --- a/examples/2_First_order_EQ/2_First_order_EQ.ino +++ b/examples/2_First_order_EQ/2_First_order_EQ.ino @@ -20,9 +20,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode diff --git a/examples/3_Second_order_EQ/3_Second_order_EQ.ino b/examples/3_Second_order_EQ/3_Second_order_EQ.ino index 0ce5c27..d095c4d 100644 --- a/examples/3_Second_order_EQ/3_Second_order_EQ.ino +++ b/examples/3_Second_order_EQ/3_Second_order_EQ.ino @@ -7,7 +7,7 @@ | a master volume slider. | | | | See the SigmaStudio project file if you want | -| to learn more, tweak or do modifications. | +| to learn more, tweak or do modifications. | |**********************************************/ // Include Wire and SigmaDSP library @@ -20,9 +20,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode @@ -39,8 +39,8 @@ secondOrderEQ eqBand2; secondOrderEQ eqBand3; secondOrderEQ eqBand4; -void setup() -{ +void setup() +{ Serial.begin(9600); Serial.println(F("3_Second_order_EQ example\n")); @@ -50,14 +50,14 @@ void setup() delay(2000); - + Serial.println(F("Pinging i2c lines...\n0 -> deveice is present\n2 -> device is not present")); Serial.print(F("DSP response: ")); Serial.println(dsp.ping()); //Serial.print(F("EEPROM ping: ")); //Serial.println(ee.ping()); - - + + // Use this step if no EEPROM is present Serial.print(F("\nLoading DSP program... ")); loadProgram(dsp); @@ -93,8 +93,8 @@ void setup() } -void loop() -{ +void loop() +{ // Adjust band 1 Serial.println(F("+10dB boost at 80Hz (band1)")); eqBand1.freq = 80; @@ -154,5 +154,5 @@ void loop() eqBand4.boost = i; dsp.EQsecondOrder(MOD_MIDEQ1_ALG0_STAGE3_B0_ADDR, eqBand4); delay(500); - } + } } diff --git a/examples/4_State_variable_filter/4_State_variable_filter.ino b/examples/4_State_variable_filter/4_State_variable_filter.ino index 7c925ac..69a77b6 100644 --- a/examples/4_State_variable_filter/4_State_variable_filter.ino +++ b/examples/4_State_variable_filter/4_State_variable_filter.ino @@ -8,7 +8,7 @@ | highpass and bandpass option. | | | | See the SigmaStudio project file if you want | -| to learn more, tweak or do modifications. | +| to learn more, tweak or do modifications. | |**********************************************/ // Include Wire and SigmaDSP library @@ -21,9 +21,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode @@ -37,8 +37,8 @@ SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); // Variable to store calculated sweep tone uint16_t frequency; -void setup() -{ +void setup() +{ Serial.begin(9600); Serial.println(F("SigmaDSP 4_State_variable_filter example\n")); @@ -48,14 +48,14 @@ void setup() delay(2000); - + Serial.println(F("Pinging i2c bus...\n0 -> deveice is present\n2 -> device is not present")); Serial.print(F("DSP response: ")); Serial.println(dsp.ping()); //Serial.print(F("EEPROM ping: ")); //Serial.println(ee.ping()); - - + + // Use this step if no EEPROM is present Serial.print(F("\nLoading DSP program... ")); loadProgram(dsp); @@ -73,7 +73,7 @@ void setup() } -void loop() +void loop() { Serial.print(F("F=500Hz Q=0.71")); dsp.stateVariable(MOD_STATEVARFILTER1_ALG0_STATEVARALG1FREQ_ADDR, 500, 0.71); diff --git a/examples/5_Signal_generator/5_Signal_generator.ino b/examples/5_Signal_generator/5_Signal_generator.ino index 5e75252..d652d99 100644 --- a/examples/5_Signal_generator/5_Signal_generator.ino +++ b/examples/5_Signal_generator/5_Signal_generator.ino @@ -6,7 +6,7 @@ | This example we use the DSP as a crude | | Signal generator. | | See the SigmaStudio project file if you want | -| to learn more, tweak or do modifications. | +| to learn more, tweak or do modifications. | |**********************************************/ // Include Wire and SigmaDSP library @@ -19,9 +19,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode @@ -34,8 +34,8 @@ SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); // Variable to store calculated sweep tone uint16_t frequency; -void setup() -{ +void setup() +{ Serial.begin(9600); Serial.println(F("5_Signal_generator example\n")); @@ -45,14 +45,14 @@ void setup() delay(2000); - + Serial.println(F("Pinging i2c bus...\n0 -> deveice is present\n2 -> device is not present")); Serial.print(F("DSP response: ")); Serial.println(dsp.ping()); //Serial.print(F("EEPROM ping: ")); //Serial.println(ee.ping()); - - + + // Use this step if no EEPROM is present Serial.print(F("\nLoading DSP program... ")); loadProgram(dsp); @@ -70,7 +70,7 @@ void setup() } -void loop() +void loop() { Serial.println(F("Sine sweep")); dsp.mux(MOD_WAVEFORM_SELECT_MONOSWSLEW_ADDR, 0); diff --git a/examples/6_Dynamic_bass_boost/6_Dynamic_bass_boost.ino b/examples/6_Dynamic_bass_boost/6_Dynamic_bass_boost.ino index 6c526ba..9dc5478 100644 --- a/examples/6_Dynamic_bass_boost/6_Dynamic_bass_boost.ino +++ b/examples/6_Dynamic_bass_boost/6_Dynamic_bass_boost.ino @@ -19,9 +19,9 @@ // The first parameter is the Wire object we'll be using when communicating wth the DSP // The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type +// The third parameter is the sample rate // An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); // Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode diff --git a/examples/7_Signal_detect_readout/7_Signal_detect_readout.ino b/examples/7_Signal_detect_readout/7_Signal_detect_readout.ino index e67e80d..204f634 100644 --- a/examples/7_Signal_detect_readout/7_Signal_detect_readout.ino +++ b/examples/7_Signal_detect_readout/7_Signal_detect_readout.ino @@ -1,97 +1,97 @@ -/***********************************************| -| SigmaDSP library | -| https://github.com/MCUdude/SigmaDSP | -| | -| 7_Signal_detect_readout.ino | -| This example we use the DSP to boost the bass | -| using the Dynamic enhancement block. | -| See the SigmaStudio project file if you want | -| to learn more, tweak or do modifications. | -|***********************************************/ - -// Include Wire and SigmaDSP library -#include -#include - -// Include generated parameter file -#include "SigmaDSP_parameters.h" - - -// The first parameter is the Wire object we'll be using when communicating wth the DSP -// The second parameter is the DSP i2c address, which is defined in the parameter file -// The third parameter is the SigmaDSP type -// An optional fourth parameter is the pin to physically reset the DSP -SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, ADAU1701 /*,12*/); - - -// Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode -// The first parameter is the Wire object we'll be using when communicating wth the EEPROM -// The second parameter is the EEPROM i2c address, which is defined in the parameter file -// The third parameter is the EEPROM size in kilobits (kb) -// An optional fourth parameter is the pin to toggle while writing content to EEPROM -//DSPEEPROM ee(Wire, EEPROM_I2C_ADDRESS, 256, LED_BUILTIN); - -// Variables to hold the current signal detect value -uint32_t previousLevelLeft = 1; -uint32_t previousLevelRight = 1; -uint32_t currentLevelLeft = 0; -uint32_t currentLevelRight = 0; - -void setup() -{ - Serial.begin(9600); - Serial.println(F("7_Signal_detect_readout example\n")); - - Wire.begin(); - dsp.begin(); - //ee.begin(); - - delay(2000); - - - Serial.println(F("Pinging i2c bus...\n0 -> deveice is present\n2 -> device is not present")); - Serial.print(F("DSP response: ")); - Serial.println(dsp.ping()); - //Serial.print(F("EEPROM ping: ")); - //Serial.println(ee.ping()); - - - // Use this step if no EEPROM is present - // For some reaon, the noise filter in the DSP program causes - // a somewhat loud click when the program is loaded. - // This is prevented by muting and unmuting the ADC - dsp.muteADC(true); - Serial.print(F("\nLoading DSP program... ")); - loadProgram(dsp); - Serial.println("Done!\n"); - dsp.muteADC(false); - delay(1000); - - - - // Comment out the three code lines above and use this step instead if EEPROM is present - // The last parameter in writeFirmware is the FW version, and prevents the MCU from overwriting on every reboot - //ee.writeFirmware(DSP_eeprom_firmware, sizeof(DSP_eeprom_firmware), 0); - //dsp.reset(); - //delay(2000); // Wait for the FW to load from the EEPROM -} - - -void loop() -{ - // Read the signal detect block for each channel - currentLevelLeft = dsp.readBack(MOD_SIGNAL_DETECTION_READOUT_LEFT_ALG0_VAL0_ADDR, MOD_SIGNAL_DETECTION_READOUT_LEFT_ALG0_VAL0_VALUES, 3); - currentLevelRight = dsp.readBack(MOD_SIGNAL_DETECTION_READOUT_RIGHT_ALG0_VAL0_ADDR, MOD_SIGNAL_DETECTION_READOUT_RIGHT_ALG0_VAL0_VALUES, 3); - - // Print message if there is a change on one of the channels - if(currentLevelLeft != previousLevelLeft || currentLevelRight != previousLevelRight) - { - previousLevelLeft = currentLevelLeft; - previousLevelRight = currentLevelRight; - Serial.print(F("Signal on left channel: ")); - Serial.print((bool)!currentLevelLeft); - Serial.print(F("\tSignal on right channel: ")); - Serial.println((bool)!currentLevelRight); - } - delay(1000); -} +/***********************************************| +| SigmaDSP library | +| https://github.com/MCUdude/SigmaDSP | +| | +| 7_Signal_detect_readout.ino | +| This example we use the DSP to boost the bass | +| using the Dynamic enhancement block. | +| See the SigmaStudio project file if you want | +| to learn more, tweak or do modifications. | +|***********************************************/ + +// Include Wire and SigmaDSP library +#include +#include + +// Include generated parameter file +#include "SigmaDSP_parameters.h" + + +// The first parameter is the Wire object we'll be using when communicating wth the DSP +// The second parameter is the DSP i2c address, which is defined in the parameter file +// The third parameter is the sample rate +// An optional fourth parameter is the pin to physically reset the DSP +SigmaDSP dsp(Wire, DSP_I2C_ADDRESS, 48000.00f /*,12*/); + + +// Only needed if an external i2c EEPROM is present + the DSP is in selfboot mode +// The first parameter is the Wire object we'll be using when communicating wth the EEPROM +// The second parameter is the EEPROM i2c address, which is defined in the parameter file +// The third parameter is the EEPROM size in kilobits (kb) +// An optional fourth parameter is the pin to toggle while writing content to EEPROM +//DSPEEPROM ee(Wire, EEPROM_I2C_ADDRESS, 256, LED_BUILTIN); + +// Variables to hold the current signal detect value +uint32_t previousLevelLeft = 1; +uint32_t previousLevelRight = 1; +uint32_t currentLevelLeft = 0; +uint32_t currentLevelRight = 0; + +void setup() +{ + Serial.begin(9600); + Serial.println(F("7_Signal_detect_readout example\n")); + + Wire.begin(); + dsp.begin(); + //ee.begin(); + + delay(2000); + + + Serial.println(F("Pinging i2c bus...\n0 -> deveice is present\n2 -> device is not present")); + Serial.print(F("DSP response: ")); + Serial.println(dsp.ping()); + //Serial.print(F("EEPROM ping: ")); + //Serial.println(ee.ping()); + + + // Use this step if no EEPROM is present + // For some reaon, the noise filter in the DSP program causes + // a somewhat loud click when the program is loaded. + // This is prevented by muting and unmuting the ADC + dsp.muteADC(true); + Serial.print(F("\nLoading DSP program... ")); + loadProgram(dsp); + Serial.println("Done!\n"); + dsp.muteADC(false); + delay(1000); + + + + // Comment out the three code lines above and use this step instead if EEPROM is present + // The last parameter in writeFirmware is the FW version, and prevents the MCU from overwriting on every reboot + //ee.writeFirmware(DSP_eeprom_firmware, sizeof(DSP_eeprom_firmware), 0); + //dsp.reset(); + //delay(2000); // Wait for the FW to load from the EEPROM +} + + +void loop() +{ + // Read the signal detect block for each channel + currentLevelLeft = dsp.readBack(MOD_SIGNAL_DETECTION_READOUT_LEFT_ALG0_VAL0_ADDR, MOD_SIGNAL_DETECTION_READOUT_LEFT_ALG0_VAL0_VALUES, 3); + currentLevelRight = dsp.readBack(MOD_SIGNAL_DETECTION_READOUT_RIGHT_ALG0_VAL0_ADDR, MOD_SIGNAL_DETECTION_READOUT_RIGHT_ALG0_VAL0_VALUES, 3); + + // Print message if there is a change on one of the channels + if(currentLevelLeft != previousLevelLeft || currentLevelRight != previousLevelRight) + { + previousLevelLeft = currentLevelLeft; + previousLevelRight = currentLevelRight; + Serial.print(F("Signal on left channel: ")); + Serial.print((bool)!currentLevelLeft); + Serial.print(F("\tSignal on right channel: ")); + Serial.println((bool)!currentLevelRight); + } + delay(1000); +} diff --git a/src/SigmaDSP.cpp b/src/SigmaDSP.cpp index fd47236..a321d0a 100644 --- a/src/SigmaDSP.cpp +++ b/src/SigmaDSP.cpp @@ -7,14 +7,14 @@ /** * @brief Construct a new SigmaDSP::SigmaDSP object - * + * * @param WireObject TwoWire i2c object * @param i2cAddress 7-bit i2c address - * @param device The DSP type in use + * @param sample_freq The audio sample frequency in [Hz] * @param resetPin pin to reset the DSP with (optional parameter) */ -SigmaDSP::SigmaDSP(TwoWire &WireObject, uint8_t i2cAddress, uint8_t device, int8_t resetPin) - : _WireObject(WireObject), _dspAddress(i2cAddress), _deviceType(device), _resetPin(resetPin) +SigmaDSP::SigmaDSP(TwoWire &WireObject, uint8_t i2cAddress, float sample_freq, int8_t resetPin) + : FS(sample_freq), _WireObject(WireObject), _dspAddress(i2cAddress), _resetPin(resetPin) { } @@ -37,7 +37,7 @@ void SigmaDSP::begin() /** * @brief Sets the i2c clock speed - * + * * @param clock i2c clock speed in [Hz] */ void SigmaDSP::i2cClock(uint32_t clock) @@ -62,7 +62,7 @@ void SigmaDSP::reset() /** * @brief Sends an i2c ping message - * + * * @return ping receive status; * 0 - success: ack received; * 2 - error: address send, nack received; @@ -78,7 +78,7 @@ uint8_t SigmaDSP::ping() /** * @brief Controls a mux. The mux can only be a single address block, which is the clickless SW slew mux - * + * * @param startMemoryAddress DSP memory address * @param index Index (the signal) you want to switch to (0, 1, 2, ..., N) * @param numberOfIndexes The total number of indexes (2 or more) @@ -94,7 +94,7 @@ void SigmaDSP::mux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberOfI /** * @brief Controls a demux - * + * * @param startMemoryAddress DSP memory address * @param index Index (the signal) you want to switch to (0, 1, 2, ..., N) * @param numberOfIndexes The total number of indexes (2 or more) @@ -119,7 +119,7 @@ void SigmaDSP::demux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberO /** * @brief Adjusts a gain block - * + * * @param startMemoryAddress DSP memory address * @param gain Gain value (1 = 0dB gain, 2 = +6dB gain) * @param channels Number of channels this gain cell has (defaults to 1 if not defined) @@ -134,7 +134,7 @@ void SigmaDSP::gain(uint16_t startMemoryAddress, float gain, uint8_t channels) /** * @brief Adjusts a gain block - * + * * @param startMemoryAddress DSP memory address * @param gain Gain value (1 = 0dB gain, 2 = +6dB gain) * @param channels Number of channels this gain cell has (defaults to 1 if not defined) @@ -153,7 +153,7 @@ void SigmaDSP::gain(uint16_t startMemoryAddress, int32_t gain, uint8_t channels) /** * @brief Controls a volume control block with slew - * + * * @param startMemoryAddress DSP memory address * @param dB Volume to set in dB * @param slew slew rate (optional parameter, default 12) @@ -169,7 +169,7 @@ void SigmaDSP::volume_slew(uint16_t startMemoryAddress, float dB, uint8_t slew) /** * @brief Controls the dynamic bass boost level block in dB - * + * * @param startMemoryAddress DSP memory address * @param dB Bass boost level in dB (0 to +20dB) */ @@ -183,7 +183,7 @@ void SigmaDSP::dynamicBass(uint16_t startMemoryAddress, float dB) /** * @brief Controls a hard clip block with separate negative and positive thresholds - * + * * @param startMemoryAddress DSP memory address * @param highThreshold High threshold (0.0 to 1.0) * @param lowThreshold Low threshold (-1.0 to 0.0) @@ -196,7 +196,7 @@ void SigmaDSP::hardClip(uint16_t startMemoryAddress, float highThreshold, float /** * @brief Controls a soft clip block with adjustable curve - * + * * @param startMemoryAddress DSP memory address * @param alpha Clipping coefficient (0.1 to 10.0) */ @@ -211,7 +211,7 @@ void SigmaDSP::softClip(uint16_t startMemoryAddress, float alpha) /** * @brief Controls a DC source block - * + * * @param startMemoryAddress DSP memory address * @param level DC value level range (-1.0 to 1.0) */ @@ -223,7 +223,7 @@ void SigmaDSP::dcSource(uint16_t startMemoryAddress, float level) /** * @brief Controls a sine wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Sine wave frequency in [Hz] */ @@ -236,7 +236,7 @@ void SigmaDSP::sineSource(uint16_t startMemoryAddress, float frequency) /** * @brief Controls a sine wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Sine wave frequency in [Hz] */ @@ -251,7 +251,7 @@ void SigmaDSP::sineSource(uint16_t startMemoryAddress, int32_t frequency) /** * @brief Controls a square wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Square wave frequency in [Hz] */ @@ -260,7 +260,7 @@ void SigmaDSP::squareSource(uint16_t startMemoryAddress, float frequency) { sine /** * @brief Controls a sine wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Square wave frequency in [Hz] */ @@ -269,7 +269,7 @@ void SigmaDSP::squareSource(uint16_t startMemoryAddress, int32_t frequency) { si /** * @brief Controls a sawtooth source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Sawtooth frequency in [Hz] */ @@ -283,7 +283,7 @@ void SigmaDSP::sawtoothSource(uint16_t startMemoryAddress, float frequency) /** * @brief Controls a sawtooth source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Sawtooth frequency in [Hz] */ @@ -298,7 +298,7 @@ void SigmaDSP::sawtoothSource(uint16_t startMemoryAddress, int32_t frequency) /** * @brief Controls a triangle wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Triangle wave frequency in [Hz] */ @@ -312,7 +312,7 @@ void SigmaDSP::triangleSource(uint16_t startMemoryAddress, float frequency) /** * @brief Controls a triangle wave source block - * + * * @param startMemoryAddress DSP memory address * @param frequency Triangle wave frequency in [Hz] */ @@ -327,12 +327,12 @@ void SigmaDSP::triangleSource(uint16_t startMemoryAddress, int32_t frequency) /** * @brief Controls an audio delay block - * - * Delay ranges: + * + * Delay ranges: * 0.0-42.6ms (ADAU170x) @ 48kHz; * 0.0-21.3ms (ADAU170x) @ 96kHz; - * 0.0-10.6ms (ADAU170x) @ 192kHz; - * + * 0.0-10.6ms (ADAU170x) @ 192kHz; + * * WARNING! Delays calculated are theoretical assuming you * have 100% data memory available in your Sigma Studio design. * Data memory is shared among other blocks in Sigma Studio so @@ -341,7 +341,7 @@ void SigmaDSP::triangleSource(uint16_t startMemoryAddress, int32_t frequency) * for its processing. The SigmaStudio compiler manages the data * RAM and indicates if the number of addresses needed in the * design exceeds the maximum available. - * + * * @param startMemoryAddress DSP memory address * @param delayMs Delay value in [ms] */ @@ -358,7 +358,7 @@ void SigmaDSP::audioDelay(uint16_t startMemoryAddress, float delayMs) /** * @brief Controls a first order EQ block - * + * * @param startMemoryAddress DSP memory address * @param equalizer Equalizer parameter struct */ @@ -417,7 +417,7 @@ void SigmaDSP::EQfirstOrder(uint16_t startMemoryAddress, firstOrderEQ_t &equaliz /** * @brief Controls a second order EQ block - * + * * @param startMemoryAddress DSP memory address * @param equalizer Equalizer parameter struct */ @@ -594,7 +594,7 @@ void SigmaDSP::EQsecondOrder(uint16_t startMemoryAddress, secondOrderEQ_t &equal /** * @brief Controls a baxandall low-high dual tone control block - * + * * @param startMemoryAddress DSP memory address * @param toneCtrl Tone control parameter struct */ @@ -668,7 +668,7 @@ void SigmaDSP::toneControl(uint16_t startMemoryAddress, toneCtrl_t &toneCtrl) /** * @brief Controls a state variable filter block - * + * * @param startMemoryAddress DSP memory address * @param frequency Filter frequency (1 to 19148 Hz) * @param q Filter Q value (1.28 to 10.00) @@ -685,7 +685,7 @@ void SigmaDSP::stateVariable(uint16_t startMemoryAddress, float frequency, float /** * @brief Calculates the curve and the other parameters of an RMS compressor block. * Set ratio = 1 to disable compressor - * + * * @param startMemoryAddress DSP memory address * @param compressor Compressor parameter struct */ @@ -767,9 +767,9 @@ void SigmaDSP::compressorRMS(uint16_t startMemoryAddress, compressor_t &compress /** - * @brief This function calculates the curve and the other parameters of a peak compressor block. + * @brief This function calculates the curve and the other parameters of a peak compressor block. Set ratio = 1 to disable compressor - * + * * @param startMemoryAddress DSP memory address * @param compressor Compressor parameter struct */ @@ -842,7 +842,7 @@ void SigmaDSP::compressorPeak(uint16_t startMemoryAddress, compressor_t &compres /** * @brief Mutes the internal analog to digital converter in the DSP - * + * * @param mute Mute state. Muted if true, unmuted if false */ void SigmaDSP::muteADC(bool mute) @@ -866,7 +866,7 @@ void SigmaDSP::muteADC(bool mute) /** * @brief Mutes the internal digital to analog in the DSP - * + * * @param mute Mute state. Muted if true, unmuted if false */ void SigmaDSP::muteDAC(bool mute) @@ -890,7 +890,7 @@ void SigmaDSP::muteDAC(bool mute) /** * @brief Writes 5 bytes of data to the parameter memory of the DSP. The first byte is 0x00 - * + * * @param memoryAddress DSP memory address * @param data Data array to write * @param finished Indicates if this is the last packet or not @@ -898,7 +898,7 @@ void SigmaDSP::muteDAC(bool mute) void SigmaDSP::safeload_writeRegister(uint16_t memoryAddress, uint8_t *data, bool finished) { static uint8_t _safeload_count = 0; // Keeps track of the safeload count - + uint8_t addr[2]; // Address array addr[0] = (memoryAddress >> 8) & 0xFF; @@ -926,7 +926,7 @@ void SigmaDSP::safeload_writeRegister(uint16_t memoryAddress, uint8_t *data, boo /** * @brief Writes 28.0 data to the parameter memory of the DSP. - * + * * @param memoryAddress DSP memory address * @param data Data array to write * @param finished Indicates if this is the last packet or not @@ -940,7 +940,7 @@ void SigmaDSP::safeload_writeRegister(uint16_t memoryAddress, int32_t data, bool /** * @brief Writes 5.23 data to the parameter memory of the DSP. - * + * * @param memoryAddress DSP memory address * @param data Data array to write * @param finished Indicates if this is the last packet or not @@ -965,7 +965,7 @@ void SigmaDSP::safeload_writeRegister(uint16_t memoryAddress, double data, bo /** * @brief Writes data to the DSP (max 32 bytes a time due to the default i2c buffer size of the Wire library) - * + * * @param memoryAddress DSP memory address * @param length Number of bytes to write * @param data Data array to write @@ -989,7 +989,7 @@ void SigmaDSP::writeRegister(uint16_t memoryAddress, uint8_t length, uint8_t *da /** * @brief Writes data to the DSP from PROGMEM (max 32 bytes a time due to the default i2c buffer size of the Wire library) - * + * * @param memoryAddress DSP memory address * @param length Number of bytes to write * @param data Data array to write @@ -1013,7 +1013,7 @@ void SigmaDSP::writeRegister(uint16_t memoryAddress, uint8_t length, const uint8 /** * @brief Writes data to the DSP from PROGMEM - * + * * @param memoryAddress DSP memory address * @param length Number of bytes to write * @param data Data array to write @@ -1049,7 +1049,7 @@ void SigmaDSP::writeRegisterBlock(uint16_t memoryAddress, uint16_t length, const /** * @brief Reads a DSP memory block - * + * * @param memoryAddress DSP memory address * @param readout Which register to read * @param numberOfBytes How manu bytes to read @@ -1087,7 +1087,7 @@ int32_t SigmaDSP::readBack(uint16_t memoryAddress, uint16_t readout, uint8_t num /** * @brief Reads a DSP hardware register - * + * * @param reg DSP register address * @param numberOfBytes Number of bytes to read from the register * @return uint32_t value the register contains @@ -1113,7 +1113,7 @@ uint32_t SigmaDSP::readRegister(dspRegister reg, uint8_t numberOfBytes) /** * @brief Converts a 5.23 float value to 5-byte HEX and stores it in the passed buffer - * + * * @param value Value to convert * @param buffer Buffer to store the converted data in */ @@ -1133,7 +1133,7 @@ void SigmaDSP::floatToFixed(float value, uint8_t *buffer) /** * @brief Converts a 28.0 integer value to 5-byte HEX and stores it the passed buffer - * + * * @param value Value to convert * @param buffer Buffer to store the converted data in */ @@ -1150,7 +1150,7 @@ void SigmaDSP::intToFixed(int32_t value, uint8_t *buffer) /** * @brief Converts a 5.23 float value to int 28.0 - * + * * @param value Value to convert * @return int32_t converted value in 28.0 format */ @@ -1168,7 +1168,7 @@ int32_t SigmaDSP::floatToInt(float value) /** * @brief Calculates the points of a linearly spaced vector - * + * * @param x1 Start point * @param x2 End point * @param n Number of points to calculate diff --git a/src/SigmaDSP.h b/src/SigmaDSP.h index 877107f..66c85e3 100644 --- a/src/SigmaDSP.h +++ b/src/SigmaDSP.h @@ -7,12 +7,9 @@ #include "parameters.h" #include "DSPEEPROM.h" -// Only ADAU1701 is supported at the moment -#define ADAU1701 0 - /** * @brief ADAU1701 hardware register constants - * + * */ typedef enum { @@ -55,7 +52,7 @@ class SigmaDSP { public: // Store passed device type and i2c address to private constants - SigmaDSP(TwoWire &WireObject, uint8_t i2cAddress, uint8_t device, int8_t resetPin = -1); + SigmaDSP(TwoWire &WireObject, uint8_t i2cAddress, float sample_freq, int8_t resetPin = -1); // Init and setup void begin(); @@ -64,8 +61,8 @@ class SigmaDSP uint8_t ping(); // DSP functions - void mux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberOfIndexes = 0); - void demux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberOfIndexes); + void mux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberOfIndexes = 0); + void demux(uint16_t startMemoryAddress, uint8_t index, uint8_t numberOfIndexes); void gain(uint16_t startMemoryAddress, float gainVal, uint8_t channels = 1); void gain(uint16_t startMemoryAddress, int32_t gainVal, uint8_t channels = 1); void gain(uint16_t startMemoryAddress, double gainVal, uint8_t channels = 1) { gain(startMemoryAddress, (float)gainVal, channels); } @@ -75,11 +72,11 @@ class SigmaDSP void gain(uint16_t startMemoryAddress, uint8_t gainVal, uint8_t channels = 1) { gain(startMemoryAddress, (int32_t)gainVal, channels); } void gain(uint16_t startMemoryAddress, int8_t gainVal, uint8_t channels = 1) { gain(startMemoryAddress, (int32_t)gainVal, channels); } - void volume_slew(uint16_t startMemoryAddress, float dB, uint8_t slew = 12); - void dynamicBass(uint16_t startMemoryAddress, float dB); - void hardClip(uint16_t startMemoryAddress, float highThreshold, float lowThreshold); - void softClip(uint16_t startMemoryAddress, float alpha); - void dcSource(uint16_t startMemoryAddress, float level); + void volume_slew(uint16_t startMemoryAddress, float dB, uint8_t slew = 12); + void dynamicBass(uint16_t startMemoryAddress, float dB); + void hardClip(uint16_t startMemoryAddress, float highThreshold, float lowThreshold); + void softClip(uint16_t startMemoryAddress, float alpha); + void dcSource(uint16_t startMemoryAddress, float level); void sineSource(uint16_t startMemoryAddress, float frequency); void sineSource(uint16_t startMemoryAddress, int32_t frequency); @@ -139,7 +136,7 @@ class SigmaDSP * @brief Template wrapper for safeload_writeRegister. * Handles both int 28.0 and float 5.23 formatted parameters. * You can add as many data parameters as you want - * + * * @param address DSP memory address * @param data1 First value to write * @param dataN Nth value to write @@ -170,6 +167,9 @@ class SigmaDSP int32_t readBack(uint16_t address, uint16_t value, uint8_t length); uint32_t readRegister(dspRegister hwReg, uint8_t numberOfBytes); + // Public constants + const float FS; // Sample rate in [Hz] + private: // Wrapper template functions for safeload template @@ -192,12 +192,11 @@ class SigmaDSP // Objects TwoWire &_WireObject; // Reference to passed Wire object - + // Private constants const uint8_t _dspAddress; // Passed device i2c address - const uint8_t _deviceType; // Passed device type const int8_t _resetPin; // Digital pin to reset the DSP - + // Private variables uint16_t _dspRegAddr; // Used by template safeload functions }; diff --git a/src/parameters.h b/src/parameters.h index de14c6e..bbbe6d0 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -1,12 +1,6 @@ #ifndef PARAMETERS_H #define PARAMETERS_H - -// Sample rate constants -#define FS 48000.00f -#define SR (uint32_t)(1.0f/FS) - - // Math constants #define pi 3.1415926f