Git Product home page Git Product logo

tmrpcm's People

Contributors

brewmanz avatar d-a-v avatar ftp27 avatar gandy92 avatar ivankravets avatar kevinwchang avatar tmrh20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmrpcm's Issues

TMRpcm & ISR(TIMER1_CAPT_vect)

Hi people... I am fighting and don't get solution.
I try to read SMPTE timecode across de ISR. I've changed the timer1 by timer2 with sucess. Y read the SD card with sucess, but, when i tried to read/write a vector, the audio dessapears.
Here is part of the code...

#define icpPin 8 // ICP input pin on arduino
#define one_time_max 600 // 600 these values are setup for NTSC video
#define one_time_min 300 // 400 PAL would be around 1000 for 0 and 500 for 1
#define zero_time_max 1200 // 1050 80 bits times 29.97 frames per sec
#define zero_time_min 700 // 950 equals 833 (divide by 8 clock pulses)

#define end_data_position 63
#define end_sync_position 77
#define end_smpte_position 80

#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 10 //using digital pin 4 on arduino nano 328
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
#include <SoftwareSerial.h>

#define CLR(x, y) (x &= (~(1<<y)))
#define SET(x, y) (x |= (1<<y))

#define d0 2
#define d1 9//3 // 3 es pata 5 - 9 que es pata 15
#define d2 4
#define in A0

#define inh1 A1
#define inh2 A2
#define inh3 A3
#define inh4 A4

#define Tx 7
#define Rx A5//8
//********************************************************
volatile char timeCode[11];
volatile unsigned int bit_time;
volatile unsigned int bit_time_min = 1000;
volatile unsigned int bit_time_max = 0;
volatile boolean valid_tc_word;
volatile boolean ones_bit_count;
volatile boolean tc_sync;
volatile boolean write_tc_out;
volatile boolean drop_frame_flag;

volatile byte total_bits;
volatile byte current_bit;
volatile byte sync_count;

SoftwareSerial serie(Rx, Tx);

TMRpcm tmrpcm;
int lastInput;
byte lastD0 = 0, lastD1 = 0;

void setup()
{
//******************************************************************************************
pinMode(icpPin, INPUT); // ICP pin (digital pin 8 on arduino) as input

bit_time = 0;
valid_tc_word = false;
ones_bit_count = false;
tc_sync = false;
write_tc_out = false;
drop_frame_flag = false;
total_bits = 0;
current_bit = 0;
sync_count = 0;

delay (200);

TCCR1A = B00000000; // clear all
TCCR1B = B11000010; // ICNC1 noise reduction + ICES1 start on rising edge + CS11 divide by 8
TCCR1C = B00000000; // clear all
TIMSK1 = B00100000; // ICIE1 enable the icp
TCNT1 = 0; // clear timer1
//***********************************************************************
pinMode(d0, OUTPUT);
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(in, INPUT);
pinMode(inh1, OUTPUT);
pinMode(inh2, OUTPUT);
pinMode(inh3, OUTPUT);
pinMode(inh4, OUTPUT);
//pinMode(LED, OUTPUT);

tmrpcm.speakerPin = 3;

Serial.begin(115200);
serie.begin(115200);
Serial.println("Finished setup... ");
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
}
tmrpcm.play("UnoF.wav");}

void loop()
{
//**********************************************************
if (write_tc_out)
{
write_tc_out = false;
/if (drop_frame_flag) Serial.print("TC DROP FRAME");
if (!drop_frame_flag) Serial.print("TC NO DROP FRAME");
Serial.print((char
)timeCode);/
Serial.print("\r\n");
Serial.println("......");
delay (40);
}
//
*********************************************************
if (lastInput != readInput())
{
unsigned long inicio = millis();
cli();sei();
switch(readInput())
{
case 1:
{
lastInput = 1;
player(1);
serie.write(lastInput);
break;
}
case 2:
{
lastInput = 2;
player(2);
serie.write(lastInput);
break;
}
case 3:
{
lastInput = 3;
player(3);
serie.write(lastInput);
break;
}
}
}
if(serie.available()>0)
{
byte dato[3];
serie.readBytes(dato, 3);
//Serial.print("D0: ");Serial.print(dato[0]);Serial.print("; D1: ");Serial.print(dato[1]);Serial.print("; D2: ");Serial.println(dato[2]);
if(dato[0]<32 && dato[1]<32 && dato[2]<32)
{
if(lastD0 != dato[0])
{
lastD0 = dato[0];
player(dato[0]);
}
if(lastD1 != dato[1])
{
lastD1 = dato[1];
player(dato[1]+16);
}
}
else
if(dato[0] == 98 && dato[1] == 98 && dato[2] == 98)
{
//LEDdigitalWrite(LED, LOW);
Serial.println("Desconectado...");
}
//if(dato[0] == 99 && dato[1] == 99 && dato[2] == 99) digitalWrite(LED, HIGH);
}
}

//*******************************************************************
int readInput()
{
CLR(PORTC, 1) ;
SET(PORTC, 2) ;
SET(PORTC, 3) ;
SET(PORTC, 4) ;
switch (switchIn())
{
case 1: return 1; break;
case 2: return 2; break;
case 3: return 3; break;
case 4: return 4; break;
case 5: return 5; break;
case 6: return 6; break;
case 7: return 7; break;
case 8: return 8; break;
}
}
//*******************************************************************
int switchIn()
{
CLR(PORTD, 2) ;
CLR(PORTB, 1);//CLR(PORTD, 3) ;// Cambia por B1
CLR(PORTD, 4) ;
delay(1);
if (digitalRead(in)) return 1;

SET(PORTD, 2) ;
CLR(PORTB, 1);//CLR(PORTD, 3) ;
CLR(PORTD, 4) ;
delay(1);
if (digitalRead(in)) return 2;
}
//Player
void player(byte num)
{
switch (num)
{
case 1:
{
Serial.println("Play 1");
tmrpcm.play("UnoM.wav");
delay(10);
break;
}
case 2:
{
Serial.println("Play 2");
tmrpcm.play("DosM.wav");
delay(10);
break;
}
case 3:
{
Serial.println("Play 3");
tmrpcm.play("TresM.wav");
delay(10);
break;
}
case 4:
{
Serial.println("Play 4");
tmrpcm.play("CuatroM.wav");
delay(10);
break;
}
}
}
//
****************************************
ISR(TIMER1_CAPT_vect)
{
//toggleCaptureEdge
byte tc[8];
int lastTime = 0;
int time = micros();
TCCR1B ^= _BV(ICES1); // Invierte el flanco de deteccion
bit_time = ICR1;
TCNT1 = 0; //resetTimer1
if(bit_time < bit_time_min && bit_time > one_time_min) bit_time_min = bit_time;
if(bit_time > bit_time_max && bit_time < zero_time_max) bit_time_max = bit_time;
if ((bit_time < one_time_min) || (bit_time > zero_time_max)) // get rid of anything way outside the norm
{
total_bits = 0;
}
else
{
if (ones_bit_count == true) ones_bit_count = false;// only count the second ones pluse
else
{
if (bit_time > zero_time_min)
{
current_bit = 0;
sync_count = 0;
}
else //if (bit_time < one_time_max)
{
ones_bit_count = true;
current_bit = 1;
sync_count++;
if (sync_count == 12) // part of the last two bytes of a timecode word
{
sync_count = 0;
tc_sync = true;
total_bits = end_sync_position;
}
}
if (total_bits <= end_data_position) // timecode runs least to most so we need
{ // to shift things around
tc[0] = tc[0] >> 1;
for(int n=1; n<8; n++)
{
if(tc[n] & 1) tc[n-1] |= 0x80;
tc[n] = tc[n] >> 1;
}
if(current_bit == 1)tc[7] |= 0x80;
}
total_bits++;
}
if (total_bits == end_smpte_position) // we have the 80th bit
{
total_bits = 0;
if (tc_sync)
{
tc_sync = false;
valid_tc_word = true;
lastTime = time;
}
}
if (valid_tc_word)
{
valid_tc_word = false;
/timeCode[10] = (tc[0]&0x0F)+0x30; // frames
timeCode[9] = (tc[1]&0x03)+0x30; // 10's of frames
timeCode[8] = ':';
timeCode[7] = (tc[2]&0x0F)+0x30; // seconds
timeCode[6] = (tc[3]&0x07)+0x30; // 10's of seconds
timeCode[5] = ':';
timeCode[4] = (tc[4]&0x0F)+0x30; // minutes
timeCode[3] = (tc[5]&0x07)+0x30; // 10's of minutes
timeCode[2] = ':';
timeCode[1] = (tc[6]&0x0F)+0x30; // hours
timeCode[0] = (tc[7]&0x03)+0x30; // 10's of hours
/

  if(tc[1]&0x04) drop_frame_flag = true;
  else drop_frame_flag = false;
  
  //drop_frame_flag = bit_is_set(tc[1], 2);
  write_tc_out = true;
}

}
}

That is the code... and when i do somethin with timeCode[XX] the sound dessapear...

I'm lost... Could you give a hand ???

Ubuntu 14.04 pcmConfig.h Error

Hello there I have a question about an error that I am facing. I download the latest version of TMRpcm and imported to Arduino IDE 1.0.5 for Ubuntu 14.04 and trying to upload to my nano. Then state as following error, (SdAudio.ino :1.68: fatal error: pcmConfig.h: No such file or directory compilation terminated.). And the weird part is its there can't seem to find a solution so I thought I would report this issue to see if there's a solution.

Support for UsbFat library

Hello @TMRh20 ,

I want to build a program that will seek audio file inside a USB DOK (DisK On Key) when it is inserted to the USB Host shield. (link: http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino )

I've saw that there's an example with a SD card (sdfat.ino).
I've fiddled a lot to get the USB Host Shield 2.0 library (link: https://github.com/felis/USB_Host_Shield_2.0) to work and succeeded.

However I've found a simpler implementation of it in the UsbFat library: https://github.com/greiman/UsbFat

Can you help me connect between these two libraries (UsbFat & TMRpcm) and hopefully produca a similar example sketch?

3 Audio simultaneously

Hi everyone,

I am trying to modfy the code for my application. My goal is playing 2 audio simultaneously using 1 timer and playing the last audio file with another timer. These are done seperately as Multi_Mode and Mode2. I want to combine these 2 features. But I am not a good coder. Can anyone guide me to figure this out ?

TMRpcm Freezing Other Processes

My partner and I are using your TMRpcm library for a school project and we are running into some troubles with it. Before anything, I must say it is a really great piece of work, thank you for making it! The issue we are having is that once a sound file is played, the Arduino freezes, and our following code (graphics rendering on a LCD and its calculations) runs very slowly or not at all until the song ends. We are using an Arduino Mega. I realize that TMRpcm is processor intensive; however, I was wondering if you knew of any possible workarounds or fixes.

Support for the Due?

The Due has the ability to run the PWM ports at 12 bit; which should improve sound quality greatly! It also has two dedicated DAC ports, but they have lots of digital noise and pops when starting a file.

I have two Due's at my disposal, I can help and test if needed.

question about recording

hello, i have a little question about the recording mode, I want to record a signal that's little ( 1V peak to peak) and i would prefer not to amplify it ( if possible) before putting it into the arduino. so my signal will theoretically oscillate between 2 and 3 volts before going to the arduino, does the tmrpcm library notice it and uses the 10 bit resolution between 2 and 3 volts are does he uses the 10 bits resolution between 0 and 5 volts ? if so is there a way to make it only take the voltage between 2 and 3 volts ?

i hope my question is clear and thanks to anyone who can help me

have a nice day

Starting Music and Pwm Signal Down

Hi,

im control arduino with RC car transmitter. receiver signal pins connected A0, A1, A2.
İm read signal 1000-2000 and mapping -255/255. 0 (Zero) center position.

Speaker connected 9. Pin on Arduino Uno

İm starting arduino, transmitter at center position and serial print analog pins 0 value.
İm doing button up Serial print 255 and button down Serial print -255.
No problem so far...
Again transmitter center position, Serial Print
A0: 0
A1: 0
A2: 0

Button down
A0: -255
A1: -255
A2: -255

Button Up
A0: 255
A1: 255
A2: 255

only start playing wav and later

A0: -255
A1: -255
A2: -255

Music continues playing, Button down
A0: -255
A1: -255
A2: -255

Music continues playing, Button up

A0: -130
A1: -130
A2: -130

And stop play music.
returns to normal
A0: 0
A1: 0
A2: 0

I would be very happy if you help

Thanks

im not able to compile even the basic example

Arduino: 1.6.7 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Users\Diksha\AppData\Local\Temp\arduino_5484f871416f9ce1317bba18f537edf5\basic.ino: In function 'void setup()':

C:\Users\Diksha\AppData\Local\Temp\arduino_5484f871416f9ce1317bba18f537edf5\basic.ino:19:22: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

tmrpcm.play("music"); //the sound file "music" will play each time the arduino powers up, or is reset

                  ^

C:\Users\Diksha\AppData\Local\Temp\arduino_5484f871416f9ce1317bba18f537edf5\basic.ino: In function 'void loop()':

C:\Users\Diksha\AppData\Local\Temp\arduino_5484f871416f9ce1317bba18f537edf5\basic.ino:28:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   tmrpcm.play("music");

                      ^

C:\Users\Diksha\Documents\Arduino\libraries\arduino_420772\pcmRF.cpp:8:20: fatal error: SdFat.h: No such file or directory

#include <SdFat.h>

                ^

compilation terminated.

Multiple libraries were found for "SD.h"
Used: C:\Users\Diksha\Documents\Arduino\libraries\SD
Not used: C:\Users\Diksha\Documents\important\softwares\Arduino\libraries\SD
exit status 1
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

can i change playback speed.

Hi, first of all congratulate you for your work.
Im using a nano v3 328 for audio playback in a project of mine. I want to change playback speed of wav files. Can I change the playback speed when playing files?

Looping one file, but allowing others to play.

Hi, I see you have added a looping function so I decided to test it.

It works great but as it loops the output, pressing a switch for other tracks to play seem to loop as well.

Perhaps adding a audio.loop("etc.wav") feature?

Cheers!

Range of volume level

Hi all,

I would like to know if there is any way to change the range of volume level. For example I would like to set it between 1 to 100 instead of 1 to 7.

Thanks a lot.
Blas.

Volume issue

i found some bug in the volume controls...

instead of volume 0-7, its -2 - 7 ( -2 is volume off and 7 is max volume.... if its more then 7... volume is off)

need to fix it so that if its on 0 then volume is off and cant go any lower then 0 and if volume is 7 its max volume and if u try pushing volume up again it will stay at 7 and not turn volume off

for the set volume the issue is the same in a way...
setVolume(0) = volume 2 and not volume level 0
setVolume(5) = volume 7 and not volume level 5

any thing more then setVolume(5) will just end up being silence...

these volume need to be fix...

PWM signal after music stops

Hi there,
I would like to report a bug, or it is not really a bug. I am not sure.

I tried this on Arduino Uno, Leonardo and mega328 alone, and it is very consistent.

Setup oscilloscope on output D9 I got this
2
32kHz Square wave about 25% duty circle.

Connect D9 to RC lowpass filter 1k Ohm and 15nF which has cut-off frequency about 10kHz
im_grph

You can see the amplitude of 32Khz is still quite high.

I got sawtooth signal on the output
1

Of course I can change the cap to 68nF which cut-off frequency is about 2kHz to eliminate 32Khz square wave, but it also cut-off part of music too.

It happens right after playing the first song. And it stays there even after music stops. It is quite annoying. With that noise like that, I am not sure connect it to professional audio equipment is safe, even with a coupling capacitor.

Like I said, I am not sure this is a bug or it happens because of the mechanism of generate analog signal from PWM.

Best regards,
Simon Vu

Slow Audio Playback

I have tried using TMRpcm with a Catalex micro sd reader. I converted the wav to a couple of different sample frequencies and they have been done at 8 bit, I can get the sound file to play, but it does so slowly, so the speech is slowed down by at least a factor of two or more?

Any ideas on what I've done wrong?

cheers
Rob

Lower footprint?

Just started to play with the library and its working great. However, I don't think I'll be able to use because of its footprint. Any suggestions on how to lower it? Just running a simple sketch (e.g. one of the examples) takes about half of the available storage space on the Arduino I have used.

Buzzing Sound While Using TMRpcm

Hi,

I am a newbie and doing a school project to learn more on Arduino.

I have Arduino Uno and ethernet shield. I have connected these two and also have put a formatted micro SD card in the SD card reader of the ethernet shield. I have connected a basic speaker from a local hobby shop on pin 9 and ground.

When I try to run a program at http://www.arduino.cc/en/Tutorial/Tone, it works perfectly fine. The only minor change is that I have used pin 9 instead of pin 8, and this tutorial works perfectly fine for me.

My next goal is to play a simple audio file.

For this, I am trying to use TMRpcm, the same circuit and sample programs giving me buzzing sound on my output. Here is my code, but I believe the issue may be with my circuit itself:

include <SD.h>

define SD_ChipSelectPin 4

include <TMRpcm.h>

TMRpcm tmrpcm;
char mychar;

void setup(){

tmrpcm.speakerPin = 9;

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
Serial.println("SD successful");
}
tmrpcm.setVolume(7);
tmrpcm.quality(1);

tmrpcm.play("DRUM1.WAV"); // sample file I created using given specification using audacity

}

void loop() {
Serial.print("In loop"); // This is just a dummy code
delay(5000);

}

This just brings up some buzzing sound for about 20 seconds. Can someone help with point me to right circuit for this, or point me to a simple audio file player?

Thanks.

conflicting files on SD card when audio is playing?

ok not sure if any one else is having this issue but when i have raw image files on my sd card and when audio wav is playing all my image gets all messed up?

when audio is stopped, all image goes back to normal again... any idea?

using a arduino mega 2560 on speaker pin on 11... with a 320x240 tft lcd touch screen and lcd shield for the tft

Goes quiet after repeated plays

Hello! I'm having another issue. I'm using the same setup as I mentioned in my previous issue, (slightly sketchy arduino leonardo and SD card reader), and am successfully playing great sound. However, After a number of plays (seemingly random - sometimes as high as fifty or a hundred and once as low as two (after increasing buffer size)), the sound will cut out, and nothing more will play. This happens in both multi and single mode, MODE2 or not. Our original code responded to inputs using input_pullup and force-sensitive resistors connected to ground, but we get the same effect with just:

loop(){
tmrpcm.play("hat.wav",0);
delay(1000);
}

We are playing a high number of short sound files, and are wondering if there could be a problem with random repeated SD card reads or a memory issue playing multiple files (or even one file played multiple times). Any suggestions?

Support For 1284P

The 1284P is an Arduino supported microcontroller which I've been using for sometime.

It's shown among other supported controllers here, http://playground.arduino.cc/Main/ArduinoOnOtherAtmelChips

I've downloaded your library and got the SD working however nothing seems to happen when I try to play something.

Check out the pin out with pin functions and can you confirm which pin I should be using. I've tried using D15 as its a PWN output. Should I try any other pins? Does it need to be on a timer pin? If yes, which pin would that be? Some explanation would go a huge way.

Pinout : http://blog.protoneer.co.nz/arduino-pinout/ (scroll down)

Thank you, looks like a absolutely fantastic library that I will be using in my product if I can get it working.

play song one after another in a loop

hi master

i have tried to put wav.play("music1.wav"); and wav.play("music2.wav"); in the setup()
it worked
but when I placed these files into the loop
it cannot play both files it only played one

is there a way to play my music one after another without pressing any button?

Thanks a lot.

Current consumption

I'm working on a project that requires powering with some batteries. On initial power up, I'm using about 150mA of power. When I have your library play a file, it's consuming about 350mA. When it finishes playing, it will stay at 350, and sometimes increase to 450mA. If I wait for .isPlaying() to return 0 and execute disable(), the current consumption returns to 150mA. The timer is eating a lot of juice it appears.

What is the purpose of the timer and why does it continue to run when playback has ceased? Thank you and awesome library!

Support for 8Mhz boards?

Hey @TMRh20 , how can this library be modified to allow for Arduinos running at 8Mhz?

I've looked into your code, but it's a bit confusing to follow the many variable names. I'm a FW guy and would be happy to help make this addition if you can point me in the right direction.

Thanks for contributing this great library.
Any help is much appreciated. @simsalapim is interested in this as well.

-Ray

16-bit Mono on Arduino UNO

First of all, many thanks for the great TMRpcm library. It works on 8-bit very well on Arduino UNO!

I also tried the 16-bit advanced sample from git to play 16bit Mono (using a 1:256 resistor ladder) but unfortunately, on the MSB output pin the sound is heavily "clipped" - it sound like overamplified (on the LSB pin output I get "noise" as supposed). I tried different sampling rates (12~32kHz), but no success. Any idea?

setretries problem

Hi,
I see that when I set "setRetries(x,15)" when x is a multiple of 16 I receive a sent error.
On the receiver I can see that the packet is arrived.
The same issue can be found in the ManiacBug version, but there the receiver receives a lot of
packets (15) with the same value.

Bye Andrea

Polyphonic sound

Hi!

First of all, thanks for the library, this is amazing! perfect for what I'm doing. second of all, is the library capable of doing more than one sound at a time through the same pin? if not, can you just initiate multiple instances of the class and assign them to different pmw pins?

Thanks!

ESP8266 port

I really would like to use your awesome nice library on a esp8266.
kirchnet@ the esp8266 community wrote a "good" working code to play a wav file:
http://www.esp8266.com/viewtopic.php?p=44557
(Sound a lot of more awfull than your great library on a ATmega(Compared to his code yours sounds like HiFi))

The code still has some problems, but anyway,
is a esp8266 port planned ?

Sorry for my english.
Thanks in advance,
gamecompiler.

Continuous popping noise when Arduino powered via VIN

When I supply power (12V or 5V) to the Arduino (an Adafruit Metro Mini) via VIN, a continuous popping sound occurs when audio is supposed to be playing, and the light on the SD card reader and the pin 13 light on the Arduino flashes along with the pop. When power is supplied over USB, audio playback works fine.

Here's a short video of the pop: https://www.youtube.com/watch?v=3xnE4kFzT7E

Any idea why this might be the case? Maybe it's a fault of my amp and not this library?

need library returning values on call/serial print

so i just wanted to say that

tmrpcm.volume();

tmrpcm.quality();

tmrpcm.loop();

etc etc for all the commands need to give a value for example

tmrpcm.volume(); or tmrpcm.setvolume(); need to give a value so that a user can is if statements on them...

like if set volume can only be at 7 max... and volume is the control for up and down... it should let you know if the volume is at level 0 or at like 5 or level 7 so that a user can make a function that wont exceed the max or min value...

currently if you use volume(1); // controls volume up... it will keep going up till its muted it self and even if you do volume(0); it will still

same for quality and loop and all the other lib, itshould give a value of where its at so that if statements can be used with them..

ID3 Tags

Hey TMRh20,
I've written an ID3 Tag Reader for Arduino for PCM Wave Files.
Are you interested in including this function in your Project?

http://pastebin.com/cfPcSxn7

It would be great ;)

Request: play wav in loop mode (continously)

Hi,
is it possible to play a wav file in loop without break ? I want to use your library for a sound module for my rc boat ! So i need a possibility to play the motor sound continously.

Thanks for reply
Marco

Example Not Working for Mega 2560

I have tried multiple times to get the example code "music" to work, with no luck. I am using an Arduino Mega 2560 SainSmart clone, and a Seeed V4.1 SD Shield. I have tried multiple coding and wiring configurations.

I HAVE been able to get the CardInfo example to work. So I know(or at least am almost certain) the neither board is damaged in any way. I even went so far as to try a Catalex Micro SD board(the one I do suspect to be ruined- none of wiring configurations I tried worked with CardInfo)

It is my goal, to eventually get my project to both move and produce sound, and am trying to tackle each task individually and then combine them.

Help would be MUCH APPRECIATED!!!!

Loud "pop" at the beginning and end of recording

First of all, cheers to all of the contribs for making an awesome library for the Arduino ! This is really cool.

Now, I would like to push my UNO a little bit by using it to record an audio source through an analog input. When recording at 22050 Hz, it sounds good enough BUT there's a loud noise at the beginning and end of file.

There's a sample attached to this post.

Did this occur to you, and do you know how I could fix this ? Thank you !
Patrick
SAMPLE.WAV.zip

demo music request in wiki

Hi, it would be great advertising for the library if you posted a section in your wiki with links to demo music coming from an Arduino running your code. Ex: post a youtube video (better), or even an mp3 download (ok), of various songs (with vocals) playing, being produced by an Arduino. I'd like to know how well this library can reproduce regular mp3 tracks with vocals, without having to build the circuit and load the code (though I will eventually get around to this).

Thanks!
Looks like a great lib.

TMRpcm breaks RF24Network

When i initialize RF24Network with:
RF24Network network(radio);

The RF24Network library breaks the TMRpcm library and no sounds play.
But:

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

  }
  else{   
    Serial.println("SD ok");   
  }

Says SD ok.
How can i fix that ? I really would like to use the network library.

Here is my complete code:

/*
* Giving Credit where Credit Is Due
*
* Portions of this code were derived from code posted in the Arduino forums by Paul Malmsten.
* You can find the original thread here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434
*
* The Audio portion of the code was derived from the Melody tutorial on the Arduino wiki
* You can find the original tutorial here: http://arduino.cc/en/Tutorial/Melody
* 
* The Lasertag portion is taken from the great IBM Lasertag tutorial:
* You can find the original tutorial here:
* http://www.ibm.com/developerworks/opensource/tutorials/os-arduino1/
* 
*/
#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 5  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>


//Sound stuff
TMRpcm tmrpcm;   // create an object for use in this sketch
unsigned long time = 0;

//RF24 Stuff
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>


RF24 radio(7,8);                // nRF24L01(+) radio attached using Getting Started board 

RF24Network network(radio);      // Network uses that radio
//TMRpcm fails if i USE this line, if not, everything is working correctly
const uint16_t this_node = 00;    // Address of our node in Octal format ( 04,031, etc)
const uint16_t other_node = 01;   // Address of the other node in Octal format

struct payload_t {                 // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};
//-------------------------------------------------------
//
//

int sensorPin  = 2;      // Sensor pin 1
int senderPin  = 3;      // Infrared LED on Pin 3
int triggerPin = 4;      // Pushbutton Trigger on Pin 4
int speakerPin = 10;     // Positive Lead on the Piezo
int blinkPin   = 13;     // Positive Leg of the LED we will use to indicate signal is received

int startBit   = 2000;   // This pulse sets the threshold for a transmission start bit
int endBit     = 3000;   // This pulse sets the threshold for a transmission end bit
int one        = 1000;   // This pulse sets the threshold for a transmission that represents a 1
int zero       = 400;    // This pulse sets the threshold for a transmission that represents a 0
int trigger;             // This is used to hold the value of the trigger read;
boolean fired  = false;  // Boolean used to remember if the trigger has already been read.
int ret[2];              // Used to hold results from IR sensing.
int waitTime = 300;     // The amount of time to wait between pulses

int playerLine = 14;     // Any player ID >= this value is a referee, < this value is a player;
int myCode     = 1;      // This is your unique player code;
int myLevel    = 1;      // This is your starting level;
int maxShots   = 6;      // You can fire 6 safe shots;
int maxHits    = 6;      // After 6 hits you are dead;
int myShots    = 0;      // You can fire 6 safe shots;
int myHits     = 0;      // After 6 hits you are dead;

int maxLevel   = 9;      // You cannot be promoted past level 9;
int minLevel   = 0;      // You cannot be demoted past level 0

int refPromote = 0;      // The refCode for promotion;
int refDemote  = 1;      // The refCode for demotion;
int refReset   = 2;      // The refCode for ammo reset;
int refRevive  = 3;      // The refCode for revival;

int replySucc  = 14;     // the player code for Success;
int replyFail  = 15;     // the player code for Failed;

void setup() {
  pinMode(blinkPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(senderPin, OUTPUT);
  pinMode(triggerPin, INPUT);
  pinMode(sensorPin, INPUT);
  randomSeed(analogRead(0));
  for (int i = 1;i < 4;i++) {
    digitalWrite(blinkPin, HIGH);
    playTone(900*i, 200);
    digitalWrite(blinkPin, LOW);
    delay(200);
  }
  //Prepare SPI

  Serial.begin(9600);
  Serial.println("Ready: ");
  tmrpcm.speakerPin = 9;

  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

  }
  else{   
    Serial.println("SD ok");   
  }

  //________________________________
  //      INIT RADIO
  //________________________________
  //radio.begin();
  //network.begin(/*channel*/ 90, /*node address*/ this_node);

  //________________________________
  //    PLAY STARTUP SOUND
  //________________________________
  tmrpcm.play("powerup.wav");
}

void loop() {

  senseFire();
  senseIR();

  if (ret[0] != -1) {
    playTone(1000, 50);
    Serial.print("Who: ");
    Serial.print(ret[0]);
    Serial.print(" What: ");
    Serial.println(ret[1]);
    if (ret[0] >= playerLine) {
      if (ret[1] == refPromote) {
        // Promote
        if (myLevel < maxLevel) {
          Serial.println("PROMOTED!");
          myLevel++;
          playTone(900, 50);
          playTone(1800, 50);
          playTone(2700, 50);
        }
      } else if (ret[1] == refDemote) {
        // demote
        if (myLevel > minLevel) {
          Serial.println("DEMOTED!");
          myLevel--;
        }
          playTone(2700, 50);
          playTone(1800, 50);
          playTone(900, 50);
      } else if (ret[1] == refReset) {
        Serial.println("AMMO RESET!");
        myShots = maxShots;
        playTone(900, 50);
        playTone(450, 50);
        playTone(900, 50);
        playTone(450, 50);
        playTone(900, 50);
        playTone(450, 50);
      } else if (ret[1] == refRevive) {
        Serial.println("REVIVED!");
        myShots = 0;
        myHits = 0;
        myLevel = 1;
        playTone(900, 50);
        playTone(1800, 50);
        playTone(900, 50);
        playTone(1800, 50);
        playTone(900, 50);
        playTone(800, 50);
      }
    } else {
      if (ret[1] == replySucc) {
        playTone(9000, 50);
        playTone(450, 50);
        playTone(9000, 50);
        Serial.println("SUCCESS!");        
      } else if (ret[1] == replyFail) {
        playTone(450, 50);
        playTone(9000, 50);
        playTone(450, 50);
        Serial.println("FAILED!");        
      }
      if (ret[1] <= maxLevel && ret[1] >= myLevel && myHits <= maxHits) {
        Serial.println("HIT!");
        myHits++;
        playTone(9000, 50);
        playTone(900, 50);
        playTone(9000, 50);
        playTone(900, 50);
      }
    }
  }
}

void senseIR() {
  int who[4];
  int what[4];
  int end;
  if (pulseIn(sensorPin, LOW, 50) < startBit) {
    digitalWrite(blinkPin, LOW);
    ret[0] = -1;
    return;
  }
  digitalWrite(blinkPin, HIGH);
  who[0]   = pulseIn(sensorPin, LOW);
  who[1]   = pulseIn(sensorPin, LOW);
  who[2]   = pulseIn(sensorPin, LOW);
  who[3]   = pulseIn(sensorPin, LOW);
  what[0]  = pulseIn(sensorPin, LOW);
  what[1]  = pulseIn(sensorPin, LOW);
  what[2]  = pulseIn(sensorPin, LOW);
  what[3]  = pulseIn(sensorPin, LOW);
  end      = pulseIn(sensorPin, LOW);
  if (end <= endBit) {
    Serial.print(end);
    Serial.println(" : bad end bit");
    ret[0] = -1;
    return;
  }
  Serial.println("---who---");
  for(int i=0;i<=3;i++) {
    Serial.println(who[i]);
    if(who[i] > one) {
      who[i] = 1;
    } else if (who[i] > zero) {
      who[i] = 0;
    } else {
      // Since the data is neither zero or one, we have an error
      Serial.println("unknown player");
      ret[0] = -1;
      return;
    }
  }
  ret[0]=convert(who);
  Serial.println(ret[0]);

  Serial.println("---what---");
  for(int i=0;i<=3;i++) {
    Serial.println(what[i]);
    if(what[i] > one) {
      what[i] = 1;
    } else if (what[i] > zero) {
      what[i] = 0;
    } else {
      // Since the data is neither zero or one, we have an error
      Serial.println("unknown action");
      ret[0] = -1;
      return;
    }
  }
  ret[1]=convert(what);
  Serial.println(ret[1]);
  return;
}

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

int convert(int bits[]) {
  int result = 0;
  int seed   = 1;
  for(int i=3;i>=0;i--) {
    if(bits[i] == 1) {
      result += seed;
    }
    seed = seed * 2;
  }
  return result;
}

void senseFire() {
  trigger = digitalRead(triggerPin);
  if (trigger == LOW && fired == false) {
    Serial.println("Button Pressed");
    fired = true;
    myShots++;
    if (myHits <= maxHits && myShots > maxShots && random(1,20) <= myShots) {
      Serial.println("SELF DESTRUCT");
      tmrpcm.play("disarm.wav");
      selfDestruct();
    } else if (myHits <= maxHits) {
      Serial.print("Firing Shot : ");
      tmrpcm.play("milshot.wav");
      Serial.println(myShots);
      fireShot(myCode, myLevel);
    }
  } else if (trigger == HIGH) {
    if (fired == true) {
      Serial.println("Button Released");
    }
    // reset the fired variable
    fired = false;
  }
}

void fireShot(int player, int level) {
  int encoded[8];
  digitalWrite(blinkPin, HIGH);
  for (int i=0; i<4; i++) {
    encoded[i] = player>>i & B1;   //encode data as '1' or '0'
  }
  for (int i=4; i<8; i++) {
    encoded[i] = level>>i & B1;
  }
  // send startbit
  oscillationWrite(senderPin, startBit);
  // send separation bit
  digitalWrite(senderPin, HIGH);
  delayMicroseconds(waitTime);
  // send the whole string of data
  for (int i=7; i>=0; i--) {
    if (encoded[i] == 0) {
      oscillationWrite(senderPin, zero);
    } else {
      oscillationWrite(senderPin, one);
    }
    // send separation bit
    digitalWrite(senderPin, HIGH);
    delayMicroseconds(waitTime);
  }
  oscillationWrite(senderPin, endBit);
  playTone(100, 5);
  digitalWrite(blinkPin, LOW);
}

void oscillationWrite(int pin, int time) {
  for(int i = 0; i <= time/26; i++) {
    digitalWrite(pin, HIGH);
    delayMicroseconds(13);
    digitalWrite(pin, LOW);
    delayMicroseconds(13);
  }
}

void selfDestruct() {
  myHits  = maxHits+1;
  playTone(1000, 250);
  playTone(750, 250);
  playTone(500, 250);
  playTone(250, 250);
}

Conflict with Servo Library

I'm not sure how to get ahold of you, so I hope this is OK. I am using your audio player, and it works great. But I'd like to also use the servo library associated with another timer. I think the audio library is conflicting with the servo library. I am using an Arduino Uno. Both libraries work fine when run in separate programs. Pin assignments:

define servo1_pin 3 // Output (Uno Timer2 PWM pin)

define speaker_output 9 // Output (Uno Timer1 PWM pin)

Any idea why these might be conflicting? I have tried all of the other PWM pins for the servo, and it's dead on all of them, except it jitters on pin 10 (Uno Timer1) which is associated with the audio output pin Timer1.
This is for a Valentine's Day project I'm helping my son with, due Friday as you might guess.
Thanks in advance for you assistance. You can see the project code here:
https://github.com/ageppert/Valentine_Robot

-Andy

Playing From Onboard Flash

Has there been any discussion about the ability to play a file that is saved in the onboard flash memory instead of an SD card? I have a project that I am working on where I want to play a background sound. The WAV file is less than 2K and the sketch to play using the SD card plus the other things I am having it do is about 16K so there is space for it all. I would like to be able to put this all together without having to put a SD card on.

Help

I

For my final project i'm thinking about making a small sequencer out of squares with arduino but i'm not sure how to start. I just started out with arduino and i'm still learning.

Is it possible do determine and modify the samples bpm (resample them to fit the bpm) and loop a sample while that sample's switch is pressed?

Unable to loop on every 2nd paired pins

I'm looking for a seamless looping functionality of this lib and tried on the 2 examples of multi-track playback. I noticed that you can only loop every 1st set of pins and cannot on the other pairs.

Furthermore, I wish there's a seamless playback and advanced looping functionality wherein we can possibly jump on a certain part of the clip and loop there for a predefined duration and jump to another without a single moment of silence between every calls.

More power and thanks in advance.

Support For ATmega32U4

Hello!

Looking at the Wiki it seems the library doesn't currently support ATmega32U4 devices such as the Arduino Micro, correct? If not, do you plan to support it?

Thanks!

Timer2 Uno high tone/beep

Hello,

First off, thank your for the great working library! It works really great with the 16 bit timer1. I'm trying to make it work with the 8 bit timer2 but I cant get it right. I've uncommented the line mentioned at your wiki page in .h file, but i get an really annoying high beep. I'm not using a .wav file with the uncommon frequency like 15.7khz but a file converted with iTunes that works fine with the 16bit timer1. Do you have an idea how to solve this problem? Or is the problem the file that I'm using?

Thank you!
Ronald

ENABLE_MULTI needs play+stop.

Hi, I'm trying to play two wav files at the same time (background + button-beep) on an Arduino Micro.

Everything works fine on pins 9+10 with or without MODE2, but as soon as I uncomment ENABLE_MULTI it fails. I've narrowed it down to needing to call audio.play("x.wav"); audio.stopPlayback(); first, otherwise it won't play anything.

ENABLE_MULTI doesn't work with nano

Hi, Using a nano v3 328 for slave audio playback in a project of mine with this great library.

However, have an issue. Audio can be played ok on a single channel (pin D9), but when you enable the ENABLE-MULTI option nothing is played on either channel. (pin D9 or pin D10). D10 is correctly set as an output and the SD card cs line is set to pin 4 as per instructions.

What else can i do to resolve this, or is it a bug?

file sounds muddy through piezo

Howdy. I've been trying to play sounds with a circuit quite a bit like http://www.instructables.com/id/Playing-Wave-file-using-arduino/?ALLSTEPS , and any file I generate sounds like it's slowed or buzzing. The files provided in the instructable work reasonably well (though all I have to work with are tiny piezo speakers), but the files I create always sound like falling gravel. I'm creating these things with Audacity, a mono file with an appropriate bitrate, and saving as directed (other uncompressed - microsoft(wav), 8-bit unsigned). I'm running off of a knock-off Sparkfun Pro Micro (essentially a leonardo), and using code very much like the one in the instructable, but playing automatically after a time delay rather than waiting for buttons. I really do think my issue is with my audio files - any advice? Or otherwise, could someone test these files and see if the problem is in my hardware? Thanks!

Some of my files are
https://www.dropbox.com/s/irf9ub7r5wotm6f/wave1.wav?dl=0 , https://www.dropbox.com/s/17im2rxtnlriumv/snare2.wav?dl=0 ,
https://www.dropbox.com/s/kq1ztpvoqvq4f0o/snare1.wav?dl=0
and one of the working files:
https://www.dropbox.com/s/ns03wnytwiexgf8/1.wav?dl=0

Explanation of 'complimentary mode'

Hullo :)

Can you explain what the 'complimentary mode' is for? I see it referenced in the Advanced Usage page and on the wiki but can't see its actual purpose.

Cheers,
Gavin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.