Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: Looking for audio shield which can play seperate audio on left & right channels on: March 16, 2013, 07:14:22 am
If you are ready to settled for "decent quality" audio output you can try this.
http://hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio

Separate shield not necessary. Combine two mono tracks as a stereo track and play with this.There is a stereo setting in it.Just go with that.

manmachine.
2  Using Arduino / Programming Questions / Re: Playing 1000 songs from SD card on: March 16, 2013, 06:45:49 am
Hi,

    This is what worked for me.I am half way to my goal though.

Code:
#include <SD.h>              // need to include the SD library
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>        //  also need to include this library...

TMRpcm audio;   // create an object for use in this sketch
File myFile;
char trackname[] = "0000.wav"; //basic denomination
int tracknumber;
   
void setup(){

   audio.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
   Serial.begin(9600);
   if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
   Serial.println("SD fail"); 
   return;   // don't do anything more if not       
  }

   pinMode(2,INPUT);
   digitalWrite(2,HIGH);
   attachInterrupt(0,incfile,FALLING);
   
   pinMode(3,INPUT);
   digitalWrite(3,HIGH);
  // attachInterrupt(0,decfile,FALLING);
   
   sprintf(trackname, "%04d.wav",0);//startup file name
}
     
void loop(){   
 
    audio.play(trackname);
    while(audio.isPlaying()) {interrupts();}       
}

void incfile() {
     noInterrupts(); //diable further interrupts, avoid nesting
     if(tracknumber<100){tracknumber=tracknumber+1; //increment file name,curb the filename to 100(for testing=100) 
     Serial.println(tracknumber); //  debug line - to be discarded later
     sprintf(trackname, "%04d.wav",tracknumber);//calculate the file name
     Serial.println(trackname); //name of the new file to be played
     audio.stopPlayback();}  // this was found necessary to start the new file
                             //from the begining
     else{} 
}
/*void decfile() {
     noInterrupts();
     if(tracknumber!=0){tracknumber=tracknumber-1;   
     Serial.println(tracknumber);
     sprintf(trackname, "%04d.wav",tracknumber);
     Serial.println(trackname);
     audio.stopPlayback();}
     else{}       
}*/

@PaulS: Thank you for the ' sprintf ' hint. Could you please clarify a few more points?

Quote
As soon as that file quits playing, turn interrupts back on. Loop gets called again, and the process starts over.
What if the playing file is a long one and I want to switch to the next one , discontinuing the playing one ?

Quote
You should NOT be disabling interrupts 99.9999% of the time.
Even within the INTERRUPT service routine ? Wouldn't it leads to nesting ?

Sorry for a newbie question : If there are more than one INTERRUPT routine , as in the above code, how to place them in the sketch so that they are totally independent ? In the above code, the first one runs over the beneath one as well, and hence commented out for the time being.

@others:I have some difficulty in understanding interrupt handling in Arduino.Actually, I am thinking of adding some more buttons ( for- inc10s,inc100s,dec10s,dec100s,volume etc.)to be interfaced with additional logic circuits.Although, I know I can do this with the spare port pins, I prefer reseving those pis for display etc,.
So,could somebody point me to resources that may explain Arduino interrupts,to an 'assembly language' person ?

Thanks.

manmachine.
3  Using Arduino / Programming Questions / Re: Playing 1000 songs from SD card on: March 14, 2013, 11:59:15 pm
Thank you for answering guys.Much helpful piece of advice.
I'll get back with my outcome.

Manmachine
4  Using Arduino / Programming Questions / Playing 1000 songs from SD card on: March 13, 2013, 02:00:03 pm
Hi,

   I want some guidance to write a piece of code. I am not expert in coding.

   My gadget is Arduino atmega328 + LC Studio sd card breakout board.This gadget is to play wave audio files stored in the sd card.The wave files are numerically named as 0001.wav,0002.wav,0003.wav,....etc (they are 100s in numbers). I want to play these files as described below.

      I want to have 2 push buttons(called UP,DOWN) connected to the interrupts pins 2 & 3 respectively.At start-up, file "0001.wav" should be played.When I press 'UP' button once, file "0002.wav" should be played.Consecutively pressing 'UP', files with increment in name (0003.wav,0004.wav....so on), should be played. The 'DOWN' button is meant for decrement order play,you figured it out,I guess.

So far my code is this.

Code:
#include <SD.h>              // need to include the SD library
#define SD_ChipSelectPin 4       // using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>              // also need to include this library...

TMRpcm tmrpcm;                    // create an object for use in this sketch

void setup(){

  tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

   Serial.begin(9600);
   if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
   Serial.println("SD fail"); 
    return;   // don't do anything more if not   
  }
   
   pinMode(2,INPUT);
   digitalWrite(2,HIGH);
   attachInterrupt(0,otherfile,FALLING); 
}
   
void loop(){
    noInterrupts();     
    tmrpcm.play("0001.wav");
    while(tmrpcm.isPlaying()) {}
    interrupts(); 
}

void otherfile() {
     noInterrupts();
     delay(10);        // clean switching
     tmrpcm.play("0002.wav");
     while(tmrpcm.isPlaying()) {} 
}


I am successfuly played the start up file 0001.wav.I donot know how to proceed.I have tried interrupt service routine and able to play one of the remaining songs, though it is not a good way, as shown in the codes .How to go about this ?
      I sought your help.

 BTW, apart from the standard <SD.h> ,I'm using "tmrpcm" library found here.
https://github.com/TMRh20/TMRpcm
   
 Thank you in advance.

manmachine
5  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: March 09, 2013, 02:39:57 am
Hi,
   @Tuttut:Thank you for your reply.So, its going to be a different approach!Well,Could you post a FLOW CHART of the proposed lib implementation,what might be a possible solution.

manmachine
6  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: March 08, 2013, 12:05:47 am
Hi,

    I'm still getting audio glitch.May be,something wrong (sd card format etc)with my setup.Could you please confirm that the test file I am using (please see attachment)works Ok in your set up?

 
:  Thank you for the explanation about the patch.Now I understand little more about the 'worker' function and I try to understand your libs more deep.

manmachine
7  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: March 06, 2013, 01:52:46 pm
Hi,
   Sorry, that patch did not work.
  Result : Audio file not played.Instead, there were lot of glitches-only glitches.I have noticed that the glitches came out as a stream (loudest at the start and diminished along the time line and died in few seconds).But that was from "Bare minimum" sketch.
  When I tried the " Bare minimum with Debug", it gave a continuous tone of 125 hz approx.(No audio file content played).
But, sketch examples with worker (bare minimum with worker,bare minimum with worker with debug),worked normally,of course with the glitch.
 Could you please explain what exactly the patch modifies.
 Anyway, thank you for trying to help me.

manmachine.
 
8  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: March 05, 2013, 01:58:54 am
Thank you tuttut for the reply.
OK, I take the easy way you have mentioned.
One more question. I need to play a 5sec audio as a seamless loop:indefinitely .Though I am able to accomplish that with the "Bare minimum" you have provided,there occurs an audio glitch at the end-to-beginning of the file played. The file  has perfect zero-crossing at the beginning and in the end.Could you please suggest anything to avoid this problem.
(My gadget: Ardiuno Atmega 328+LC studio SDcard breakout board).
Thank you again.
9  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: March 04, 2013, 12:08:18 pm
Hi,
    Great lib.But, Is there any scope of varying the pitch/speed of the file in the SD card ?
Thanks.
Pages: [1]