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:
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
The info at Arduino Playground - 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.
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.
TMRh20:
The info at Arduino Playground - HomePage 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.
I too visited this page but I after generating my files, do not know how to interface them with the arduino, please help
SANTHOSH_P:
I too visited this page but I after generating my files, do not know how to interface them with the arduino, please help
Best to start your own thread, rather than dig up this one that is over 7 years old. A lot has changed in that time, new hardware that is more capable, ect.
Start a new thread, post the code you tried, post a picture of your circuit, and ask specific questions.