Pages: [1]   Go Down
Author Topic: Button that plays mp3/wav sound file on laptop  (Read 1082 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

He guys,

Noob speaking here. I'm really stuck. I don't know much about the Arduino, but I need to make something that is not very hard I think. What I need is a way to play a sound (mp3,wav) from my computer, on my computer, by using a button connected to my Arduino. How is this possible? If you can help me, you'l be a hero!

Cheers


Logged

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

The Arduino detects the button press, and sends a message over Serial. You'll need something running on your PC that will receive the Serial data and play the MP3 file. A Processing sketch (http://processing.org), using the Minim library (http://code.compartmental.net/tools/minim/), could do that.
Logged

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

Great! This is helping smiley-cool

Now I found this example code to play a file with Minim:

/**
  * This sketch demonstrates how to play a file with Minim. <br />
  * It's also a good example of how to draw waveforms using the sample buffers of an AudioSource.
  */

import ddf.minim.*;

Minim minim;
AudioPlayer player;

void setup()
{
  size(512, 200, P3D);
  minim = new Minim(this);
  // load a file, give the AudioPlayer buffers that are 2048 samples long
  player = minim.loadFile("marcus_kellis_theme.mp3", 2048);
  // play the file
  player.play();
}

void draw()
{
  background(0);
  stroke(255);
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  // note that if the file is MONO, left.get() and right.get() will return the same value
  for(int i = 0; i < player.bufferSize() - 1; i++)
  {
    float x1 = map(i, 0, player.bufferSize(), 0, width);
    float x2 = map(i+1, 0, player.bufferSize(), 0, width);
    line(x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50);
    line(x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50);
  }
}

void stop()
{
  // always close Minim audio classes when you are done with them
  player.close();
  // always stop Minim before exiting
  minim.stop();
 
  super.stop();
}



Where can I say that it has to be triggered by a button?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31431
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to let that program communicate with the serial port first. Then look at the serial port for your message. When it arrives you do what is in your draw function.
Logged

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

Sorry, i'm trying to understand it, but what do you mean by communicate with the serial port? Do I have to do that in the code, or with the Arduino software?

Something like this: http://processing.org/reference/libraries/serial/Serial.html ?
« Last Edit: December 05, 2012, 06:37:26 am by BlackDynamite » Logged

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

Quote
Do I have to do that in the code, or with the Arduino software?

Both. Have a look at the Serial I/O -> SimpleRead example in Processing. At the bottom of the sketch, in a comment block, is a simple Arduino sketch that sends the result of a digitalRead() over Serial. The example sketch changes the colour of a rectangle, but you can add your Minim code to it.
Logged

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

Thanks! I deleted the comment section and replaced it with the Minim code. h

ttps://gist.github.com/4215638

But i get this warning (see attachment)


* Schermafbeelding 2012-12-05 om 14.50.04.png (39.49 KB, 597x744 - viewed 21 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31431
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only have one setup and draw function in a sketch. You have to merge the codes.
Most likel you don'tknowhow to do that. It's one of the problems that cut and paste programming gives you. You will have to learn at least the very basics of what you are doing.
Try a few of the examples and get a feel for what you are doing.
Logged

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

I understand what you mean. Unfortunately I don't have much time.. But really thanks for the thinking and helping me out. I'm going with this information to my teacher and hope he can help me complet the project..

Cheers
Logged

Pages: [1]   Go Up
Jump to: