Pages: [1]   Go Down
Author Topic: Simple program to output an mp3 or wav file?  (Read 553 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm very new to the world of MicroControllers and even C++ programing. I have managed to cobble together some code to emit a click from a speaker, but I need to figure out how to send out a single sound file (about 15kb in size) to said speaker. I have found nothing in the current examples in the newest version of the Arduino programming software, so if any one could point me in the right direction I'd be much appreciated.

If they can go a step further and point out where I can find some example code or even post some, that would be even better. I'm not asking for any one to do the work for me, just help in the right direction.

That said I am TOTALLY lost when it comes to programming.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where are you planning to store the 15 Kb file? An SD card?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was hoping that there was enough space to store the file in the memory, but will store it to an SD card if need be. the board I have has an ATMEGA328 so I was guessing (feel free to correct me) that the program would be a few KBs max and would accomodate the file i need to output.
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're probably going to need something like this:
http://www.sparkfun.com/products/10628
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even If i do need an external device that still doesn't help me with my current problem. I need to add an output sound to this code:

Code:

const int buttonPin = 2;
const int ledPin =  13;
const int spkrPin = 12;

int buttonState = 0;

void setup() {

  pinMode(ledPin, OUTPUT);   
  pinMode(spkrPin, OUTPUT);
  pinMode(buttonPin, INPUT);     
}

void loop(){

  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {     
    digitalWrite(ledPin, LOW); 
  }
  else {
    digitalWrite(ledPin, HIGH);
   
    if (buttonState == HIGH) {     
    digitalWrite(spkrPin, HIGH); 
  }
  else {
    digitalWrite(spkrPin, LOW);
  }
}
}


This code is 1,096 bytes with a max capacity of roughly 32kb (30 i believe after proper allocation). I just want to add a simple snippet to the above in order to load and output a small 15kb file (half of available storage).

Thanks again for any assistance!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Even If i do need an external device that still doesn't help me with my current problem. I need to add an output sound to this code:
Are you listening here? The external device that you need has a SD card reader and appropriate decoder chip to allow you to store a wav file on the SD card. Then, you just tell the device to play the file, and it does all the work.

Quote
I need to add an output sound to this code
Where is the data? The time to play each note, and which note to play? Just diddling the speaker pin will make a noise, but you have NO control over what noise it makes. Using the tone() library, you can play notes - recognizable, controllable sounds. The problem is that you can only play one note at a time, and most music is composed of multiple notes being played simultaneously.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand I'm going to need something to store the file onto if the memory can not store it. The problem I'm having is how do I call the file from where it is stored, output it and if extra hardware is needed, how do I code that into the existing program or what library do I look into to to write a new program that would do this job.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This code is 1,096 bytes with a max capacity of roughly 32kb (30 i believe after proper allocation). I just want to add a simple snippet to the above in order to load and output a small 15kb file (half of available storage).


32 Kb of program memory. You have 2 Kb of RAM. You won't fit 15 Kb into it. Time to rethink.
Logged

Pages: [1]   Go Up
Jump to: