|
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
- #include <Bounce.h>
-
-
-
-
-
- AudioPlaySdWav playWav1;
- AudioOutputI2S headphones;
-
-
- AudioEffectBitcrusher left_BitCrusher;
- AudioEffectBitcrusher right_BitCrusher;
-
-
- AudioConnection patchCord1(playWav1, 0, left_BitCrusher, 0);
- AudioConnection patchCord2(playWav1, 1, right_BitCrusher, 0);
- AudioConnection patchCord3(left_BitCrusher, 0, headphones, 0);
- AudioConnection patchCord4(right_BitCrusher, 0, headphones, 1);
-
-
-
- AudioControlSGTL5000 audioShield;
-
-
-
- #define SDCARD_CS_PIN 10
- #define SDCARD_MOSI_PIN 7
- #define SDCARD_SCK_PIN 14
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Bounce button0 = Bounce(0, 5);
- Bounce button1 = Bounce(1, 5);
- Bounce button2 = Bounce(2, 5);
-
- unsigned long SerialMillisecondCounter;
-
-
- int current_CrushBits = 16;
- int current_SampleRate = 44100;
-
-
- boolean compressorOn = false;
-
- void setup() {
-
-
- pinMode(0, INPUT_PULLUP);
- pinMode(1, INPUT_PULLUP);
- pinMode(2, INPUT_PULLUP);
- Serial.begin(38400);
-
-
-
- AudioMemory(40);
-
-
- audioShield.enable();
- audioShield.volume(0.7);
-
-
-
-
-
-
-
-
-
-
- SPI.setMOSI(SDCARD_MOSI_PIN);
- SPI.setSCK(SDCARD_SCK_PIN);
- if (!(SD.begin(SDCARD_CS_PIN))) {
-
- while (1) {
- Serial.println("Unable to access the SD card");
- delay(500);
- }
- }
-
- left_BitCrusher.bits(current_CrushBits);
- left_BitCrusher.sampleRate(current_SampleRate);
- right_BitCrusher.bits(current_CrushBits);
- right_BitCrusher.sampleRate(current_SampleRate);
-
-
-
-
-
-
- audioShield.autoVolumeControl(1, 1, 0, -6, 40, 20);
- audioShield.autoVolumeDisable();
- audioShield.audioPostProcessorEnable();
-
- SerialMillisecondCounter = millis();
- }
-
- int val;
-
- void loop() {
-
- if (millis() - SerialMillisecondCounter >= 5000) {
- Serial.print("Proc = ");
- Serial.print(AudioProcessorUsage());
- Serial.print(" (");
- Serial.print(AudioProcessorUsageMax());
- Serial.print("), Mem = ");
- Serial.print(AudioMemoryUsage());
- Serial.print(" (");
- Serial.print(AudioMemoryUsageMax());
- Serial.println(")");
- SerialMillisecondCounter = millis();
- AudioProcessorUsageMaxReset();
- AudioMemoryUsageMaxReset();
- }
-
-
-
- button0.update();
- button1.update();
- button2.update();
-
-
- if (! (playWav1.isPlaying())){
- playWav1.play("SDTEST1.WAV");
- }
-
- if (button0.fallingEdge()) {
-
- if (current_CrushBits >= 2) {
- current_CrushBits--;
- } else {
- current_CrushBits = 16;
- }
-
- left_BitCrusher.bits(current_CrushBits);
- left_BitCrusher.sampleRate(current_SampleRate);
- right_BitCrusher.bits(current_CrushBits);
- right_BitCrusher.sampleRate(current_SampleRate);
- Serial.print("Bitcrusher set to ");
- Serial.print(current_CrushBits);
- Serial.print(" Bit, Samplerate at ");
- Serial.print(current_SampleRate);
- Serial.println("Hz");
- }
-
- if (button1.fallingEdge()) {
-
- if (current_SampleRate >= 690) {
- current_SampleRate = current_SampleRate / 2;
- } else {
- current_SampleRate=44100;
- }
-
- left_BitCrusher.bits(current_CrushBits);
- left_BitCrusher.sampleRate(current_SampleRate);
- right_BitCrusher.bits(current_CrushBits);
- right_BitCrusher.sampleRate(current_SampleRate);
- Serial.print("Bitcrusher set to ");
- Serial.print(current_CrushBits);
- Serial.print(" Bit, Samplerate at ");
- Serial.print(current_SampleRate);
- Serial.println("Hz");
- }
-
- if (button2.fallingEdge()) {
- if (compressorOn) {
-
- audioShield.autoVolumeDisable();
- compressorOn = false;
- } else {
-
- audioShield.autoVolumeEnable();
- compressorOn = true;
- }
- Serial.print("Compressor: ");
- Serial.println(compressorOn);
- }
- }
|