Audio quality of ArrayPlay bad than WavPlay.

charnjit

Well-known member
I am playing a 031_01.wav from playSdWav1 and then same file from playArray . i am listenig ArrayPlay Quality is bad than WavPlay. i record both files in audacity. they are apearing different. first is WavPlay , second is Array play.
WavPlay_ArrayPlay.jpg

Rec_WavPlay_ArrayPlay is recording file link for result of both file.,you can listen differance between. first is WavPlay , second is Array play in recording.
and my main sketch i used is:
C++:
#include <Keypad.h>                              
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
#include "Data.h"

const uint8_t ROWS = 7;  // 7 rows
const uint8_t COLS = 4;  //4 columns    
char keys[ROWS][COLS] = {
    { 1, 2, 3, 4 },
    { 5, 6, 7, 8 },
    { 9, 10, 11, 12 },
    { 13, 14, 15, 16 },
    { 17, 18, 19, 20 },
    { 21, 22, 23, 24 },
    { 25, 26, 27, 28 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 };
uint8_t colPins[COLS] = { 40, 41, 14, 16 };        
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
 
AudioPlaySdResmp           playSdWav1;    
AudioPlayArrayResmp  playArrayWav1;
AudioPlayArrayResmp  playArrayWav2;
AudioPlayArrayResmp  playArrayWav3;
AudioPlayArrayResmp  playArrayWav5;
AudioPlayArrayResmp  playArrayWav4;
AudioPlayArrayResmp  playArrayWav6;  
AudioPlayArrayResmp  playArrayWav7;  
AudioPlayArrayResmp  playArrayWav9;  
AudioPlayArrayResmp  playArrayWav8;
AudioPlayArrayResmp  playArrayWav11;
AudioPlayArrayResmp  playArrayWav12;
AudioPlayArrayResmp  playArrayWav10;
AudioPlayArrayResmp  playArrayWav13;
AudioPlayArrayResmp  playArrayWav14;
AudioPlayArrayResmp  playArrayWav15;
AudioPlayArrayResmp  playArrayWav16;

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        AudioPlayArrayResmp *playArray[] = {
  &playArrayWav1,
  &playArrayWav2,
  &playArrayWav3,
  &playArrayWav5,
   &playArrayWav4,
   &playArrayWav6,
   &playArrayWav7,
   &playArrayWav9,
   &playArrayWav8,
   &playArrayWav11,
   &playArrayWav12,
   &playArrayWav10,
   &playArrayWav13,
   &playArrayWav14,
   &playArrayWav15,
   &playArrayWav16
};               //  #######################################################################################
 
AudioMixer4              DRUM_mixer1;        
AudioMixer4              DRUM_mixer2;        
AudioMixer4              SD_WAV_mixer5;        
AudioMixer4              DRUM_mixer3;        
AudioMixer4              DRUM_mixer4;        
AudioMixer4              DRUM_mixer6;        
AudioMixer4              WAV_mixer7;        
AudioMixer4              MASTER_mixer8;        
AudioAmplifier           amp2;          
AudioAmplifier           amp1;

AudioOutputI2S i2s2;        

AudioConnection          patchCord1(playSdWav1, 0, SD_WAV_mixer5, 0);
AudioConnection          patchCord2(playSdWav1, 1, SD_WAV_mixer5, 1);

AudioConnection          patchCord3(playArrayWav1, 0, DRUM_mixer1, 0);
AudioConnection          patchCord4(playArrayWav2, 0, DRUM_mixer1, 1);
AudioConnection          patchCord5(playArrayWav3, 0, DRUM_mixer1, 2);
AudioConnection          patchCord6(playArrayWav5, 0, DRUM_mixer2, 0);
AudioConnection          patchCord7(playArrayWav4, 0, DRUM_mixer1, 3);
AudioConnection          patchCord8(playArrayWav6, 0, DRUM_mixer2, 1);
AudioConnection          patchCord9(playArrayWav7, 0, DRUM_mixer2, 2);
AudioConnection          patchCord10(playArrayWav9, 0, DRUM_mixer3, 0);
AudioConnection          patchCord11(playArrayWav8, 0, DRUM_mixer2, 3);
AudioConnection          patchCord12(playArrayWav11, 0, DRUM_mixer3, 2);
AudioConnection          patchCord13(playArrayWav12, 0, DRUM_mixer3, 3);
AudioConnection          patchCord14(playArrayWav10, 0, DRUM_mixer3, 1);
AudioConnection          patchCord15(playArrayWav13, 0, DRUM_mixer4, 0);
AudioConnection          patchCord16(playArrayWav14, 0, DRUM_mixer4, 1);
AudioConnection          patchCord17(playArrayWav15, 0, DRUM_mixer4, 2);
AudioConnection          patchCord18(playArrayWav16, 0, DRUM_mixer4, 3);
AudioConnection          patchCord19(DRUM_mixer1, 0, DRUM_mixer6, 0);
AudioConnection          patchCord20(DRUM_mixer2, 0, DRUM_mixer6, 1);
AudioConnection          patchCord21(SD_WAV_mixer5, 0, WAV_mixer7, 0);
AudioConnection          patchCord22(DRUM_mixer3, 0, DRUM_mixer6, 2);
AudioConnection          patchCord23(DRUM_mixer4, 0, DRUM_mixer6, 3);
AudioConnection          patchCord24(DRUM_mixer6, 0, MASTER_mixer8, 0);
AudioConnection          patchCord25(WAV_mixer7, 0, MASTER_mixer8, 1);
AudioConnection          patchCord26(MASTER_mixer8, amp1);
AudioConnection          patchCord27(MASTER_mixer8, amp2);
AudioConnection          patchCord28(amp2, 0, i2s2, 1);
AudioConnection          patchCord29(amp1, 0, i2s2, 0);

AudioControlSGTL5000 audioShield;
 

#define SCREEN_WIDTH 128  
#define SCREEN_HEIGHT 32  

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C  
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Encoder myEnc(2, 3);

#define INC_BUTTON 24
#define DEC_BUTTON 23
#define ENCODER_BUTTON 25
#define KIT_BUTTON 17
#define TAP_BUTTON 18
#define SYNC_BUTTON 20
#define SHIFT_BUTTON 19
#define FAST_BUTTON 22
#define SLOW_BUTTON 21
String msg;
String INC_DEC_MODE = "BANK";
String PLAY_MODE = "LOOP";

float Speed = 1.00;
float VOL = 0.9;
float VOL_A = 0.0;
float VOL_AA = 0.0;
float DRUM_VOL = 0.50;
float WAV_VOL = 0.50;
int Bank = 3;
int Last_Bank = 3;
int  TAP_HOLD = 0;
int SHIFT_HOLD = 0;
int PLAY_STATUS = 0;
int LAST_PLAY_STATUS =0;
int PLAYING_STATUS=1;
unsigned long old_millis = 0;
float BPM = 110.00;
int Display_BPM = 110;
 int i= 0;
  int hold_status=0;
 int PRESS_A = 0;
 int PRESS_AA = 0;
 unsigned long PRESS_millis = 0;
 
  char *wav_31[16] = { "031_01.WAV", "031_02.WAV","031_03.WAV","031_04.WAV","031_05.WAV","031_06.WAV","031_07.WAV","031_08.WAV","031_09.WAV","031_10.WAV","031_11.WAV","031_12.WAV","031_13.WAV","031_14.WAV","031_15.WAV","031_16.WAV" };
  char *wav_file[32][16] = {  
     {"001_01.WAV", "001_02.WAV","001_03.WAV","001_04.WAV","001_05.WAV","001_06.WAV","001_07.WAV","001_08.WAV","001_09.WAV","001_10.WAV","001_11.WAV","001_12.WAV","001_13.WAV","001_14.WAV","001_15.WAV","001_16.WAV"},
     {"002_01.WAV", "002_02.WAV","002_03.WAV","002_04.WAV","002_05.WAV","002_06.WAV","002_07.WAV","002_08.WAV","002_09.WAV","002_10.WAV","002_11.WAV","002_12.WAV","002_13.WAV","002_14.WAV","002_15.WAV","002_16.WAV"},
     {"003_01.WAV", "003_02.WAV","003_03.WAV","003_04.WAV","003_05.WAV","003_06.WAV","003_07.WAV","003_08.WAV","003_09.WAV","003_10.WAV","003_11.WAV","003_12.WAV","003_13.WAV","003_14.WAV","003_15.WAV","003_16.WAV"},                
     {"004_01.WAV", "004_02.WAV","004_03.WAV","004_04.WAV","004_05.WAV","004_06.WAV","004_07.WAV","004_08.WAV","004_09.WAV","004_10.WAV","004_11.WAV","004_12.WAV","004_13.WAV","004_14.WAV","004_15.WAV","004_16.WAV"},
     {"005_01.WAV", "005_02.WAV","005_03.WAV","005_04.WAV","005_05.WAV","005_06.WAV","005_07.WAV","005_08.WAV","005_09.WAV","005_10.WAV","005_11.WAV","005_12.WAV","005_13.WAV","005_14.WAV","005_15.WAV","005_16.WAV"},
     {"006_01.WAV", "006_02.WAV","006_03.WAV","006_04.WAV","006_05.WAV","006_06.WAV","006_07.WAV","006_08.WAV","006_09.WAV","006_10.WAV","006_11.WAV","006_12.WAV","006_13.WAV","006_14.WAV","006_15.WAV","006_16.WAV"},
     {"007_01.WAV", "007_02.WAV","007_03.WAV","007_04.WAV","007_05.WAV","007_06.WAV","007_07.WAV","007_08.WAV","007_09.WAV","007_10.WAV","007_11.WAV","007_12.WAV","007_13.WAV","007_14.WAV","007_15.WAV","007_16.WAV"},
     {"008_01.WAV", "008_02.WAV","008_03.WAV","008_04.WAV","008_05.WAV","008_06.WAV","008_07.WAV","008_08.WAV","008_09.WAV","008_10.WAV","008_11.WAV","008_12.WAV","008_13.WAV","008_14.WAV","008_15.WAV","008_16.WAV"},
     {"009_01.WAV", "009_02.WAV","009_03.WAV","009_04.WAV","009_05.WAV","009_06.WAV","009_07.WAV","009_08.WAV","009_09.WAV","009_10.WAV","009_11.WAV","009_12.WAV","009_13.WAV","009_14.WAV","009_15.WAV","009_16.WAV"},
     {"010_01.WAV", "010_02.WAV","010_03.WAV","010_04.WAV","010_05.WAV","010_06.WAV","010_07.WAV","010_08.WAV","010_09.WAV","010_10.WAV","010_11.WAV","010_12.WAV","010_13.WAV","010_14.WAV","010_15.WAV","010_16.WAV"},
     {"011_01.WAV", "011_02.WAV","011_03.WAV","011_04.WAV","011_05.WAV","011_06.WAV","011_07.WAV","011_08.WAV","011_09.WAV","011_10.WAV","011_11.WAV","011_12.WAV","011_13.WAV","011_14.WAV","011_15.WAV","011_16.WAV"},
     {"012_01.WAV", "012_02.WAV","012_03.WAV","012_04.WAV","012_05.WAV","012_06.WAV","012_07.WAV","012_08.WAV","012_09.WAV","012_10.WAV","012_11.WAV","012_12.WAV","012_13.WAV","012_14.WAV","012_15.WAV","012_16.WAV"},
     {"013_01.WAV", "013_02.WAV","013_03.WAV","013_04.WAV","013_05.WAV","013_06.WAV","013_07.WAV","013_08.WAV","013_09.WAV","013_10.WAV","013_11.WAV","013_12.WAV","013_13.WAV","013_14.WAV","013_15.WAV","013_16.WAV"},
     {"014_01.WAV", "014_02.WAV","014_03.WAV","014_04.WAV","014_05.WAV","014_06.WAV","014_07.WAV","014_08.WAV","014_09.WAV","014_10.WAV","014_11.WAV","014_12.WAV","014_13.WAV","014_14.WAV","014_15.WAV","014_16.WAV"},
     {"015_01.WAV", "015_02.WAV","015_03.WAV","015_04.WAV","015_05.WAV","015_06.WAV","015_07.WAV","015_08.WAV","015_09.WAV","015_10.WAV","015_11.WAV","015_12.WAV","015_13.WAV","015_14.WAV","015_15.WAV","015_16.WAV"},
     {"016_01.WAV", "016_02.WAV","016_03.WAV","016_04.WAV","016_05.WAV","016_06.WAV","016_07.WAV","016_08.WAV","016_09.WAV","016_10.WAV","016_11.WAV","016_12.WAV","016_13.WAV","016_14.WAV","016_15.WAV","016_16.WAV"},
     {"017_01.WAV", "017_02.WAV","017_03.WAV","017_04.WAV","017_05.WAV","017_06.WAV","017_07.WAV","017_08.WAV","017_09.WAV","017_10.WAV","017_11.WAV","017_12.WAV","017_13.WAV","017_14.WAV","017_15.WAV","017_16.WAV"},
     {"018_01.WAV", "018_02.WAV","018_03.WAV","018_04.WAV","018_05.WAV","018_06.WAV","018_07.WAV","018_08.WAV","018_09.WAV","018_10.WAV","018_11.WAV","018_12.WAV","018_13.WAV","018_14.WAV","018_15.WAV","018_16.WAV"},
     {"019_01.WAV", "019_02.WAV","019_03.WAV","019_04.WAV","019_05.WAV","019_06.WAV","019_07.WAV","019_08.WAV","019_09.WAV","019_10.WAV","019_11.WAV","019_12.WAV","019_13.WAV","019_14.WAV","019_15.WAV","019_16.WAV"},
     {"020_01.WAV", "020_02.WAV","020_03.WAV","020_04.WAV","020_05.WAV","020_06.WAV","020_07.WAV","020_08.WAV","020_09.WAV","020_10.WAV","020_11.WAV","020_12.WAV","020_13.WAV","020_14.WAV","020_15.WAV","020_16.WAV"},
     {"021_01.WAV", "021_02.WAV","021_03.WAV","021_04.WAV","021_05.WAV","021_06.WAV","021_07.WAV","021_08.WAV","021_09.WAV","021_10.WAV","021_11.WAV","021_12.WAV","021_13.WAV","021_14.WAV","021_15.WAV","021_16.WAV"},
     {"022_01.WAV", "022_02.WAV","022_03.WAV","022_04.WAV","022_05.WAV","022_06.WAV","022_07.WAV","022_08.WAV","022_09.WAV","022_10.WAV","022_11.WAV","022_12.WAV","022_13.WAV","022_14.WAV","022_15.WAV","022_16.WAV"},
     {"023_01.WAV", "023_02.WAV","023_03.WAV","023_04.WAV","023_05.WAV","023_06.WAV","023_07.WAV","023_08.WAV","023_09.WAV","023_10.WAV","023_11.WAV","023_12.WAV","023_13.WAV","023_14.WAV","023_15.WAV","023_16.WAV"},
     {"024_01.WAV", "024_02.WAV","024_03.WAV","024_04.WAV","024_05.WAV","024_06.WAV","024_07.WAV","024_08.WAV","024_09.WAV","024_10.WAV","024_11.WAV","024_12.WAV","024_13.WAV","024_14.WAV","024_15.WAV","024_16.WAV"},
     {"025_01.WAV", "025_02.WAV","025_03.WAV","025_04.WAV","025_05.WAV","025_06.WAV","025_07.WAV","025_08.WAV","025_09.WAV","025_10.WAV","025_11.WAV","025_12.WAV","025_13.WAV","025_14.WAV","025_15.WAV","025_16.WAV"},
     {"026_01.WAV", "026_02.WAV","026_03.WAV","026_04.WAV","026_05.WAV","026_06.WAV","026_07.WAV","026_08.WAV","026_09.WAV","026_10.WAV","026_11.WAV","026_12.WAV","026_13.WAV","026_14.WAV","026_15.WAV","026_16.WAV"},
     {"027_01.WAV", "027_02.WAV","027_03.WAV","027_04.WAV","027_05.WAV","027_06.WAV","027_07.WAV","027_08.WAV","027_09.WAV","027_10.WAV","027_11.WAV","027_12.WAV","027_13.WAV","027_14.WAV","027_15.WAV","027_16.WAV"},
     {"028_01.WAV", "028_02.WAV","028_03.WAV","028_04.WAV","028_05.WAV","028_06.WAV","028_07.WAV","028_08.WAV","028_09.WAV","028_10.WAV","028_11.WAV","028_12.WAV","028_13.WAV","028_14.WAV","028_15.WAV","028_16.WAV"},
     {"029_01.WAV", "029_02.WAV","029_03.WAV","029_04.WAV","029_05.WAV","029_06.WAV","029_07.WAV","029_08.WAV","029_09.WAV","029_10.WAV","029_11.WAV","029_12.WAV","029_13.WAV","029_14.WAV","029_15.WAV","029_16.WAV"},
     {"030_01.WAV", "030_02.WAV","030_03.WAV","030_04.WAV","030_05.WAV","030_06.WAV","030_07.WAV","030_08.WAV","030_09.WAV","030_10.WAV","030_11.WAV","030_12.WAV","030_13.WAV","030_14.WAV","030_15.WAV","030_16.WAV"},
     {"031_01.WAV", "031_02.WAV","031_03.WAV","031_04.WAV","031_05.WAV","031_06.WAV","031_07.WAV","031_08.WAV","031_09.WAV","031_10.WAV","031_11.WAV","031_12.WAV","031_13.WAV","031_14.WAV","031_15.WAV","031_16.WAV"},
     {"032_01.WAV", "032_02.WAV","032_03.WAV","032_04.WAV","032_05.WAV","032_06.WAV","032_07.WAV","032_08.WAV","032_09.WAV","032_10.WAV","032_11.WAV","032_12.WAV","032_13.WAV","032_14.WAV","032_15.WAV","032_16.WAV"}
                                };

     File myFile;
         int16_t *SMP_addr[16];  
         uint32_t sizes[16];      
                           
void setup() {


    Serial.begin(57600);
    kpd.setHoldTime(2000);

    if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
        Serial.println(F("SSD1306 allocation failed"));
        for (;;)
            ;  // Don't proceed, loop forever
    }
    display.display();
    delay(2000);
    display.clearDisplay();
    msg = "";

    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
            Serial.println("Unable to access the SD card");
            SCN_NO_SD();
            delay(500);
        }
    }

    AudioMemory(128);
    audioShield.enable();
    audioShield.volume(1.0);
    amp1.gain(VOL);
    amp2.gain(VOL);
     MASTER_mixer8.gain(0, DRUM_VOL);      
   
    for(int i = 0; i < 16; i++)  {
  playArray[i]->enableInterpolation(true);  
}
      Serial.println("Loop Sampler 16 Pad");
     SCN_START ();
     delay(3000);
      RAM_LOAD ();
      ARRAY_SPEED_SET ();  
     SCN_MAIN();
}

long oldPosition  =   myEnc.read();  // -999;
 long Last_Position = 0;


 
void loop() {

  long newPosition = myEnc.read();
  if (myEnc.read() != oldPosition) {
  if  (myEnc.read() < oldPosition)  {    
    Serial.println(" -- ");    
      Speed = Speed + 0.01;    
      playSdWav1.setPlaybackRate(Speed);          
      SCN_SPEED ();    
      SCN_HOLD ();
  }
  else if  (myEnc.read() > oldPosition)  {    
    Serial.println(" ++ ");  
      Speed = Speed - 0.01;  
      playSdWav1.setPlaybackRate(Speed);    
      SCN_SPEED ();    
      SCN_HOLD ();
  }
    oldPosition = myEnc.read();  Serial.println(myEnc.read());
  }

     
// *******************************************************************************************************

     if (analogRead(22) ==1)         {VOL_A = 0.00;    }
      if (analogRead(22) ==42)       {VOL_A = 0.05;    }   //1
      if (analogRead(22) ==85)       {VOL_A = 0.10;    }      //2
       if (analogRead(22) ==127)     {VOL_A = 0.15;    }  //3
      if (analogRead(22) ==170)      {VOL_A = 0.20;    }     //4
       if (analogRead(22) ==213)     {VOL_A = 0.25;    }  //5
        if (analogRead(22) ==255)    {VOL_A = 0.30;    }   //6
         if (analogRead(22) ==298)   {VOL_A = 0.35;    } //7
         if (analogRead(22) ==341)   {VOL_A = 0.40;    }  //8
          if (analogRead(22) ==383)  {VOL_A = 0.45;    } //9
          if (analogRead(22) ==426)  {VOL_A = 0.50;    }  //10
          if (analogRead(22) ==468)  {VOL_A = 0.55;    }  //11
          if (analogRead(22) ==511)  {VOL_A = 0.60;    }  // 12
          if (analogRead(22) ==554)  {VOL_A = 0.65;    } //13
          if (analogRead(22) ==597)  {VOL_A = 0.70;    }  // 14
          if (analogRead(22) ==639)  {VOL_A = 0.75;    }  //15
          if (analogRead(22) ==682)  {VOL_A = 0.80;    }   // 16
          if (analogRead(22) ==724)  {VOL_A = 0.85;    }  //17
          if (analogRead(22) ==767)  {VOL_A = 0.90;    }  //18
          if (analogRead(22) ==809)  {VOL_A = 0.95;    }  //19
          if (analogRead(22) ==852)  {VOL_A = 1.00;    }  // 20
          if (analogRead(22) ==895)  {VOL_A = 1.05;    } //21
          if (analogRead(22) ==938)  {VOL_A = 1.10;    }  // 22
          if (analogRead(22) ==980)  {VOL_A = 1.15;    }  // 23
          if (analogRead(22) ==1022) {VOL_A = 1.20;    }   // 24          

      if (VOL_A != VOL_AA) {
        Serial.println( VOL_A);  
        amp1.gain(VOL_A);  
        amp2.gain(VOL_A);          
        VOL_AA = VOL_A;
        SCN_VOL ();  
        SCN_HOLD ();
        }
           //  
// *******************************************************************************************************

        if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++)
        {    int mykey = (kpd.key[i].kchar);
            if (kpd.key[i].stateChanged)  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                    Serial.println(mykey);    Serial.println("PRESSED");  
                        break;
                    case RELEASED:
                     Serial.println(mykey);    Serial.println("RELEASED");
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------  
             if ((kpd.key[i].stateChanged)  && (mykey > 0) && (mykey<17))  //  -----------------------------------------Key Changed--(1-16)-------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                    if (PLAY_MODE=="LOOP")     {
                   playSdWav1.playWav(wav_file[Bank-1][mykey-1]);    
                   if (mykey==16)  {playSdWav1.setLoopType(looptype_none); }
                   else   {playSdWav1.setLoopType(looptype_repeat); }
                    }
                     if (PLAY_MODE=="DRUM")     {     PLAY_ARRAY (mykey);    }
                   Serial.println("Matrix start");    
                   Serial.println(wav_file[Bank-1][mykey-1]);  
                   Serial.println("Matrix end");
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------  
         
                          if ((kpd.key[i].stateChanged)  && (mykey == KIT_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     PLAY_MODE = "DRUM";
                     INC_DEC_MODE = "DRUM_VOL";
                  //  Last_Bank = Bank;
                  //  Bank = 31;
                    SCN_MAIN();
                        break;
                    case RELEASED:
                      PLAY_MODE = "LOOP";
                      INC_DEC_MODE = "BANK";
                   // Bank = Last_Bank;
                   SCN_MAIN();
                 
                    break;
                }
            }  //--------------------------------------------------------------------------------------------------
              if ((kpd.key[i].stateChanged)  && (mykey ==TAP_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                      BPM = 60000/(millis()-old_millis);
                   if ((BPM>70) && (BPM<200)) SYNC_BPM ();   SCN_BPM ();    //   switch (kpd.key[i].kstate) {  case 90:    /doing/ break;  }
                     old_millis = millis();     SCN_HOLD ();      
                                       INC_DEC_MODE = "WAV_VOL";
                        break;
                         case RELEASED:
                                       INC_DEC_MODE = "BANK";
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------
 
             if ((kpd.key[i].stateChanged)  && (mykey == SYNC_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     playSdWav1.stop();
                        break;
                    case RELEASED:
                    break;
                }
            }  //--------------------------------------------------------------------------------------------------
                if ((kpd.key[i].stateChanged)  && (mykey == SHIFT_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     SHIFT_HOLD = 1;     playSdWav1.stop();
                        break;
                    case RELEASED:
                   SHIFT_HOLD = 0;
                 
                    break;
                }
            }  //--------------------------------------------------------------------------------------------------
             if ((kpd.key[i].stateChanged)  && (mykey == DEC_BUTTON))  //  -----------------------------------------Key Changed-------(-)---------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                   if  (INC_DEC_MODE == "BANK")  
                                                    { Bank--;  
                                                    if (Bank==33){ PLAY_MODE = "DRUM";}    else  { PLAY_MODE = "LOOP";}                    
                                                      SCN_MAIN(); }
                    if  (INC_DEC_MODE == "VOL")  {
                                                       VOL=VOL-0.1;
                                                       amp1.gain(VOL);  
                                                       amp2.gain(VOL);
                                                       SCN_VOL ();
                                                      }  // vol --
                    if  (INC_DEC_MODE == "DRUM_VOL")  {
                                                        DRUM_VOL=DRUM_VOL-0.05;    
                                                        MASTER_mixer8.gain(0, DRUM_VOL);
                                                        SCN_DRUM_VOL ();
                                                        SCN_HOLD ();
                                                        }
                     if  (INC_DEC_MODE == "WAV_VOL")  {
                                                        WAV_VOL=WAV_VOL-0.05;  
                                                        MASTER_mixer8.gain(1, WAV_VOL);
                                                        SCN_LEVEL ("WAV",WAV_VOL*100);  
                                                        SCN_HOLD ();
                                                        }
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------
             if ((kpd.key[i].stateChanged)  && (mykey == INC_BUTTON))  //  -----------------------------------------Key Changed--------(+)--------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                    if  (INC_DEC_MODE == "BANK")     {
                                                         Bank++;      
                                                     if (Bank==33){ PLAY_MODE = "DRUM";}   else  { PLAY_MODE = "LOOP";}              
                                                         SCN_MAIN();  
                                                         }
                      if  (INC_DEC_MODE == "VOL")   {  
                                                         VOL=VOL+0.1;
                                                         amp1.gain(VOL);  
                                                         amp2.gain(VOL);  
                                                         SCN_VOL ();
                                                         }  // vol --
                       if  (INC_DEC_MODE == "DRUM_VOL")  {  
                                                         DRUM_VOL=DRUM_VOL+0.05;    
                                                         MASTER_mixer8.gain(0, DRUM_VOL);
                                                         SCN_DRUM_VOL ();
                                                         SCN_HOLD ();
                                                         }
                        if  (INC_DEC_MODE == "WAV_VOL")  {
                                                         WAV_VOL=WAV_VOL+0.05;    
                                                         MASTER_mixer8.gain(1, WAV_VOL);
                                                         SCN_LEVEL ("WAV",WAV_VOL*100);
                                                         SCN_HOLD ();
                                                         }
                        break;
                 
                }
            }  //--------------------------------------------------------------------------------------------------
             if ((kpd.key[i].stateChanged)  && (mykey == SLOW_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     Speed = Speed - 0.01;
            playSdWav1.setPlaybackRate(Speed);   PLAYING_STATUS==0;
                       SCN_SPEED ();      SCN_HOLD ();
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------
             if ((kpd.key[i].stateChanged)  && (mykey == FAST_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     Speed = Speed + 0.01;
            playSdWav1.setPlaybackRate(Speed);   PLAYING_STATUS==0;
                        SCN_SPEED ();      SCN_HOLD ();
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------      
              if ((kpd.key[i].stateChanged)  && (mykey == ENCODER_BUTTON))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     Speed = 1.00;
            playSdWav1.setPlaybackRate(Speed);
                   PLAYING_STATUS==0;    SCN_SPEED ();      SCN_HOLD ();
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------      
        }
    }  
  // -------------------------------------------------------
    if (Serial.available() > 0) {
        int incomingByte = Serial.read();
        if (incomingByte == 49) {  // key 1
            Serial.println("1");
        }
    }  // ------------------------------------------------------
    if ((Bank > 33) && (Bank == 34)) { Bank = 1; }
     if ((Bank < 1 ) && (Bank == 0)) { Bank = 33; }
     if (VOL > 1.1) { VOL = 1.1;  }
      if (VOL < 0) { VOL = 0;  }

             if (millis() > (PRESS_millis+2000)) { PRESS_A =0;  }   // cut of SCN_HOLD
     if (PRESS_A != PRESS_AA)   {PRESS_AA = PRESS_A;  if (PRESS_A == 0) {    Serial.println("Return to Main_SCN"); SCN_MAIN();  PLAYING_STATUS==1;  } }

 PLAY_STATUS =    playSdWav1.isPlaying();
 if (LAST_PLAY_STATUS != PLAY_STATUS) {  SCN_MAIN();  Serial.println("PLAY_STATUS: "); Serial.println(PLAY_STATUS);  LAST_PLAY_STATUS = PLAY_STATUS;  }

    if (PRESS_A==0) { SCN_MAIN();    }
}

void SCN_MAIN() {
      Display_BPM = BPM;
    display.clearDisplay();
    display.setTextSize(1);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(0, 0);
    display.print("SPD- ");
    display.print(Speed);
    display.print("    ");
    display.print("BPM- ");
    display.print(Display_BPM);
    display.setCursor(0, 10);              
    display.setTextSize(2);
    if ( PLAY_MODE == "DRUM") {display.print("Drum: ");}
   else { display.print("Bank: ");}
    display.print(Bank);
    //display.drawLine(1,30,128,30,WHITE);
    display.fillRect((playSdWav1.positionMillis() / ((playSdWav1.lengthMillis()/128))) ,26,6,6,WHITE);   //  2000
    display.display();
}
void SCN_MAIN1() {
    int Temp_BPM = BPM;
    display.clearDisplay();
    display.setTextSize(1);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(0, 0);
    display.print("SPD-");
     display.print(Speed);
     display.print("    ");
     display.print("BPM- ");
     display.print(Temp_BPM);
      display.setCursor(40, 11);
      display.print("  Bank: ");
     display.print(Bank);

    display.setCursor(0, 21);            
    display.setTextSize(1);
   display.print("Memory: ");
    display.print(AudioMemoryUsage());
    display.print("   Max: ");
    display.print(AudioMemoryUsageMax());
    display.display();
}
void SCN_START ()
{
    display.clearDisplay();
    display.setTextSize(2);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(10, 0);              
   // display.print(number);
    display.print("Loading..");
     display.setCursor(20, 20);
    display.setTextSize(1);
    display.println("Please wait");
    //display.print(msg);
    display.display();
}
void SCN_BPM ()  {
      display.clearDisplay();
    display.setTextSize(2);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    display.setCursor(0, 0);              // Start at top-left corner
    display.print("BPM  ");
    display.setTextSize(3);
    display.setCursor(50, 3);
    int DISPLAY_BPM = BPM;
    display.print(DISPLAY_BPM);  //BPM
    display.display();
}
void SCN_VOL ()  {
      display.clearDisplay();
    display.setTextSize(2);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(8, 0);              
    display.print("VOL : ");
    int Display_VOL = (VOL_A*100);
    display.print(Display_VOL);
    display.drawLine(4,20,Display_VOL ,20,WHITE);
     display.drawLine(4,21,Display_VOL ,21,WHITE);
      display.drawLine(4,22,Display_VOL ,22,WHITE);
       display.drawLine(4,23,Display_VOL ,23,WHITE);
       display.drawLine(4,24,Display_VOL ,24,WHITE);
       display.drawLine(4,25,Display_VOL ,25,WHITE);
       display.drawLine(4,26,Display_VOL ,26,WHITE);
    display.display();
}
void SCN_DRUM_VOL ()  {
      display.clearDisplay();
    display.setTextSize(2);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(8, 0);              
    display.print("DRUM : ");
    int Display_VOL = (DRUM_VOL*100);
    display.print(Display_VOL);
    display.drawLine(4,20,Display_VOL ,20,WHITE);
     display.drawLine(4,21,Display_VOL ,21,WHITE);
      display.drawLine(4,22,Display_VOL ,22,WHITE);
       display.drawLine(4,23,Display_VOL ,23,WHITE);
       display.drawLine(4,24,Display_VOL ,24,WHITE);
       display.drawLine(4,25,Display_VOL ,25,WHITE);
       display.drawLine(4,26,Display_VOL ,26,WHITE);
    display.display();
}
void SCN_LEVEL (String text,int level )  {
      display.clearDisplay();
    display.setTextSize(2);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(8, 0);              
    display.print(text);
    display.print(" : ");
    display.print(level);
    display.drawLine(4,20,level ,20,WHITE);
     display.drawLine(4,21,level ,21,WHITE);
      display.drawLine(4,22,level ,22,WHITE);
       display.drawLine(4,23,level ,23,WHITE);
       display.drawLine(4,24,level ,24,WHITE);
       display.drawLine(4,25,level ,25,WHITE);
       display.drawLine(4,26,level ,26,WHITE);
    display.display();
}
void SCN_SPEED ()  {
      display.clearDisplay();
    display.setTextSize(2);              
    display.setTextColor(SSD1306_WHITE);  
    display.setCursor(0, 0);            
    display.print("SPEED");
    display.setCursor(60, 16);
    display.print(Speed);
    display.display();
}
void SCN_SHIFT()     {
          display.clearDisplay();
    display.setTextSize(2);              
  display.drawRect(3, 3, 122, 28, WHITE);
 display.setCursor(40, 10);
 display.println("SHIFT");
    display.display();
}
void SCN_TEST()     {
          display.clearDisplay();
    display.setTextSize(2);              
 display.setCursor(0, 10);
 display.println("CLICK");
    display.display();
}
void SCN_NO_SD()     {
          display.clearDisplay();
    display.setTextSize(2);            
 display.setCursor(0, 10);
 display.println("No SD Card");
    display.display();
}
 
   void SYNC_BPM ()   {
     if  (BPM < 125)  {
      // do set 106x
      float Reading = ((BPM -6.00)/100);
      Speed =  Reading;
       playSdWav1.setPlaybackRate(Speed);   Bank = 3;  SCN_MAIN();  
        Serial.println(Speed);
     }
      if  (BPM > 125)  {
        float Reading2 = ((BPM -40.00)/100);
      Speed =  Reading2;        
       playSdWav1.setPlaybackRate(Speed);     Bank = 7;  SCN_MAIN();  
        Serial.println(Speed);
     }
   }
  void SCN_HOLD ()
                { PRESS_millis = millis();   PRESS_A = 1;  }

   void RAM_LOAD ()  {
                           for(int i = 0;i < 16; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    sizes[i] = myFile.size();
   //  Serial.printf(file = '%s', size = %ld\n",wav_31[i],sizes[i]);
    SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
    myFile.read(SMP_addr[i], sizes[i]);
    myFile.close();  
  }    
  }
           void PLAY_ARRAY (int x)     {
            // if (xkey==1)  
            {       playArray[x-1]->playRaw(SMP_addr[x-1] ,sizes[x-1]/2,1);     }  
         Serial.println("Empty");
           }                          
           void ARRAY_SPEED_SET ()  {
       
                  for(int i = 0; i < 16; i++)  {
  playArray[i]->setPlaybackRate(1.0);
}
           }
i also checked code with and without set playback_speed
C++:
  void ARRAY_SPEED_SET ()  {
        
                  for(int i = 0; i < 16; i++)  {
  playArray[i]->setPlaybackRate(1.0);
}
but no changes.
play for Array is written in line no.676
loading wav files to PSRAM is written in lines (666-671)
How to fix it???
 
You’re using
C++:
playArray[x-1]->playRaw(SMP_addr[x-1] ,sizes[x-1]/2,1);
to play WAV files, which means the first 22 “samples” played will actually be the WAV header, not audio data. You should be using:
C++:
playArray[x-1]->playWav(SMP_addr[x-1]);
This may give you a compilation error - in another thread you said you were using TeensyVariablePlayback 1.0.16, and you will need to update to 1.1.0 in order to get WAV playback from data loaded to memory.

Please note for the future that posting your entire program of ~700 lines of badly formatted code is not ideal for getting a quick answer, or even any answer at all. Arduino IDE can reformat your code for you - I forget the key combination but Google will find it. Creating a short example with only the essential code will make it much easier for others to help; in the example above, all the keyboard and screen code is irrelevant to the issue.

Of course, making that short example may mean you solve the problem, which is good 😊 or it may disappear, in which case the apparently irrelevant code may play a part after all. You then have to add bits of it back gradually, until you have the smallest possible code which shows the problem, and you can refer to that when you ask for help, e.g. “this works until I add the display code in”.
 
i have update "TeensyVariablePlayback " library to 1.1.0 . and used
C++:
playArray[x-1]->playWav(SMP_addr[x-1]);
as you mention above
but no changes found ...
 
Hmmm ... they should be identical ... though looking at your image of the Audacity window above, the traces are completely different, not just having a glitch at the start of the array one. Are you 100% sure you're playing the same file with the same settings?

If you attach your WAV file to a reply, I'll try it out here. You will probably have to put it in a ZIP file as the forum doesn't allow WAV files as attachments.
 
sorry for long code. Now i make a small code to test. this is :
C++:
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>

AudioPlaySdResmp playSdWav1;
AudioPlayArrayResmp  playArrayWav1;
 
AudioMixer4              mixer1;       
AudioOutputI2S i2s2;         
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, 0,  i2s2, 0); 
AudioConnection          patchCord4(mixer1, 0, i2s2, 1);    //
AudioConnection          patchCord5(playArrayWav1, 0,mixer1, 2);
AudioControlSGTL5000 audioShield;

  char *wav_31[16] = { "031_01.WAV", "031_02.WAV","031_03.WAV","031_04.WAV"};
File myFile;
         int16_t *SMP_addr[4];   
         uint32_t sizes[4]; 

void setup() {

     SD.begin(BUILTIN_SDCARD);
    Serial.begin(57600);
    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
            Serial.println("Unable to access the SD card");           
            delay(500);
        }
    }

    AudioMemory(128);
    audioShield.enable();
    audioShield.volume(1.0);
    playSdWav1.enableInterpolation(true);         
    playArrayWav1.enableInterpolation(true);         
    Serial.println("Audio TEST: Array_Play");
    
      for(int i = 0;i < 4; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    sizes[i] = myFile.size();
    SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
    myFile.read(SMP_addr[i], sizes[i]);
    myFile.close();   
      }
}


void loop() { 
  if (Serial.available() > 0) {
        int incomingByte = Serial.read();     //49 = 1
        switch (incomingByte) {
                    case 49:
                   playSdWav1.playWav(wav_31[0]); 
                   playSdWav1.setLoopType(looptype_repeat);               
                   Serial.println("WAV Played");
                        break;
                    case 50:
                    playArrayWav1.playRaw(SMP_addr[0],sizes[0],1);                     
                    Serial.println("ARRAY Played");    //
                        break;
                        case 51:
                      playSdWav1.stop();                       
                      Serial.println("Stopped");     
                        break;
                }
    }
}
with this code (with TeensyVariablePlayback version 1.1.0). You are seeing in code ,i have used "wav_31[0]" to play from sdWavPlay & same for PlayArray. But getting again quality difference. Another thing : As i am listening sound of ArrayPlay Different from sdWavPlay . when Array files reached to last sample , a 3rd different sound(Like ArrayPlay sound) is being listen.
as you recomend for ArrrayPlay
C++:
playArray[x-1]->playWav(SMP_addr[x-1]);
in above code ,i tried
C++:
  playArrayWav1.playRaw(SMP_addr[0]);
but got error following
C++:
Teensy_41_with_PSRAM:64: error: no matching function for call to 'AudioPlayArrayResmp::playRaw(int16_t*&)'
   64 |                     playArrayWav1.playRaw(SMP_addr[0]);
      |                     ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playsdresmp.h:14,
                 from C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/TeensyVariablePlayback.h:12,
                 from C:\Users\acer\Documents\Arduino\Teensy_41_with_PSRAM\Teensy_41_with_PSRAM.ino:4:
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:49:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(const char*, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; uint16_t = short unsigned int]'
   49 |         bool playRaw(const char *filename, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:49:14: note:   candidate expects 2 arguments, 1 provided
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:77:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(int16_t*, uint32_t, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; int16_t = short int; uint32_t = long unsigned int; uint16_t = short unsigned int]'
   77 |         bool playRaw(int16_t *data, uint32_t numSamples, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:77:14: note:   candidate expects 3 arguments, 1 provided
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:83:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(const unsigned int*, uint32_t, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; uint32_t = long unsigned int; uint16_t = short unsigned int]'
   83 |         bool playRaw(const unsigned int *data, uint32_t numSamples, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:83:14: note:   candidate expects 3 arguments, 1 provided
Using library Audio at version 1.3 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library TeensyVariablePlayback at version 1.1.0 in folder: C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback
Using library LittleFS at version 1.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\LittleFS
Using library Wire at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Wire
no matching function for call to 'AudioPlayArrayResmp::playRaw(int16_t*&)'
I am surprised that code
C++:
 playArray[x-1]->playRaw(SMP_addr[x-1]);  // where x is greater than 0
(with TeensyVariablePlayback 1.1.0). now not working ,got error almost as above
C++:
mixing_kpd_TeensyVariablePlayback:676: error: no matching function for call to 'AudioPlayArrayResmp::playRaw(int16_t*&)'
  676 |             {       playArray[x-1]->playRaw(SMP_addr[x-1]);     }
      |                     ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playsdresmp.h:14,
                 from C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/TeensyVariablePlayback.h:12,
                 from C:\Users\acer\Documents\Arduino\mixing_kpd_TeensyVariablePlayback\mixing_kpd_TeensyVariablePlayback.ino:5:
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:49:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(const char*, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; uint16_t = short unsigned int]'
   49 |         bool playRaw(const char *filename, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:49:14: note:   candidate expects 2 arguments, 1 provided
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:77:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(int16_t*, uint32_t, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; int16_t = short int; uint32_t = long unsigned int; uint16_t = short unsigned int]'
   77 |         bool playRaw(int16_t *data, uint32_t numSamples, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:77:14: note:   candidate expects 3 arguments, 1 provided
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:83:14: note: candidate: 'bool AudioPlayResmp<TResamplingReader>::playRaw(const unsigned int*, uint32_t, uint16_t) [with TResamplingReader = newdigate::ResamplingArrayReader; uint32_t = long unsigned int; uint16_t = short unsigned int]'
   83 |         bool playRaw(const unsigned int *data, uint32_t numSamples, uint16_t numChannels)
      |              ^~~~~~~
C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback\src/playresmp.h:83:14: note:   candidate expects 3 arguments, 1 provided
Multiple libraries were found for "Encoder.h"
 Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Encoder
 Not used: C:\Users\acer\Documents\Arduino\libraries\Encoder-1.4.2
Multiple libraries were found for "Keypad.h"
 Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
 Not used: C:\Users\acer\Documents\Arduino\libraries\Keypad-3.1.1
Using library Keypad at version 3.1.1 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
Using library Audio at version 1.3 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library TeensyVariablePlayback at version 1.1.0 in folder: C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback
Using library LittleFS at version 1.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\LittleFS
Using library Wire at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Wire
Using library Adafruit_GFX_Library at version 1.7.5 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Adafruit_SSD1306 at version 2.5.7 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_SSD1306
Using library Encoder at version 1.4.4 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Encoder
no matching function for call to 'AudioPlayArrayResmp::playRaw(int16_t*&)'
here a .rar file can be download ,which contain 4 audio .wav files used in sketch.
please check if is to fix .....????
 
I will download and have a look.

The error is not surprising. playRaw() has to be told the size of the sample array and channel count, so it needs the two extra parameters. playWav() doesn’t need those, because the required information is already in the header that is included in the file your code copies to memory.
 
OK, I've taken a look, and fixed a few items, resulting in the following code:
C++:
#include <Audio.h>
#include <TeensyVariablePlayback.h>

AudioPlaySdResmp playSdWav1;
AudioPlayArrayResmp  playArrayWav1;

AudioMixer4              mixer1;
AudioOutputI2S i2s2;
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, 0, i2s2, 0);
AudioConnection          patchCord4(mixer1, 0, i2s2, 1);    //
AudioConnection          patchCord5(playArrayWav1, 0, mixer1, 2);
AudioConnection          patchCord6(playArrayWav1, 1, mixer1, 3); // stereo! use both channels
AudioControlSGTL5000 audioShield;

#define NUM_WAVS 4 // avoid silly mistakes
const char *wav_31[NUM_WAVS] = { "031_01.WAV", "031_02.WAV", "031_03.WAV", "031_04.WAV"};
File myFile;
int16_t *SMP_addr[NUM_WAVS];
uint32_t sizes[NUM_WAVS];

void setup() {
  Serial.begin(57600);
  while (!(SD.begin(BUILTIN_SDCARD))) {
    Serial.println("Unable to access the SD card");
    delay(500);
  }

  AudioMemory(128);

  audioShield.enable();
  audioShield.volume(0.1); // 1.0 was way too loud, caused distortion
  playSdWav1.enableInterpolation(true);
  playArrayWav1.enableInterpolation(true);
  Serial.println("Audio TEST: Array_Play");

  for (int i = 0; i < NUM_WAVS; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    if (myFile)
    {
      sizes[i] = myFile.size();
      SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
      if (nullptr == SMP_addr[i])
        Serial.printf("Failed to allocate %d in EXTMEM for %s\n", sizes[i], wav_31[i]);
      else
      {
        if (sizes[i] != myFile.read(SMP_addr[i], sizes[i]))
        {
          Serial.printf("Failed to read in %s - wrong length\n", wav_31[i]);
          extmem_free(SMP_addr[i]); // free memory
          SMP_addr[i] = nullptr;    // mark as "not loaded"
        }
        else
          Serial.printf("Read %s into memory at %08X; %d bytes\n", wav_31[i], SMP_addr[i], sizes[i]);
      }
      myFile.close();
    }
    else
      Serial.printf("Failed to open %s\n", wav_31[i]);
  }
}


void loop() {
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    switch (incomingByte) {
      case '1':
        playSdWav1.playWav(wav_31[0]);
        playSdWav1.setLoopType(looptype_repeat);
        Serial.println("WAV looping from SD");
        break;
        
      case '2':
        if (nullptr != SMP_addr[0]) // only play if it loaded correctly
        {
          // playArrayWav1.playRaw(SMP_addr[0], sizes[0], 1);   // *** BUG: it's a WAV file, and stereo...

          // this would be correct, IF it were a stereo RAW file: the second
          // parameter is the number of SAMPLES, and each sample is 2 bytes per channel,
          // so divide the file size by 4
          // playArrayWav1.playRaw(SMP_addr[0], sizes[0]/4, 2);

          playArrayWav1.playWav(SMP_addr[0]);
          Serial.println("ARRAY Played");    //
        }
        break;
        
      case '3':
        if (playSdWav1.isPlaying())
        {
          playSdWav1.stop();
          Serial.println("Stopped WAV loop");
        }         
        else
          Serial.println("WAV loop not playing!");
        break;
    }
  }
}

Key points:
  • for me, a volume of 1.0 was way too loud, causing distortion; reduced to 0.1
  • you're loading WAV files to memory, so use playWav()
  • if you do use playRaw(), its second parameter is samples, not bytes - you supplied stereo files, then used playRaw() to play them as mono files with 4x the correct number of samples: this results in all sorts of problems
  • you connected both channels of playSdWav1, but only one of playArrayWav1. Depending on the files the difference in output might range from negligible to major
  • I had some issues because you hadn't put in any error checking - I've done that for you, at which point I realised I was using a Teensy with no PSRAM, so could only load one file to memory (which is enough)
  • protected against trying to play a sample file that didn't load properly
  • made your cases more readable by using character constants rather than ASCII codes
  • #defined the number of WAV files so the array sizes and load loop are guaranteed consistent
  • got rid of numerous warnings by defining wav_31[] as const
A number of these things are basic good practice, and I'd love to be able to recommend a decent tutorial for you to skim, but I don't really know of one. Unfortunately you will often find that even supposedly well-written library code is guilty of poor practice, e.g. the liberal use of "magic numbers" (like 4, 16, 49, 50 and 51...) rather than a suitable #define or similar. It's a bit of a minefield, I'm afraid :cry:
 
Thank you.... H4yn0nnyMou5e
code you provide in #7 is working , issue Title of this thread is solved . after applying your code , now i am geting same audio quality from sdWavPlay & ArrayPlay (PSRAM) thank you to fix it .
But I got new problem:
please take a look at this code inwhich 4 .wav files are being played from Serial input in Loop_mode.using this code SdwavPlay & ArrayPlay quality is same.
code is :

C++:
#include <Audio.h>
#include <TeensyVariablePlayback.h>

AudioPlaySdResmp playSdWav1;
AudioPlayArrayResmp  playArrayWav1;

AudioMixer4              mixer1;
AudioOutputI2S i2s2;
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, 0, i2s2, 0);
AudioConnection          patchCord4(mixer1, 0, i2s2, 1);    //
AudioConnection          patchCord5(playArrayWav1, 0, mixer1, 2);
AudioConnection          patchCord6(playArrayWav1, 1, mixer1, 3); // stereo! use both channels
AudioControlSGTL5000 audioShield;

#define NUM_WAVS 4 // avoid silly mistakes
const char *wav_31[NUM_WAVS] = { "003_01.WAV", "003_02.WAV", "003_03.WAV", "003_04.WAV"};
File myFile;
int16_t *SMP_addr[NUM_WAVS];
uint32_t sizes[NUM_WAVS];

void setup() {
  Serial.begin(57600);
  while (!(SD.begin(BUILTIN_SDCARD))) {
    Serial.println("Unable to access the SD card");
    delay(500);
  }

  AudioMemory(128);

  audioShield.enable();
  audioShield.volume(0.1); // 1.0 was way too loud, caused distortion
  playSdWav1.enableInterpolation(true);
  playArrayWav1.enableInterpolation(true);
  Serial.println("Audio TEST: Array_Play on sunday");

  for (int i = 0; i < NUM_WAVS; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    if (myFile)
    {
      sizes[i] = myFile.size();
      SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
      if (nullptr == SMP_addr[i])
        Serial.printf("Failed to allocate %d in EXTMEM for %s\n", sizes[i], wav_31[i]);
      else
      {
        if (sizes[i] != myFile.read(SMP_addr[i], sizes[i]))
        {
          Serial.printf("Failed to read in %s - wrong length\n", wav_31[i]);
          extmem_free(SMP_addr[i]); // free memory
          SMP_addr[i] = nullptr;    // mark as "not loaded"
        }
        else
          Serial.printf("Read %s into memory at %08X; %d bytes\n", wav_31[i], SMP_addr[i], sizes[i]);
      }
      myFile.close();
    }
    else
      Serial.printf("Failed to open %s\n", wav_31[i]);
  }
}


void loop() {
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    switch (incomingByte) {
      case '1':
        playSdWav1.playWav(wav_31[0]);
        playSdWav1.setLoopType(looptype_repeat);
        Serial.println("WAV looping from SD");
        break;
       
      case '2':
        if (nullptr != SMP_addr[0])
        {
          playArrayWav1.playWav(SMP_addr[0]);
          Serial.println("ARRAY Played");    //
        }
        break;
       
      case '0':
        if (playSdWav1.isPlaying())
        {
          playSdWav1.stop();
          Serial.println("Stopped WAV loop");
        }        
        else
          Serial.println("WAV loop not playing!");
        break;
         case 'Q':
        playSdWav1.playWav(wav_31[0]);    
        playSdWav1.setLoopType(looptype_repeat);  
        Serial.println("WAV looping from SD 003_01.WAV");
        break;
        case 'W':
        playSdWav1.playWav(wav_31[1]);  
        playSdWav1.setLoopType(looptype_repeat);  
        Serial.println("WAV looping from SD 003_02.WAV");
        break;
        case 'E':
        playSdWav1.playWav(wav_31[2]);    
        playSdWav1.setLoopType(looptype_repeat);  
        Serial.println("WAV looping from SD 003_03.WAV");
        break;
        case 'R':
        playSdWav1.playWav(wav_31[3]);    
        playSdWav1.setLoopType(looptype_repeat);  
        Serial.println("WAV looping from SD 003_04.WAV");
        break;
    }
  }
}
Running above code . Loop_mode for
Code:
{ "003_01.WAV", "003_02.WAV", "003_03.WAV"}
is seamlessly but not seamlessy for
Code:
{ "003_04.WAV"}
file .here is small cut after every turn you can listen it in this .
video. it is same problem what i was facing before some monthes in #post . in that post i was getting a breaking cut for all .wav files sometimes (not always). but now in this post i am getting breaking cut in loop for 4th .wav not for 1,2,3. here is Download link for 4 files , what are used in above code. here is aslo download link for All .wav files what i am using in my lengthy sketch.
Note : i tried check for 16 files
Code:
 {"003_01.WAV", "003_02.WAV","003_03.WAV","003_04.WAV","003_05.WAV","003_06.WAV","003_07.WAV","003_08.WAV","003_09.WAV","003_10.WAV","003_11.WAV","003_12.WAV","003_13.WAV","003_14.WAV","003_15.WAV","003_16.WAV"}
from them files
Code:
 {"003_01.WAV", "003_02.WAV","003_03.WAV","003_07.WAV","003_08.WAV" }
was in seamless loop,
Code:
 {003_04.WAV","003_05.WAV","003_06.WAV","003_09.WAV","003_10.WAV","003_11.WAV","003_12.WAV","003_13.WAV","003_14.WAV","003_15.WAV","003_16.WAV"}
was playing with a breaking cut in loop_mode.
you had recomend me
Code:
 AudioMemory(128);
i am using it from many months.
if you ask me to see
Code:
AudioMemoryUsage();
&
Code:
AudioMemoryUsageMax();
Code:
AudioMemoryUsage();
was = 2
Code:
AudioMemoryUsageMax();
was = 4 , when breaking occur in Loop_Mode.
I seemed you can fix it , if you see this problem on your Board.
I hope you can Solve it ,,
 
Ah, yes, this is quite a subtle one. The TeensyVariablePlayback library remembers the loop start and finish, even when playing back a different file ... I think this must be an original "feature", I don't recall changing it, but maybe I did.

So the issue you have is that 003_04.WAV is half the length of the other loops (which you may not have noticed...), and if you play it after any of the others then it doesn't loop until way too late. I think if you played it first then the other loops wouldn't play in full, but they seem to repeat anyway so maybe you wouldn't spot that.

The fix is to set the loop type to looptype_none just before playback starts, then immediately set it to looptype_repeat - this resets the loop limits. I've done this just once, by creating the loopFromSD() function to play SD files, and then using it for all four options; copying and pasting code then making minor edits to each copy is a good way to introduce bugs and give you an unmaintainable mess!

I then started having fun, and did the same for the files loaded into PSRAM, so 1, 2, 3 or 4 will loop those, 0 will stop them, and Q, W, E or R will start SD playback loops, and . (full stop) will stop those. Enjoy!

C++:
#include <Audio.h>
#include <TeensyVariablePlayback.h>

AudioPlaySdResmp playSdWav1;
AudioPlayArrayResmp  playArrayWav1;

AudioMixer4              mixer1;
AudioOutputI2S i2s2;
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, 0, i2s2, 0);
AudioConnection          patchCord4(mixer1, 0, i2s2, 1);    //
AudioConnection          patchCord5(playArrayWav1, 0, mixer1, 2);
AudioConnection          patchCord6(playArrayWav1, 1, mixer1, 3); // stereo! use both channels
AudioControlSGTL5000 audioShield;

#define NUM_WAVS 4 // avoid silly mistakes
const char *wav_31[NUM_WAVS] = { "003_01.WAV", "003_02.WAV", "003_03.WAV", "003_04.WAV"};
File myFile;
int16_t *SMP_addr[NUM_WAVS];
uint32_t sizes[NUM_WAVS];

void setup() {
  Serial.begin(57600);
  while (!(SD.begin(BUILTIN_SDCARD))) {
    Serial.println("Unable to access the SD card");
    delay(500);
  }

  AudioMemory(128);

  audioShield.enable();
  audioShield.volume(0.1); // 1.0 was way too loud, caused distortion
  playSdWav1.enableInterpolation(true);
  playArrayWav1.enableInterpolation(true);
  Serial.println("Audio TEST: Array_Play on sunday");

  for (int i = 0; i < NUM_WAVS; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    if (myFile)
    {
      sizes[i] = myFile.size();
      SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
      if (nullptr == SMP_addr[i])
        Serial.printf("Failed to allocate %d in EXTMEM for %s\n", sizes[i], wav_31[i]);
      else
      {
        if (sizes[i] != myFile.read(SMP_addr[i], sizes[i]))
        {
          Serial.printf("Failed to read in %s - wrong length\n", wav_31[i]);
          extmem_free(SMP_addr[i]); // free memory
          SMP_addr[i] = nullptr;    // mark as "not loaded"
        }
        else
          Serial.printf("Read %s into memory at %08X; %d bytes\n", wav_31[i], SMP_addr[i], sizes[i]);
      }
      myFile.close();
    }
    else
      Serial.printf("Failed to open %s\n", wav_31[i]);
  }
}


void loopFromSD(int n)
{
  playSdWav1.setLoopType(looptype_none);  // ensure that loop limits...
  playSdWav1.playWav(wav_31[n]);
  playSdWav1.setLoopType(looptype_repeat);  // ...get re-set here!
  Serial.printf("WAV looping from SD %s\n", wav_31[n]);
}

void loopFromArray(int n)
{
  if (nullptr != SMP_addr[n])
  {
    playArrayWav1.setLoopType(looptype_none);  // ensure that loop limits...
    playArrayWav1.playWav(SMP_addr[n]);
    playArrayWav1.setLoopType(looptype_repeat);  // ...get re-set here!
    Serial.printf("WAV #%d (%s) looping from array\n", n+1, wav_31[n]);
  }
  else   
    Serial.printf("WAV #%d not loaded\n",n+1);
}

void loop() {
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    switch (incomingByte) {
      case '1' ... '4': // GNU extension: MUST have spaces around the ...
        loopFromArray(incomingByte - '1');
        break;
        
      case '0':
        if (playArrayWav1.isPlaying())
        {
          playArrayWav1.stop();
          Serial.println("Stopped array loop");
        }
        else
          Serial.println("Array loop not playing!");
        break;
        

      case '.':
        if (playSdWav1.isPlaying())
        {
          playSdWav1.stop();
          Serial.println("Stopped WAV loop");
        }
        else
          Serial.println("WAV loop not playing!");
        break;
        
      case 'Q':
        loopFromSD(0);
        break;
        
      case 'W':
        loopFromSD(1);
        break;
        
      case 'E':
        loopFromSD(2);
        break;
        
      case 'R':
        loopFromSD(3);
        break;
    }
  }
}
 
Thank you Loop playback have been solved. You solved it because you see it yourself on your system And it was occurs continuously infront of you . You use set
Code:
looptype_none
before play file and set
Code:
looptype_repeat
after Play file. At the spot it fix my problem. When after sometime of play suddenly player begin taking a breaking cut in loop. i seemed that condition also been solved by your code ???? I will test it for long.
playback speed change may be needed in future.
Please take a look.
As you given code . wav files are loaded into PSRAM , if they are on SD card
C++:
 for (int i = 0; i < NUM_WAVS; i++) {
    myFile = SD.open(wav_31[i], FILE_READ);
    if (myFile)
    {
      sizes[i] = myFile.size();
      SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
      if (nullptr == SMP_addr[i])
        Serial.printf("Failed to allocate %d in EXTMEM for %s\n", sizes[i], wav_31[i]);
      else
      {
        if (sizes[i] != myFile.read(SMP_addr[i], sizes[i]))
        {
          Serial.printf("Failed to read in %s - wrong length\n", wav_31[i]);
          extmem_free(SMP_addr[i]); // free memory
          SMP_addr[i] = nullptr;    // mark as "not loaded"
        }
        else
          Serial.printf("Read %s into memory at %08X; %d bytes\n", wav_31[i], SMP_addr[i], sizes[i]);
      }
      myFile.close();
    }
    else
      Serial.printf("Failed to open %s\n", wav_31[i]);
  }
I deleted one wav file from SD card of them. Teensy loaded nothing to that memory addr
Code:
SMP_addr[i]
for that file. When I sent input to play that file. It gave beep sound and teensy board
became hanged , stopped working
To protect from that condition...

-If requested .wav file is not on SD card,
- if requested file is damaged .
- if file not open to load etc.

I want write following data in sketch and should be loaded to PSRAM in above conditions

WAV files converted to code by wav2sketch
#include "AudioSampleSnare.h"
#include "AudioSampleTomtom.h"
#include "AudioSampleHihat.h"
#include "AudioSampleKick.h"
i took these files from this Example
SamplePlayer.ino
i will copy paste 4 .h files & 4 .c++ file in main sketch folder and sketch Tabs

what code will load above 4 files data into 4 addresses
Code:
SMP_addr[i]
and
Code:
sizes[i]
???
with report in serial.print(); that above 4 files have been loaded to PSRAM
In SamplePlayer.ino 6 file are used . can i used 16 .h & .c++ files in sketch to load to PSRAM, every file is 1 sec long And mono channel ????
if no , what is other way to protect from Teensy board be hanged because of empty
Code:
SMP_addr[i]
. ????
Should I need
Code:
  if (nullptr == SMP_addr[n])
thank you
 
Last edited:
Back
Top