Pages: [1]   Go Down
Author Topic: How to play music on ethernet shield Micro-SD file.mp3?  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this code but may problem is when i compile the Audio.begin(.... errors  i think the Audio.h library.
where i can find the Audio.h library?
Code:
/*

 Demonstrates the use of the Audio library for the Arduino Due

 Hardware required :
 *Arduino shield with a SD card on CS 4 (the Ethernet sheild will work)
 *Speaker attched to ground and DAC0

 Original by Massimo Banzi September 20, 2012
 Modified by Scott Fitzgerald October 19, 2012

*/

#include <SD.h>
#include <SPI.h>
#include <Audio.h>

void setup()
{
  // debug output at 9600 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    return;
  }
  Serial.println(" done.");
  // hi-speed SPI transfers
  SPI.setClockDivider(4);

  // 44100Khz stereo => 88200 sample rate
  // 100 mSec of prebuffering.
  Audio.begin(88200, 100);
}

void loop()
{
  int count=0;

  // open wave file from sdcard
  File myFile = SD.open("test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

  const int S=1024; // Number of samples to read in block
  short buffer[S];

  Serial.print("Playing");
  // until the file is not finished
  while (myFile.available()) {
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

    // Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();

  Serial.println("End of file. Thank you for listening!");
  while (true) ;
}
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31471
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code says:-
Quote
Demonstrates the use of the Audio library for the Arduino Due
So you have a Due? With an SD card?
Therefore you need the Arduino IDE version 1.5 or greater, have you got that?
Logged

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

Yes sir, i have it, but when i run the msg. is  on Audio.begin(....cursor stop here...
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31471
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you mean by:-
Quote
but when i run the msg.

You need to post the first three lines of the error message you get.
Logged

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

i'm only compiling not uploading.


* pic.png (68.79 KB, 1911x883 - viewed 33 times.)
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have the Arduino Uno board selected. You need to select the Due for the IDE to find Arm specific libraries, like Audio, correctly.
« Last Edit: December 18, 2012, 09:06:33 am by dxw00d » Logged

Pages: [1]   Go Up
Jump to: