SimpleSDAudio: Unterschied zwischen den Versionen
Tut (Diskussion | Beiträge) |
Tut (Diskussion | Beiträge) K (→Features) |
||
Zeile 10: | Zeile 10: | ||
* Integrated SD library (minimal FAT only, optimized for low RAM usage and high performance) | * Integrated SD library (minimal FAT only, optimized for low RAM usage and high performance) | ||
* Works with most SD card shields that are hooked to SPI port | * Works with most SD card shields that are hooked to SPI port | ||
− | * Easy to use: 1. init library, 2. select audio file, 3. call play, 4. call worker while audio is playing | + | * Easy to use API: 1. init library, 2. select audio file, 3. call play, 4. call worker while audio is playing |
* Supports SD and SDHC cards formated with FAT16 or FAT32 | * Supports SD and SDHC cards formated with FAT16 or FAT32 | ||
Version vom 29. Juni 2012, 19:00 Uhr
Play audio files with your Arduino in decent quality from SD card, only very few additional hardware required.
Inhaltsverzeichnis
Features
- 8-Bit PWM output - no external DAC required
- 62.500 kHz (fullrate) / 31.250 kHz (halfrate) sampling rate @ 16 MHz
- 31.250 kHz (fullrate) / 15.625 kHz (halfrate) sampling rate @ 8 Mhz
- Mono, bridge and stereo mode
- RAM usage ~1.3 kByte
- ROM usage ~6.1 kByte
- Integrated SD library (minimal FAT only, optimized for low RAM usage and high performance)
- Works with most SD card shields that are hooked to SPI port
- Easy to use API: 1. init library, 2. select audio file, 3. call play, 4. call worker while audio is playing
- Supports SD and SDHC cards formated with FAT16 or FAT32
Restrictions
- Audio file must be converted prior use
- Audio files must reside in root directory of card
- File name of audio file must be in 8.3-format
- Audio file must reside completely non-fragmented on card
- Fullrate and stereo actually leads to buffer underruns
- Minimum controller required: ATmega168. ATmega8 is too low on RAM.
Quickstart guide
- Install library: Unzip all to your /libraries/ folder.
- Copy the file /libraries/SimpleSDAudio/examples/example.raw to root folder of a freshly formated SD card (don't use quick format!).
- Connect SD card to your Arduino board (using shield or whatever, SD card's chip select should go to pin 4, all other to SPI pins).
- Connect a speaker or headphone via 100 ohm resistor in series to audio output pin (pin 9 on Arduinos with ATmega168/328, pin 44 on Arduinos with ATmega1280/2560). Connect other end of speaker to GND.
- Launch Arduino IDE and try example "BareMinimumWithDebug" first.
- You should hear the audio (plays just a few seconds). Activate serial monitor to find some information if it does not work. Maybe you have to adjust SD cards CS pin in sketch.
Software installation guide
Browse to your sketchbook location (see Arduino - File - Preferences). There should be a folder called /libraries/, if not, create a folder and name it exactly like that. Then extract the zip-file preserving the folders and put all into the "libraries" folder that you end up with a structure where the "example" folder is located here: /libraries/SimpleSDAudio/examples/. Now you can start Arduino IDE and find examples for the library under File - Examples - SimpleSDAudio.
To convert audio files for usage with this library read the next paragraph.
Preparation of SD card and conversion of audio files
The audio library uses a very trimmed SD library that uses the FAT only to find the start sector of the files. Therefore the file must be completely non-fragmented on the SD card. The best way to ensure this is to do a fresh and full format of the card (don't use quick format!). After formating the SD card, only copy new files on it. Don't delete files and avoid rename operations that creates file names that doesn't fit into 8.3 format (see http://en.wikipedia.org/wiki/8.3_filename ). All files must placed in root directory as folders are not supported by the audio library.
To convert audio files I suggest the use of SoX from http://sox.sourceforge.net .
Windows users
Windows users should download from there the ZIP distribution and unzip it to the libraries/SimpleSDAudio/tools folder. Afterwards they can drag and drop .wav files to the appropriate batch files to start the conversion. The converted files will end up in folder "converted".
Linux users
Linux users should compile SoX from source or use their favorite package manager to install SoX. Afterwards they should use the following line for conversions:
sox inputfile.wav --norm=-1 -e unsigned-integer -b 8 -r 31250 -c 1 -t raw outputfile.raw
Change the following according to your needs:
- For stereo change -c 1 to -c 2
- For full rate use -r 62500 @ 16MHz, -r 31250 @ 8 MHz
- For half rate use -r 31250 @ 16MHz, -r 15625 @ 8 MHz
The option --norm=-1 is used to avoid bad sounding clipping effects.
Hardware setup
The SD card should be connected to the SPI port of the controller. The chip select pin from the card can be connected to any free digital pin, but if pin 4 is used on Arduinos you don't have to adjust the source code. Many shields with SD card support like Ethernet-Shield will work.
According your mode configuration, one or two pins are used for audio output. This pins can not be changed and are different between different Arduino boards. For ATmega168/328 based plattforms those are pins 9 and 10. For ATmega1280/2560 those are pins 44 and 45. For other plattforms look into the file SimpleSDAudio.h.
Be careful that the audio output pins are digital ports that carry a positive voltage between 0V and 5V. It is not a good idea to have a DC voltage at line-inputs or smaller speakers as there will be a steady current flow. Therefore at least a resistor and/or a capacitor should be connected in series. For a start use at least 100 ohm or a capacitor between 100nF and 100uF. For line inputs use a voltage divider or poti to reduce the voltage.