Audio File player

Status
Not open for further replies.
great !
you could store the value to a variable, too:

uint32_t position;
position = playMp31.positionMillis();
...
...
Serial.print ( position );
 
Oh while I remember.
Could anyone pls explain why I would be hearing a clicking noise when I plug the audio adpaters jack into powered monitors, but its not there when I use headphones.
 
great !
you could store the value to a variable, too:

uint32_t position;
position = playMp31.positionMillis();
...
...
Serial.print ( position );

Yes thanks.
Once you'd explained the correct syntax it started to make a lot more sense.
Guess it was a bit of a silly question, but there's a lot of the basics I'm still struggling with.
 
The question re klicking noise I can not answer competently :)
I have an idea*, but want to hear others :) I'm a software guy..

void function(void)
The first "void" says, that the function does not return a value. The second "void" says, that it does not require a value.

uint32_t function(void)
the functin returns a value of type uint32_t (which is "unsigned 32 Bit")

void function(uint32_t)
the functions wants a value, (and perhaps does something with it). But it does not return a value.

uint32_t function(uint32_t)
..well.. both... :
example:

uint32_t foo(uint32_t abc) {
return abc * 7;
}

if you call it - for example with Serial.print (foo(3)); - you'll get 21 as answer.

I'd buy a good "C" book !!!




*there is a "short" for a short time when inserting. correct?
 
Last edited:
I'd buy a good "C" book !!!

Ha - yes good suggestion. I guess I've taken the lazy option and imposed on the good/helpful nature of folks on this forum.

I'd managed to fumble my way through my first project (midi foot controller) but looks like this one is a little more involved & complicated.

The question re klicking noise I can not answer competently
I have an idea*, but want to hear others I'm a software guy..

No other responses on the other question - would love to hear your idea pls?
 
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 ).

Thanks cartere - the thread you refer to, is it the one entitled "Audio Library" ? - ie
https://forum.pjrc.com/threads/24793-Audio-Library?highlight=audio+adapter+thread

That's a whooping 49 pages long - so matches your "huge" description! :)

I'll also take a look at using the Line OUT as you suggested.
Is all I need to do is wire a TSR compatible jack to the L, G & R connections on the Audio board?
Or do I need to add some pin defines/assignments in my code too?

Thanks.
 
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 ).

Hi - hooked up the LINE OUT and clicking has gone. Thanks cartere.

But now the volume control that was working with Franks Sketch with headphones does not.

Code:
#ifdef AUDIO_BOARD
    sgtl5000_1.enable();
    sgtl5000_1.volume(Vol_Val);
  
    SPI.setMOSI(7);
    SPI.setSCK(14);
  #endif

Is it even possible to control LINE OUT volume or by its nature is it fixed & I need to use teh amp volume?
 
Quick thought, run your signal path through a mixer object and control it's gain with the volume pot.
 
Quick thought, run your signal path through a mixer object and control it's gain with the volume pot.

Thanks - but trying to control teh volume via software as will be using all footswitches.

Found "sgtl5000_1.dacVolume(Vol_Val);" has some affect but doesnt seem to kick in until after 0.55 and maxes out at 1.

I'll keep reading but not sure I understand teh detail of all this enough to figure it out myself.
 
Frank I think he is referring to the pot on the audio card which can be setup like:

Code:
 // 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);
  }
  */
Instead of having it change the SGTL5000 headphone volume define a mixer and do something like:

Code:
mixer1.gain(1,(float)n/1023);

Which will change the lineout volume if the mixer is in the audio path.

bossredman if you will post the code and the above is your intent I will show you the changes that need to be made.
 
Hi cartere - thanks for sticking with me on this.

Just to remove any confusion, all ref's to the volume pot stemmed from your suggestion it was not something I was really looking to use:
Quick thought, run your signal path through a mixer object and control it's gain with the volume pot.
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.

I used Frank's sketch/example as a starting point (ie "Complete_MP3_AAC_MP4_M4A_example" ) & modified /"butchered" :) to my requirements.
So I "think" it already contains a mixer, based on this being in the code already.
Is that correct?

Code:
[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
Code:
//put the gain a bit lower, some MP3 Tracks will clip otherwise.
      [B]mixleft.gain(0,0.9);
      mixright.gain(0,0.9);[/B]


Here's teh relavent sections of code. (ie teh defines/declarations/setup & volume function).
Code:
(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);
}
 
OK thanks - increasing the '0.9' value seems to work.

I'd refrained from tweaking that value due to teh comment in teh original code:

//put the gain a bit lower, some MP3 Tracks will clip otherwise.
mixleft.gain(0,0.9);
mixright.gain(0,0.9);

What would you recommend best practice is moving fwd then? - ie:
1]Set my code to use a higher gain value & continue to control value by variying .dacVolume:

"sgtl5000_1.dacVolume(Vol_Val);"

or

2] change code to vary the mixer gains?
mixleft.gain(0,Vol_Val);
mixright.gain(0,Vol_Val);
 
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.

I have never used dacVolume but it looks like it has a lot going for it with no clicks and smooth ramps handled by the audio processor.
 
Thanks cartere.

I'll experiment with various settings between mixer & dacvolume.
I recall reading somewhere about a loss of resolution - any idea how that shows itself to audibly - is it really noticeable?

One more question pls - is the wiring of the Line OUT literally board to jack (ie no extra components).
Just trying to get to the bottom of the loud "pop" I now get from my powered monitors when the Teensy re-boots.

Thanks
 
Resolution should not be an issue if you are using this for a perceived loudness control, it takes about a 3db (2X) change before the human ear hears a change. All the components are on the board, do you hear the pop on a reprogram or when you first apply power?
 
Apologies for another daft question - but can some explain this a like further pls.

it just means SCLK = pin 14 and MOSI = pin 7. (most libraries default to SCLK = pin 13 and MOSI = pin 11, which is arduino convention). take a look at the pinout: https://www.pjrc.com/teensy/pinout.html , there's several pins that can serve alternate functions (light grey) or, seen the other way round, you can map certain functions to various (physical) pins. in case of the audio board, pin 11 is used as the i2s MCLK signal and pin 13 as ADC data / I2S_RX, so they're not available for SPI
 
If I can just get rid of this "pop" on each re-program - I'd say I was almost there with the proto stage of this project.

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

Snap14.jpg

FYI - this is how I've wired up a 6.25mm jack to the LineOUT pins on the Audio Adapter.
NOTE: nothing is connected to the 2 pins above the L & R resp as they are un-marked.
Is this correct?
 
Status
Not open for further replies.
Back
Top