Problems recording from signal generator

Status
Not open for further replies.
I am new to the teensy so this may be a simple question. I am attempting to record from a DC power supply (just to make sure it is working) to get a test signal. I have the power supply connected to pin 17 of the teensy. I'm having a hard time figuring out if this is the right pin to connect to. I am fairly confused about the line: sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);

I'm not sure what AUDIO_INPUT_LINEIN is referring to. Could anyone help me out with figuring out which pin I should hook the signal generator up to to record?



Code:
/*
#include <buffer.h>
#include <color.h>
#include <gfxfont.h>
#include <ssd1351.h>
*/
// Record sound as raw data to a SD card, and play it back.
//
// Requires the audio shield:
//   http://www.pjrc.com/store/teensy3_audio.html
//
// Three pushbuttons need to be connected:
//   Record Button: pin 0 to GND
//   Stop Button:   pin 1 to GND
//   Play Button:   pin 2 to GND
//
// This example code is in the public domain.

#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <XPT2046_Touchscreen.h>
#include <ILI9341_t3.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           //xy=105,63
AudioAnalyzePeak         peak1;          //xy=278,108
AudioRecordQueue         queue1;         //xy=281,63
AudioPlaySdRaw           playRaw1;       //xy=302,157
AudioOutputI2S           i2s1;           //xy=470,120
AudioConnection          patchCord1(i2s2, 0, queue1, 0);
AudioConnection          patchCord2(i2s2, 0, peak1, 0);
AudioConnection          patchCord3(playRaw1, 0, i2s1, 0);
AudioConnection          patchCord4(playRaw1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=265,212

#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

// The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 8

// The display also uses hardware SPI, plus #9 & #10
#define TFT_RST 255
#define TFT_MOSI 7
#define TFT_SCLK 14
#define TFT_MISO 12
// For the Adafruit shield, these are the default.
#define TFT_DC 20
#define TFT_CS 21

// which input on the audio shield will be used?
const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;


// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14


// Remember which mode we're doing
int mode = 0;  // 0=stopped, 1=recording, 2=playing

// The file where data is recorded
File frec;
int x;
int y;
int counter;
ILI9341_t3 tft(TFT_CS, TFT_DC, 255, TFT_MOSI, TFT_SCLK, TFT_MISO);
XPT2046_Touchscreen ts(STMPE_CS);

void setup() {

 
  Serial.begin(9600);
  Serial.println(myInput);
  while(!Serial); // Wait for the serial to work
  tft.begin();
  Serial.println("here");
  if (!ts.begin()) {
    Serial.print("TS not connected.");
    while (1);
  }
  tft.fillScreen(ILI9341_BLUE);
  tft.setRotation(3);
  tft.setCursor(80,65);
  tft.fillRoundRect(60, 55, 75, 30, 5, ILI9341_BLACK);
  tft.println("RECORD");

  tft.setCursor(190, 65);
  tft.fillRoundRect(185, 55, 75, 30, 5, ILI9341_BLACK);
  tft.println("PLAY");
  // Configure the pushbutton pins
  tft.setCursor(140,25);
  tft.fillRoundRect(130,15, 60, 30, 5, ILI9341_BLACK);
  tft.println("STOP");

  // Audio connections require memory, and the record queue
  // uses this memory to buffer incoming audio.
  AudioMemory(60);

  // Enable the audio shield, select input, and enable output
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.volume(0.5);

  // Initialize the SD card
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here if no SD card, but print a message
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}


void loop() {

  TS_Point p = ts.getPoint();
  //Serial.println(p);
    int given_x = 320 * (p.x - 130) / 3650;
    int given_y = 240 * (p.y - 150) / 3870;
    if (!ts.bufferEmpty() && ts.touched()) {
      if (given_x - x > 15 || x - given_x > 15 || given_y - y > 15 || y - given_y > 15) {
      y = given_y;
      x = given_x;
      }
    }
    if (counter > 10000) {
      counter = -1;
    } else if (counter == 0) {
        if (y <= 85 && y >= 55) {
          if (x <= 135 && x >= 60) {
            Serial.println("Record Button Press");
            if (mode == 2) stopPlaying();
            if (mode == 0) startRecording();
          }
          if (x <= 260 && x >= 185) {
            // Start playback
            Serial.println("Play Button Press");
            if (mode == 1) stopRecording();
            if (mode == 0) startPlaying(); 
          }
        } else if (y >= 15 && x >= 150 && x <= 210) {
          Serial.println("Stop Button Press");
          if (mode == 1) stopRecording();
          if (mode == 2) stopPlaying();
        }
      } else if (counter % 500 == 0) {
      // Update the pot values
    }
    counter++;

  // If we're playing or recording, carry on...
  if (mode == 1) {
    continueRecording();
  }
  if (mode == 2) {
    continuePlaying();
  }

  // when using a microphone, continuously adjust gain
 // if (myInput == AUDIO_INPUT_MIC) adjustMicLevel();
}


void startRecording() {
  Serial.println("startRecording");
  if (SD.exists("RECORD.RAW")) {
    // The SD library writes new data to the end of the
    // file, so to start a new recording, the old file
    // must be deleted before new data is written.
    SD.remove("RECORD.RAW");
  }
  frec = SD.open("RECORD.RAW", FILE_WRITE);
  if (frec) {
    queue1.begin();
    mode = 1;
  }
}

void continueRecording() {
  if (queue1.available() >= 2) {
    byte buffer[512];
    // Fetch 2 blocks from the audio library and copy
    // into a 512 byte buffer.  The Arduino SD library
    // is most efficient when full 512 byte sector size
    // writes are used.
    memcpy(buffer, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    memcpy(buffer+256, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    // write all 512 bytes to the SD card
    elapsedMicros usec = 0;
    frec.write(buffer, 512);
  }
}

void stopRecording() {
  Serial.println("stopRecording");
  queue1.end();
  if (mode == 1) {
    while (queue1.available() > 0) {
      frec.write((byte*)queue1.readBuffer(), 256);
      queue1.freeBuffer();
    }
    frec.close();
  }
  mode = 0;
}


void startPlaying() {
  Serial.println("startPlaying");
  playRaw1.play("RECORD.RAW");
  mode = 2;
}

void continuePlaying() {
  if (!playRaw1.isPlaying()) {
    playRaw1.stop();
    mode = 0;
  }
}

void stopPlaying() {
  Serial.println("stopPlaying");
  if (mode == 2) playRaw1.stop();
  mode = 0;
}

//void adjustMicLevel() {
  // TODO: read the peak1 object and adjust sgtl5000_1.micGain()
  // if anyone gets this working, please submit a github pull request :-)
//}
 
Line in is on the audio shield. Upper right center on the picture.
teensy3_audio_back.jpg
 
Line in is on the audio shield. Upper right center on the picture.
View attachment 16443

Thank you for the response. This worked! This leads me to another question. I am now testing both of the 2 input signal pins that are there. Only one is working. Both pins have wires soldered to the pin and the respective ground pins. Is there a way where I could use both those channels simultaneously to record? Note my code above where I am recording from AUDIO_INPUT_LINEIN. Would I have to change my code to be able to recognize both those signals? Or is this not supported OR could there be something wrong with my soldering/hardware? Thanks!
 
The connections are only using the left channel (0).
Use this connection to route the right channel from the line-in to the right channel output:
Code:
AudioConnection          patchCord4(playRaw1, 1, i2s1, 1);

To record, you'd need another queue:
Code:
AudioRecordQueue         queue2;
and add code in startRecording to start the queue - queue2.begin();
Then modify continueRecording so that it reads one buffer from queue1 and one from queue2 and then interleaves their samples into the buffer.
Or you can create a mono output by averaging the samples in the two buffers.

Pete
 
The connections are only using the left channel (0).
Use this connection to route the right channel from the line-in to the right channel output:
Code:
AudioConnection          patchCord4(playRaw1, 1, i2s1, 1);

To record, you'd need another queue:
Code:
AudioRecordQueue         queue2;
and add code in startRecording to start the queue - queue2.begin();
Then modify continueRecording so that it reads one buffer from queue1 and one from queue2 and then interleaves their samples into the buffer.
Or you can create a mono output by averaging the samples in the two buffers.

Pete

Thanks for this response! I made all the changes you said and it's still not working. To clarify, I am trying to record to two different files in the SD card. I am not having success writing to the secondary file, but the first is still working. I can't figure out what the problem in my code is.
Code:
// Record sound as raw data to a SD card, and play it back.
//
// Requires the audio shield:
//   http://www.pjrc.com/store/teensy3_audio.html
//
// Three pushbuttons need to be connected:
//   Record Button: pin 0 to GND
//   Stop Button:   pin 1 to GND
//   Play Button:   pin 2 to GND
//
// This example code is in the public domain.

#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <XPT2046_Touchscreen.h>
#include <ILI9341_t3.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           
AudioAnalyzePeak         peak1;          
AudioRecordQueue         queue1;         
AudioRecordQueue         queue2; 
AudioPlaySdRaw           playRaw1;       
AudioOutputI2S           i2s1;           
AudioConnection          patchCord1(i2s2, 0, queue1, 0);
AudioConnection          patchCord2(i2s2, 0, peak1, 0);
AudioConnection          patchCord3(playRaw1, 0, i2s1, 0);
AudioConnection          patchCord4(playRaw1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     

#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

// The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 8

// The display also uses hardware SPI, plus #9 & #10
#define TFT_RST 255
#define TFT_MOSI 7
#define TFT_SCLK 14
#define TFT_MISO 12
// For the Adafruit shield, these are the default.
#define TFT_DC 20
#define TFT_CS 21


// which input on the audio shield will be used?
const int LineInput = AUDIO_INPUT_LINEIN;
//const int  = AUDIO_INPUT_MIC;


// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14


// Remember which mode we're doing
int recording = 0;  // 0=stopped, 1=recording, 2=playing
int playing = 0;


// The file where data is recorded
File frec;
int x;
int y;
int counter;
char curr_menu = 'R';
int was_touched_flag = 0;
int can_scroll_down = 0;
int can_scroll_up = 0;
char* files[26];

int num_files = 0, scroll_offset = 0;
ILI9341_t3 tft(TFT_CS, TFT_DC, 255, TFT_MOSI, TFT_SCLK, TFT_MISO);
XPT2046_Touchscreen ts(STMPE_CS);
int tracks[4];

void setup() {
  tracks[0] = 0;
  tracks[1] = 0;
  tracks[2] = 0;
  tracks[3] = 0;
  Serial.begin(9600);
  while(!Serial); // Wait for the serial to work
  tft.begin();
  if (!ts.begin()) {
    Serial.print("TS not connected.");
    while (1);
  }
  display_top();
  display_record_menu();

  // Audio connections require memory, and the record queue
  // uses this memory to buffer incoming audio.
  AudioMemory(60);

  // Enable the audio shield, select input, and enable output
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(LineInput);
  sgtl5000_1.volume(0.5);

  // Initialize the SD card
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here if no SD card, but print a message
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void loop() {

  TS_Point p = ts.getPoint();
    if (!ts.bufferEmpty() && ts.touched()) {
      if (p.x - x > 15 || x - p.x > 15 || p.y - y > 15 || y - p.y > 15) {
      x = p.x;
      y = p.y;
      }
    }
    if (counter > 10000) {
      counter = -1;
    } else if (counter == 0) {
        flag_resp(p.x,p.y);
      } else if (counter % 500 == 0) {
      // Update the pot values
    }
    counter++;

  // If we're playing or recording, carry on...
  if (recording) {
    continueRecording();
  }
  if (playing) {
    continuePlaying();
  }

  // when using a microphone, continuously adjust gain
  if (LineInput == AUDIO_INPUT_MIC) adjustMicLevel();
}


void startRecording() {
  Serial.println("startRecording");

  //check for flag if file 1 or file 2 has been pressed 
  if (tracks[0]){
  if (SD.exists("RECORD.RAW")) {
    // The SD library writes new data to the end of the
    // file, so to start a new recording, the old file
    // must be deleted before new data is written.
    SD.remove("RECORD.RAW");
  }
     frec = SD.open("RECORD.RAW", FILE_WRITE);
     if (frec) {
      queue1.begin();
      mode = 1;
    }
  }
 
  if (tracks[1]){
  if (SD.exists("RECORD1.RAW")) {
    SD.remove("RECORD1.RAW");
  }
     frec2 = SD.open("RECORD1.RAW", FILE_WRITE);
     if (frec2) {
      queue2.begin();
      mode = 1;
    }
  }
 
}

void continueRecording() {
  //if first track is enabled 
  if (tracks[0]){
  if (queue1.available() >= 2) {
    byte buffer[512];
    // Fetch 2 blocks from the audio library and copy
    // into a 512 byte buffer.  The Arduino SD library
    // is most efficient when full 512 byte sector size
    // writes are used.
    memcpy(buffer, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    memcpy(buffer+256, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    // write all 512 bytes to the SD card
    elapsedMicros usec = 0;
    frec.write(buffer, 512);
  }
  }
  //If 2nd track is enabled 
  if (tracks[1]){
    if (queue2.available() >= 2) {
    byte buffer[512];
    memcpy(buffer, queue2.readBuffer(), 256);
    queue2.freeBuffer();
    memcpy(buffer+256, queue2.readBuffer(), 256);
    queue2.freeBuffer();
    // write all 512 bytes to the SD card
    elapsedMicros usec = 0;
    frec2.write(buffer, 512);
    }
  }
}

void stopRecording() {
  Serial.println("stopRecording");
  queue1.end();
  
  if (mode == 1) {
    if (tracks[0]){
    while (queue1.available() > 0) {
      frec.write((byte*)queue1.readBuffer(), 256);
      queue1.freeBuffer();
    }
    frec.close();
    }
  
    else if (tracks[1]){
    while (queue2.available() > 0) {
      frec.write((byte*)queue2.readBuffer(), 256);
      queue2.freeBuffer();
    }
    frec2.close();
    }
  mode = 0;
}


void startPlaying() {

  if (playtracks[0]){
    Serial.println("startPlaying");
    playRaw1.play("RECORD.RAW");
    mode = 2;
  }
  if (playtracks[1]){
    Serial.println("startPlaying");
    playRaw1.play("RECORD1.RAW");
    mode = 2;
  }
}

void continuePlaying() {
  if (!playRaw1.isPlaying()) {
    playRaw1.stop();
    mode = 0;
  }
}

void stopPlaying() {
  Serial.println("stopPlaying");
  if (mode == 2) playRaw1.stop();
  mode = 0;
}

void adjustMicLevel() {
  // TODO: read the peak1 object and adjust sgtl5000_1.micGain()
  // if anyone gets this working, please submit a github pull request :-)
}


/* * * * * * * * * * * * * * * * * * * * * *
* Name: flag_resp
*
* Parameters:
* x: x coordinate of touch
* y: y coordinate of touch
*
* Description: Decide on which function to
* call based on the x and y coordinates
* of where the screen was touched.
*
* * * * * * * * * * * * * * * * * * * * * */
void flag_resp(int given_x, int given_y) {
  int x = 320 * (given_x - 130) / 3650;
  int y = 240 * (given_y - 150) / 3870;
  Serial.print("x: "); Serial.print(x);
  Serial.print("\ty: "); Serial.print(y); Serial.print("\t");
  //Serial.print(curr_menu);
  if (y >= 45) {   // Lower menu buttons -> specific to each menu
    switch (curr_menu) {
      case 'F':
        if (x <= 80 && x >= 50) {
          // scroll buttons
          if (y <= 105 && y >= 75)
            if (num_files > 4)
              scroll_up(); // Scroll up
          if (y <= 225 && y >=195)
            if (num_files > 4)
              scroll_down(); // scroll down
          break;
        }
//        if (x <= 90 && x >= 60) {
//          // add to playback list
//          if (y <= 105 && y >= 75)
//            add_playback(1); // add first file to list
//          if (y <= 225 && y >=195)
//            add_playback(2); // add second file to list
//          if (y <= 105 && y >= 75)
//            add_playback(3); // add third file to list
//          break;
//        }
//        if (x <= 135 && x >= 105) {
//          // Play file
//          if (y <= 105 && y >= 75)
//            playback(1); // add first file to list
//          if (y <= 225 && y >=195)
//            playback(2); // add second file to list
//          if (y <= 105 && y >= 75)
//            playback(3); // add third file to list
//          break;
//        }
//        if (x <= 305 && x >= 275) {
//          // delete file
//          if (y <= 105 && y >= 75)
//            delete_file(1); // add first file to list
//          if (y <= 225 && y >=195)
//            delete_file(2); // add second file to list
//          if (y <= 105 && y >= 75)
//            delete_file(3); // add third file to list
//          break;
//        }
        break;
      case 'P':
//        if (x <= 135 && x >= 105) {
//          // scroll buttons
//          if (y <= 105 && y >= 75)
//            // Scroll up
//          if (y <= 225 && y >=195)
//            // scroll down
//          break;
//        }
//        if (x <= && x >= ) {
//          // Play file
//          //SD_CARD.playback(getIndex(y));
//          break;
//        }
//        if (x <= && x >= ) {
//          // Open individual volume slider - Required?
//          break;
//        }
//        if (x <= && x >= ) {
//          // Remove from playback list
//          break;
//        }
        break;
      case 'R':
        if (y <= 85 && y >= 55) {
          if (x <= 135 && x >= 60) {
            if (true) {
              if (recording && !playing)
                stopRecording();
              else if (!recording && !playing)
                startRecording();
              break;
            } else {
              Serial.print("Tried recording.");
              tft.fillRoundRect(105, 45, 120, 60, 5, ILI9341_RED);
              tft.setCursor(135, 65);
              tft.println("SD CARD ERR");
              delayMicroseconds(2000000);
              display_record_menu();  
            }
          }
          if (x <= 260 && x >= 185) {
            // Start recording with playback
            if (true) {
            if (recording && playing) {
              stopRecording();  
              stopPlaying();       
              } else if (!recording && !playing) {
                startRecording();
                startPlaying();
              }
            } else {
              Serial.print("Tried recording.");
              tft.fillRoundRect(105, 45, 120, 60, 5, ILI9341_RED);
              tft.setCursor(135, 65);
              tft.println("SD CARD ERR");
              delayMicroseconds(2000000);
              display_record_menu();  
            }
          }
        }
        if (x <= 110 && x >= 80) {
          // Select / deselect track
          if (y >= 100 && y <= 120) {
            // track 1
            Serial.print("Track one button");
            if (tracks[0]) {
              tft.fillRoundRect(65, 100, 30, 30, 5, ILI9341_BLACK);
              tracks[0] = 0;
            } else {
              tft.fillRoundRect(65, 100, 30, 30, 5, ILI9341_RED);
              tracks[0] = 1;
            }
          } else if (y <= 150 && y >= 130) {
            // Track 2
            Serial.print("Track two button");
            if (tracks[1]) {
              tft.fillRoundRect(65, 135, 30, 30, 5, ILI9341_BLACK);
              tracks[1] = 0;
            } else {
              tft.fillRoundRect(65, 135, 30, 30, 5, ILI9341_RED);
              tracks[1] = 1;
            }
          } else if (y <= 195 && y >= 170) {
            // Track 3
            Serial.print("Track three button");
            if (tracks[2]) {
              tft.fillRoundRect(65, 170, 30, 30, 5, ILI9341_BLACK);
              tracks[2] = 0;
            } else {
              tft.fillRoundRect(65, 170, 30, 30, 5, ILI9341_RED);
              tracks[2] = 1;
            }

          } else if (y <= 230 && y >= 205) {
            // track 4
            Serial.print("Track four button");
            if (tracks[3]) {
              tft.fillRoundRect(65, 205, 30, 30, 5, ILI9341_RED);
              tracks[3] = 0;
            } else {
              tracks[3] = 1;
              tft.fillRoundRect(65, 205, 30, 30, 5, ILI9341_BLACK);
            }
          }
          break;
        }
        break;
      } 
    } else if (y >= 15) {
    // upper menu buttons
      if (x >=  65 && x <= 125 && curr_menu != 'R') {
        curr_menu = 'R';
        display_record_menu();  
      }
        
      if (x >= 150 && x <= 210 && curr_menu != 'P') {
        curr_menu = 'P';
        display_playback_menu();  
      }
      if (x >= 230 && x <= 290 && curr_menu != 'F') {
        curr_menu = 'F';
        display_file_menu();
      }
  }
  was_touched_flag = 0;
 Serial.print("\n");
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: display_top
*
* Parameters: N/A
*
* Description: This function will display
* the top three buttons for file
* selection. Each one will be an empty
* box with the word in the center.
*
* * * * * * * * * * * * * * * * * * * * * */
void display_top () {
  tft.fillScreen(ILI9341_BLUE);
  tft.setRotation(3);
  // This function will display the top three buttons for file selection.
  // Each one will be an empty box with the word in the center.
  tft.setCursor(55,25);
  if (curr_menu != 'R')
    tft.fillRoundRect(45,15, 60, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(45,15, 60, 30, 5, ILI9341_RED);
  tft.println("RECORD");

  tft.setCursor(140,25);
  if (curr_menu != 'P')
    tft.fillRoundRect(130,15, 60, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(130,15, 60, 30, 5, ILI9341_RED);
  tft.println("PLAYBACK");

  tft.setCursor(225,25);
  if (curr_menu != 'F')
    tft.fillRoundRect(210,15, 60, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(210,15, 60, 30, 5, ILI9341_RED);
  tft.println("FILES");
  
  //Serial.print("Display top.");
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: display_file_menu
*
* Parameters: N/A
*
* Description: Display all of the buttons
* and symbols that make up the file menu display.
*
* * * * * * * * * * * * * * * * * * * * * */
void display_file_menu () {
  Serial.println("Display file menu.");
  //recorder->getFiles(files, num_files);
  Serial.print(num_files);
  num_files = 7;
  files[0] = "track_1_20190411_0900.raw";
  files[1] = "track_2_20190411_0900.raw";
  files[2] = "track_3_20190411_0900.raw";
  files[3] = "track_4_20190411_0900.raw";
  
  files[4] = "track_1_20190408_1145.raw";
  files[5] = "track_2_20190408_1145.raw";
  files[6] = "track_4_20190408_1145.raw";
  //scroll_offset = 0;
  
  display_top();
  if (num_files > 4) {
    tft.fillRoundRect(30, 65, 30, 170, 5, ILI9341_BLACK);
    tft.fillRoundRect(30, 65, 30, 30, 5, ILI9341_ORANGE);
    tft.fillTriangle(35,90,45,70,55,90, ILI9341_BLACK);
    tft.fillRoundRect(30, 205, 30, 30, 5, ILI9341_ORANGE);
    tft.fillTriangle(35,210,45,230,55,210, ILI9341_BLACK);
    can_scroll_down = 1;
  } else
    can_scroll_down = 0;
  if (num_files == 0) {
    Serial.print("Tried file menu.");
    tft.fillRoundRect(105, 45, 120, 60, 5, ILI9341_RED);
    tft.setCursor(135, 65);
    tft.println("SD CARD ERR");
    delayMicroseconds(2000000);
  }
  if(num_files > 0) {
    tft.setCursor(110,110);
    tft.fillRoundRect(65, 100, 30, 30, 5, ILI9341_BLACK);
    tft.println(files[0 + scroll_offset]);
  }
  if(num_files > 1) {
    tft.setCursor(110,145);
    tft.fillRoundRect(65, 135, 30, 30, 5, ILI9341_BLACK);
    tft.println(files[1 + scroll_offset]);
  }
  if(num_files > 2) {
    tft.setCursor(110,180);
    tft.fillRoundRect(65, 170, 30, 30, 5, ILI9341_BLACK);
    tft.println(files[2 + scroll_offset]);
  }
  if(num_files > 3) {
    tft.setCursor(110,215);
    tft.fillRoundRect(65, 205, 30, 30, 5, ILI9341_BLACK);
    tft.println(files[3 + scroll_offset]);
  }
  can_scroll_up = 0;
  // We'll need four bitmap images?
    // Plus symbol
    // Play symbol
    // Deletion symbol
    // Scroll up symbol
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: display_playback_menu
*
* Parameters: N/A
*
* Description: Display all of the buttons
* and symbols that make up the playback menu display.
*
* * * * * * * * * * * * * * * * * * * * * */
void display_playback_menu () {
  Serial.print("Display playback.");

  // We'll need four bitmap images?
    // Sound symbol
    // Play symbol
    // Deletion symbol
    // Scroll up symbol

  // // Some pseudocode
  // for file in display:
  //  drawBitmap(display.origin[x], display.origin[y], play_symbol, 30, 30, green);
  //  drawBitmap(display.origin[x] + 45, display.origin[y], sound_symbol, 30, 30, yellow);
  //  display(file_name);
  //  drawBitmap(display.origin[x] + 215, display.origin[y], delete_symbol, 30, 30, gray); // Or grey?
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: display_record_menu
*
* Parameters: N/A
*
* Description: Display all of the buttons
* and symbols that make up the record menu display.
*
* * * * * * * * * * * * * * * * * * * * * */
void display_record_menu () {
  // We'll need four bitmap images?
  // Sound
  // No sound
  // An X
  // A checkmark?
  display_top();
  Serial.print("Display recording.");
  tft.setCursor(80,65);
  tft.fillRoundRect(60, 55, 75, 30, 5, ILI9341_BLACK);
  tft.println("RECORD");

  tft.setCursor(190, 65);
  tft.fillRoundRect(185, 55, 75, 30, 5, ILI9341_BLACK);
  tft.println("REC W/ Play");

  tft.setCursor(110,110);
  if (tracks[0])
    tft.fillRoundRect(65, 100, 30, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(65, 100, 30, 30, 5, ILI9341_RED);
  tft.println("track_1_20190411_1145");

  tft.setCursor(110,145);
  if (tracks[1])
    tft.fillRoundRect(65, 135, 30, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(65, 135, 30, 30, 5, ILI9341_RED);
  tft.println("track_2_20190411_1145");
/* We have switched to a two channel version.
  tft.setCursor(110,180);
  if (recorder->tracks[2])
    tft.fillRoundRect(65, 170, 30, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(65, 170, 30, 30, 5, ILI9341_RED);
  tft.println("track_3_20190411_1145");

  tft.setCursor(110,215);
  if (recorder->tracks[3])
    tft.fillRoundRect(65, 205, 30, 30, 5, ILI9341_BLACK);
  else
    tft.fillRoundRect(65, 205, 30, 30, 5, ILI9341_RED);
  tft.println("track_4_20190411_1145");
*/  
  //tft.drawBitmap(65, 124, x_symbol, 30, 30, ILI9341_RED);
  //tft.drawBitmap(65, 124, check_symbol, 30, 30, ILI9341_DARKGREEN);
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: scroll_up
*
* Parameters: N/A
*
* Description: Shift the origins of the
* files that are being displayed or are
* about to be displayed to have them fit on the menu.
*
* * * * * * * * * * * * * * * * * * * * * */
void scroll_up() {
  Serial.print("scroll up.");  
  if (scroll_offset > 0) {
    scroll_offset--;
    Serial.print(scroll_offset);
    display_file_menu();
  }
}

/* * * * * * * * * * * * * * * * * * * * * *
* Name: scroll_down
*
* Parameters: N/A
*
* Description: Shift the origins of the
* files that are being displayed or are
* about to be displayed to have them fit on the menu.
*
* * * * * * * * * * * * * * * * * * * * * */
void scroll_down() {
    Serial.print("scroll down.");
    if (num_files - scroll_offset > 3) {
      scroll_offset++;
      Serial.print(scroll_offset);
      display_file_menu();
    }
}
void add_playback(int track) {
  Serial.print("Added "); Serial.print(track); Serial.print(" to playback.");  
}
void playback(int track) {
  Serial.print("Playing "); Serial.print(track); 
}
void delete_file(int track) {
    Serial.print("Deleting "); Serial.print(track); 
}

Does anything here stand out to you? This is a lot of code but most of it is for the touchscreen capability (which I don't believe is part of the problem, but it could be)
 
You also need a connection from the right channel input to queue2
Code:
AudioConnection          patchCord1a(i2s2, 1, queue2, 0);

Pete
 
You also need a connection from the right channel input to queue2
Code:
AudioConnection          patchCord1a(i2s2, 1, queue2, 0);

Pete

Thanks Pete! This worked! Also, is it possible to play a file from the SD card while simultaneously recording a song (file) to the SD card?
 
Status
Not open for further replies.
Back
Top