bossredman
Well-known member
Thanks Frank!!
great !
you could store the value to a variable, too:
uint32_t position;
position = playMp31.positionMillis();
...
...
Serial.print ( position );
I'd buy a good "C" book !!!
The question re klicking noise I can not answer competently
I have an idea*, but want to hear others I'm a software guy..
There are a number of dc blocking and ground issues when connecting the audio card to a amplifier, the quickest thing to try would be use the line out to drive the amp. This is discussed in the huge audio adapter thread ( good luck ).
There are a number of dc blocking and ground issues when connecting the audio card to a amplifier, the quickest thing to try would be use the line out to drive the amp. This is discussed in the huge audio adapter thread ( good luck ).
#ifdef AUDIO_BOARD
sgtl5000_1.enable();
sgtl5000_1.volume(Vol_Val);
SPI.setMOSI(7);
SPI.setSCK(14);
#endif
Quick thought, run your signal path through a mixer object and control it's gain with the volume pot.
// Volume control
// uncomment if you have a volume pot soldered to your audio shield
/*
int n = analogRead(15);
if (n != volume) {
volume = n;
codec.volume((float)n / 1023);
}
*/
mixer1.gain(1,(float)n/1023);
My goal is to try to create a 'foot controlled' backing track player (mp3) - so ideally I'd like to s/w (via foot switches) to control all functionality if possible.Quick thought, run your signal path through a mixer object and control it's gain with the volume pot.
[B]AudioMixer4 mixleft;
AudioMixer4 mixright;[/B]
//mp3
AudioConnection patch1(playMp31,0,mixleft,0);
AudioConnection patch2(playMp31,1,mixright,0);
#ifdef AUDIO_BOARD
[B]AudioConnection patch5(mixleft, 0, i2s1, 0);
AudioConnection patch6(mixright, 0, i2s1, 1);[/B]
AudioControlSGTL5000 sgtl5000_1; //xy=240,153
#endif
//put the gain a bit lower, some MP3 Tracks will clip otherwise.
[B]mixleft.gain(0,0.9);
mixright.gain(0,0.9);[/B]
(Ignore teh mute/unmute lines - I was trying to stop (unsuccessfully) a "popping" sound when the Teensy re-boots)
Thanks.
#define AUDIO_BOARD // if using audioboard
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.h> //Buttons
#include <EEPROM.h> // store last track
#include <play_sd_mp3.h> //mp3 decoder
#define BUTTON1 2 //NEXT
#define BUTTON2 3 //Play Pause
#define BUTTON3 4 //PREV
#define BUTTON4 5 //Volume Up
#define BUTTON5 6 //Volume Down
Bounce bouncer1 = Bounce(BUTTON1, 50);
Bounce bouncer2 = Bounce(BUTTON2, 50);
Bounce bouncer3 = Bounce(BUTTON3, 50);
Bounce bouncer4 = Bounce(BUTTON4, 50);
Bounce bouncer5 = Bounce(BUTTON5, 50);
const int chipSelect = 10; // if using another pin for SD card CS.
int track;
int tracknum;
int trackext[255]; // 0= nothing, 1= mp3, 2= aac, 3= wav.
String tracklist[255];
int FolderX;
int FolderNumber = 0;
String FolderList[255];
int Current_Folder = 1;
int Current_Track = 0;
boolean browse_mode = false;
File root;
char playthis[21]; //was 15 originally. now 21 = folder(8), / (1), Trackname (8), . (1), ext (3)
boolean trackchange;
boolean paused;
boolean just_reboot = true; //tracks if just re-booted
uint32_t positionMillis();
AudioPlaySdMp3 playMp31;
#ifdef AUDIO_BOARD
AudioOutputI2S i2s1;
#endif
AudioMixer4 mixleft;
AudioMixer4 mixright;
//mp3
AudioConnection patch1(playMp31,0,mixleft,0);
AudioConnection patch2(playMp31,1,mixright,0);
#ifdef AUDIO_BOARD
AudioConnection patch5(mixleft, 0, i2s1, 0);
AudioConnection patch6(mixright, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=240,153
#endif
float Vol_Val = 0.5; //initial volume level value
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void setup() {
//while (!Serial) ;
delay(1000);
Serial.println("======= Void SETUP =======");
Serial.begin(115200);
#ifdef AUDIO_BOARD
sgtl5000_1.enable();
//sgtl5000_1.volume(Vol_Val); //headphones
sgtl5000_1.lineOutLevel(13);
sgtl5000_1.dacVolume(Vol_Val); //lineout
//sgtl5000_1.muteLineout();
//sgtl5000_1.unmuteLineout();
SPI.setMOSI(7);
SPI.setSCK(14);
#endif
//setup pins with pullups
pinMode(BUTTON1,INPUT_PULLUP);
pinMode(BUTTON2,INPUT_PULLUP);
pinMode(BUTTON3,INPUT_PULLUP);
pinMode(BUTTON4,INPUT_PULLUP);
pinMode(BUTTON5,INPUT_PULLUP);
// reads the last track what was playing.
track = EEPROM.read(0);
// Serial.print("EPROM last track: ");
// Serial.println(track);
// Audio connections require memory to work. For more detailed information, see the MemoryAndCpuUsage example
AudioMemory(16);
//put the gain a bit lower, some MP3 Tracks will clip otherwise.
mixleft.gain(0,0.9);
mixright.gain(0,0.9);
//Start SD card
if (!(SD.begin(chipSelect))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
//Starting to index the SD card for FOLDERS.
root = SD.open("/");
FindDirectory(root);
//files.close();
Serial.println("Select Folder - u=up / d=down");
Serial.print('\t');
Serial.print("Current Folder: ");
Serial.println(FolderList[Current_Folder]);
serialcontrols();
}
void Vol_Up()
{
Serial.println("======= Void VOL UP =======");
Vol_Val = Vol_Val + 0.05;
if(Vol_Val > 1)
{
Vol_Val = 1;
Serial.print("Vol: ");
Serial.print(Vol_Val);
Serial.println(" - MAX'd out!!!");
}
else
{
Serial.print("Vol: ");
Serial.println(Vol_Val);
}
//sgtl5000_1.volume(Vol_Val);
sgtl5000_1.dacVolume(Vol_Val);
}
//put the gain a bit lower, some MP3 Tracks will clip otherwise.
mixleft.gain(0,0.9);
mixright.gain(0,0.9);
dacVolume(both);
Normally output volume should be used with volume(), which changes the analog gain in the headphone amplifier. This function on the other hand controls digital attenuation before conversion to analog, which reduces resolution, but allows another fine control of output signal level. The ranges is 0 to 1.0, with the default (no digital attenuation) at 1.0.
dacVolume uses zero-crossing detect to avoid clicks, and ramping is handled by the chip so that a new volume may be set directly in a single call.
The SD socket is accessed with 4 SPI pins.
SCLK and MOSI are used at alternate locations.
Apologies for another daft question - but can some explain this a like further pls.
All the components are on the board, do you hear the pop on a reprogram or when you first apply power?
bossredman said:On every reprogram