Trying to get play_queue to work

Status
Not open for further replies.

cartere

Well-known member
Code:
#include <Audio.h> 
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
//AudioInputAnalog analogPinInput(16); // analog A2 (pin 16)
AudioInputI2S    audioInput;         // audio shield: mic or line-in
AudioOutputI2S   audioOutput;        // audio shield: headphones & line-out

AudioPlayQueue   myQueue;
// Create Audio connections between the components
//
AudioConnection c1(myQueue, 0, audioOutput, 0);


// Create an object to control the audio shield.
// 
AudioControlSGTL5000 audioShield;
static  int16_t sintable[] = {
	     0,    784,   1569,   2352,   3134,   3914,   4692,   5467,
	  6239,   7007,   7770,   8529,   9283,  10031,  10774,  11509,
	 12238,  12960,  13673,  14379,  15075,  15763,  16441,  17109,
	 17767,  18414,  19051,  19675,  20288,  20889,  21477,  22052,
	 22613,  23162,  23696,  24216,  24721,  25212,  25687,  26147,
	 26591,  27019,  27431,  27826,  28204,  28566,  28910,  29237,
	 29546,  29838,  30111,  30366,  30603,  30822,  31022,  31203,
	 31366,  31510,  31634,  31740,  31827,  31894,  31942,  31971,
	 31981,  31971,  31942,  31894,  31827,  31740,  31634,  31510,
	 31366,  31203,  31022,  30822,  30603,  30366,  30111,  29838,
	 29546,  29237,  28910,  28566,  28204,  27826,  27431,  27019,
	 26591,  26147,  25687,  25212,  24721,  24216,  23696,  23162,
	 22613,  22052,  21477,  20889,  20288,  19675,  19051,  18414,
	 17767,  17109,  16441,  15763,  15075,  14379,  13673,  12960,
	 12238,  11509,  10774,  10031,   9283,   8529,   7770,   7007,
	  6239,   5467,   4692,   3914,   3134,   2352,   1569,    784,
	     0,   -784,  -1569,  -2352,  -3134,  -3914,  -4692,  -5467,
	 -6239,  -7007,  -7770,  -8529,  -9283, -10031, -10774, -11509,
	-12238, -12960, -13673, -14379, -15075, -15763, -16441, -17109,
	-17767, -18414, -19051, -19675, -20288, -20889, -21477, -22052,
	-22613, -23162, -23696, -24216, -24721, -25212, -25687, -26147,
	-26591, -27019, -27431, -27826, -28204, -28566, -28910, -29237,
	-29546, -29838, -30111, -30366, -30603, -30822, -31022, -31203,
	-31366, -31510, -31634, -31740, -31827, -31894, -31942, -31971,
	-31981, -31971, -31942, -31894, -31827, -31740, -31634, -31510,
	-31366, -31203, -31022, -30822, -30603, -30366, -30111, -29838,
	-29546, -29237, -28910, -28566, -28204, -27826, -27431, -27019,
	-26591, -26147, -25687, -25212, -24721, -24216, -23696, -23162,
	-22613, -22052, -21477, -20889, -20288, -19675, -19051, -18414,
	-17767, -17109, -16441, -15763, -15075, -14379, -13673, -12960,
	-12238, -11509, -10774, -10031,  -9283,  -8529,  -7770,  -7007,
	 -6239,  -5467,  -4692,  -3914,  -3134,  -2352,  -1569,   -784 };
int16_t *buf, *bufsave;
int i;
void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);

  // Enable the audio shield and set the output volume.
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(0.6);
   buf=myQueue.getBuffer();
   bufsave=buf;
  
}


void loop() {
 for(i=0;i<128;i++) {
    *buf=sintable[i];
    //Serial.println(*buf);
    buf++;
 }
 //buf=bufsave;
 myQueue.playBuffer();
  

}


This generates a tone ( well half a tone ) but after awhile the teensy goes away ( usb port unrecognized ). If I leave "buf=bufsave" in no tone. Any idea where I am going wrong?
 
Code:
       #include <Audio.h> 
        #include <Wire.h>
        #include <SD.h>
        #include <SPI.h>
        const int myInput = AUDIO_INPUT_LINEIN;
        //const int myInput = AUDIO_INPUT_MIC;

        // Create the Audio components.  These should be created in the
        // order data flows, inputs/sources -> processing -> outputs
        //
        //AudioInputAnalog analogPinInput(16); // analog A2 (pin 16)
        AudioInputI2S    audioInput;         // audio shield: mic or line-in
        AudioOutputI2S   audioOutput;        // audio shield: headphones & line-out

        AudioPlayQueue   myQueue;
        // Create Audio connections between the components
        //
        AudioConnection c1(myQueue, 0, audioOutput, 0);


        // Create an object to control the audio shield.
        // 
        AudioControlSGTL5000 audioShield;
        static  int16_t sintable[] = {
        	     0,    784,   1569,   2352,   3134,   3914,   4692,   5467,
        	  6239,   7007,   7770,   8529,   9283,  10031,  10774,  11509,
        	 12238,  12960,  13673,  14379,  15075,  15763,  16441,  17109,
        	 17767,  18414,  19051,  19675,  20288,  20889,  21477,  22052,
        	 22613,  23162,  23696,  24216,  24721,  25212,  25687,  26147,
        	 26591,  27019,  27431,  27826,  28204,  28566,  28910,  29237,
        	 29546,  29838,  30111,  30366,  30603,  30822,  31022,  31203,
        	 31366,  31510,  31634,  31740,  31827,  31894,  31942,  31971,
        	 31981,  31971,  31942,  31894,  31827,  31740,  31634,  31510,
        	 31366,  31203,  31022,  30822,  30603,  30366,  30111,  29838,
        	 29546,  29237,  28910,  28566,  28204,  27826,  27431,  27019,
        	 26591,  26147,  25687,  25212,  24721,  24216,  23696,  23162,
        	 22613,  22052,  21477,  20889,  20288,  19675,  19051,  18414,
        	 17767,  17109,  16441,  15763,  15075,  14379,  13673,  12960,
        	 12238,  11509,  10774,  10031,   9283,   8529,   7770,   7007,
        	  6239,   5467,   4692,   3914,   3134,   2352,   1569,    784,
        	     0,   -784,  -1569,  -2352,  -3134,  -3914,  -4692,  -5467,
        	 -6239,  -7007,  -7770,  -8529,  -9283, -10031, -10774, -11509,
        	-12238, -12960, -13673, -14379, -15075, -15763, -16441, -17109,
        	-17767, -18414, -19051, -19675, -20288, -20889, -21477, -22052,
        	-22613, -23162, -23696, -24216, -24721, -25212, -25687, -26147,
        	-26591, -27019, -27431, -27826, -28204, -28566, -28910, -29237,
        	-29546, -29838, -30111, -30366, -30603, -30822, -31022, -31203,
        	-31366, -31510, -31634, -31740, -31827, -31894, -31942, -31971,
        	-31981, -31971, -31942, -31894, -31827, -31740, -31634, -31510,
        	-31366, -31203, -31022, -30822, -30603, -30366, -30111, -29838,
        	-29546, -29237, -28910, -28566, -28204, -27826, -27431, -27019,
        	-26591, -26147, -25687, -25212, -24721, -24216, -23696, -23162,
        	-22613, -22052, -21477, -20889, -20288, -19675, -19051, -18414,
        	-17767, -17109, -16441, -15763, -15075, -14379, -13673, -12960,
        	-12238, -11509, -10774, -10031,  -9283,  -8529,  -7770,  -7007,
        	 -6239,  -5467,  -4692,  -3914,  -3134,  -2352,  -1569,   -784 };
        int16_t *buf, *bufsave;
        int i;
        void setup() {
          // Audio connections require memory to work.  For more
          // detailed information, see the MemoryAndCpuUsage example
          AudioMemory(12);

          // Enable the audio shield and set the output volume.
          audioShield.enable();
          audioShield.inputSelect(myInput);
          audioShield.volume(0.6);
           buf=myQueue.getBuffer();
           bufsave=buf;
          
        }


        void loop() {
         buf=myQueue.getBuffer();
         for(i=0;i<128;i++) {
            *buf=sintable[i];
            buf++;
         }
       
         
         myQueue.playBuffer();
         buf=myQueue.getBuffer();
         for(i=128;i<256;i++) {
            *buf=sintable[i];
            buf++;
        }
        myQueue.playBuffer();

        }

Working code, was confused by "Only a single buffer should be requested at a time."
 
Status
Not open for further replies.
Back
Top