Go Down

Topic: Playing .wav sound through Arduino Uno (Read 10120 times) previous topic - next topic

dmc0162

Jun 21, 2012, 04:48 am Last Edit: Jun 21, 2012, 05:02 am by dmc0162 Reason: 1
For one of the functions of my project, I was wondering if it is possible for my Arduino Uno to play a very simple and very short .wav through a small speaker.  I found this website which provides a program to encode the .wav at a very low bit rate to conserve memory:

http://www.romanblack.com/picsound.htm


I have put my file into this program, and I have the option to export a few different ways, and I was wondering which will be the proper file for use in my Arduino code:

These are my options:
Export binary file .BTC format
Export PIC assembler file .ASM
Export PIC MkroC file .C

I would assume since we program the arduino basically in C language that I would use the last one.  


When I convert the file into a .C file, I get code that looks something like this:


//=====================================================
// AUTO CREATED FILE made by Windows BTc Sound Encoder
// v2.0    Copyright 2002-2008 - Roman Black
//
// Hippyware.  
// www.RomanBlack.com
//=====================================================

// File Details:
// Size 142336 bits     (17792 bytes)
// Sound encoded at 44100 bits/sec
// using BTc16 1bit Algorithm to be decoded on
// the following circuit:
//
//
//             R = 1596 ohms  
//  
// Digital -----------R-----*----- Analogue  
//                          |      out  
//                          |    
//                          |    
//                          C = 0.22 uF    
//                          |    
//                          |    
//                          |    
//                         Gnd    
//
//
//=====================================================
// Bitstream data is MikroC .C table format,
// in 'functions' of 2048 bytes with a .C 'return' as
// the last of every 256 byte block. At the end of every
// 2048 bytes the C compiler inserts its own return.
//
// Bits are played from left to right, from ms_bit to
// ls_bit.
//=====================================================
//--------------------------------------------------
void sound_data1()    org (1 * 256)
{
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;
  asm retlw 0xAA ;

....... and so on.


My question is, what programming function would I actually use in my code to send this sound signal to one of the pins. Thanks

TMRh20

The info at http://arduino.cc/playground/Code/PCMAudio is a good starting point for trying to play sound clips, and would probably work with that type of file given the correct modifications.

The above reference uses timers built into the ATMega chips to create a PWM signal. To learn how to do this you pretty much have to read the datasheet for the chips, since it writes directly to the registers of the chip instead of using the basic digitalWrite() type functions.

This is pretty much the only way I have found to make the Arduino play back sound files with reasonable quality.

Nick Gammon

Quote
// Size 142336 bits     (17792 bytes)


The Arduino Uno has 2048 bytes of memory, so there is no way that will fit. Playing tunes with PWM is within its capabilities.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Harishkalla

Hi,
Is it possible the Audio library enables an Arduino Uno or Arduino YUN board to play back .wav files from a storage device like an SD card.

I dont have Arduino Due.

jurs

#4
Sep 29, 2015, 01:51 pm Last Edit: Sep 29, 2015, 01:53 pm by jurs
The Arduino Uno has 2048 bytes of memory, so there is no way that will fit. Playing tunes with PWM is within its capabilities.
Arduino UNO max. flash size for a sketch is 32,256 bytes, and playing 8-bit PCM sound samples at a bit rate of 8000 samples per second is possible to something like three and a half seconds from flash (const PROGMEM).

If more than 3.5s of PCM-sound is needed, a MEGA2560 can be used. Or a SD card to play sound from SD. But in any case, 8-bit/8kHz is a relatively poor sound quality, but it's enough to understand speech and create signal tones different than the simple square wave tones generated with the tone() function.

In this thread I posted a code that plays two small sound samples from ROGMEM of an Arduino UNO:
http://forum.arduino.cc/index.php?topic=318002.msg2201769#msg2201769

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy