Änderungen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche

SimpleSDAudio

2.861 Byte hinzugefügt, 17:35, 7. Apr. 2015
/* It does not compile */
<div style="clear: both; border-width:0px; border-color:#333300; border-style:solid; padding:5px; background-color:#FFEFEF; margin:1em; margin-left:5em; margin-right:5em;">
Please note: If you got here by clicking a link from internet parasites like "gotlinks" that force you to install software that takes over you computer or force you to do other things that you don't want to just to get the correct link to this free site, please be aware that we are NOT responsible for that! Feel free to correct such links if you have access to those sites. </div>
 
[[Datei:SSDA Minimal.jpg|320px|right|thumb|Minimal setup for SimpleSDAudio (here without level-shifters - only for Arduino running at 3.3V)]]
[[Datei:SSDA Arduino Ethernet.jpg|320px|right|thumb|Minimal setup for SimpleSDAudio with Arduino Ethernet - loudspeaker connected via 100uF capacitor to audio output]]
* 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
* Combination of fullrate and quadro-output actually leads to buffer underruns
* Minimum controller required: ATmega368. ATmega168 is too low on RAM.
 
=== Alternatives ===
Now there is an alternative library called '''TMRpcm''' that does something similar: https://github.com/TMRh20/TMRpcm/wiki . This is a little bit easier to use (no conversion of WAV file needed). Here a table with the differences:
{| class="wikitable"
!Feature!!SimpleSDAudio!!TMRpcm
|-
|Highest sampling rate||X||-
|-
|Native WAV playback (no file conversion needed)||-||X
|-
|Highly speed-optimized code (using Assembler for audio core)||X||-
|-
|Using size-optimized minimal SD-FAT library||X||-
|-
|Universal SD library in the background supporting fragmented files and many other uses||-||X
|-
|Stereo operation possible||X||X
|-
|Quad speaker operation possible||X||X
|-
|Volume setting support||-||X
|}
So depending on your needs, try the library that best fit your needs. TMRpcm might be easier for beginners. Both libraries should work with the same connections. You can take the information about the connections from here and use the TMRpcm library with that.
 
You want even more, multi-channel audio playback, digital filters, mixers, DSP functions? Then take a look at the [http://www.pjrc.com/teensy/td_libs_Audio.html Teensy 3.1 Audio Library] using a serious (but still affordable) micro controller but still using the Arduino IDE.
= Download =
=== Windows users ===
For Windows users should download from there the ZIP distribution and unzip it to Sox binaries are already part of the library located in the libraries/SimpleSDAudio/tools folder. Afterwards they can Just 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 ===
<gallery widths=300px heights=150px perrow=2>
Datei:SD_Card_Connection.png|SD card connection with level shifting to standard Arduinos
Datei:SSDA SimpleConnections.png|Examples for simple 8-bit audio outputs
Datei:SSDA Simple16bit.png|Rising the audio resolution to something near 16-bit
Datei:SSDA Better16bit.png|Still unexpensive solution to get nice 16-bit audio output
</gallery>
 
The 16-bit output is done by operating two 8-bit outputs together: One will provide an 8-bit signal containing the higher 8-bits and the other one contains the lower 8-bits. If you listen to each of those channels separately, you will hear the usual audio on the upper 8-bit outputs but with noticable 8-bit noise especially on quiet audio parts. On the lower 8-bit you will hear just noise. But when you add this noise (reduced in volume by a factor of 256th done by the resistors) to the higher 8-bits then something magic will happen: The 8-bit noise will vanish (but unfortunately often a lot of noise originating from power supply might still be left).
=== Audio amplifier for loudspeakers ===
Follow those pictures to build a very cheap SD-card adapter.
[[<gallery widths=600px heights=300px perrow=1>Datei:BuildSDBreadboardHolder_Step1.jpg|frame|left|You need one single-row and one double-row pinheader cut to 7 pins each.]]</gallery> <gallery widths=300px heights=300px perrow=23>
Datei:BuildSDBreadboardHolder_Step2.jpg|Using pliers to bend one side of pins < shape. Don't bend other side.
Datei:BuildSDBreadboardHolder_Step3.jpg|Bend all 7 pins of one row, leave other row non bend. You should end up like this:
==== init() ====
<pre>boolean init(uint8_t soundMode);</pre>
Call this to initialze initialize the library and set sound mode. Thisfunction will also aquire acquire the needed buffer (if not
already set manually using setWorkBuffer), initialize SD card
and sets up all used pins.
Output channel configuration flags
* SSDA_MODE_MONO - Use only 1st PWM pin
* SSDA_MODE_STEREO - Use both PWM pins for stereo outputor mono 16 bit* SSDA_MODE_QUADRO - Uses four PWM pins for either 4 speakers or stereo 16 Bit* SSDA_MODE_MONO_BRIDGE - Use both PWM pins for more power(mono output only)
Auto worker call flag
* SSDA_MODE_AUTOWORKER - Add this flag and you don't need to call worker for playback
The function return true if successfullsuccessful, false if an erroroccuredoccurred. You can use getLastError() to retrieve the error code.
Typical reasons for errors are wrong SD card connection or
too low RAM (1k heap required) for internal buffer available.
providing the filename in 8.3 format.
The function return true if successfullsuccessful, false if an error
occured. You can use getLastError() to retrieve the error code.
Typical reasons for errors are that the file was not found.
== It does not compile ==
* Are you using the latest version of Arduino IDE?
** SimpleSDAudio_V1.00 need at least V1.0.1 of Arduino IDE. It has been tested and works ok also under V1.6.1.
** SimpleSDAudio_V1.01 need at least V1.0 of Arduino IDE (remove complete block with !Serial from examples when using with Arduino IDE V1.0).
* Have you selected the correct CS pin for your SD-card? Uncomment the line <pre>// SdPlay.setSDCSPin(10);</pre> in the examples and enter correct pin number here.
* Your SD shield may be crap and SD communication is only possible with limited speed. Try commenting the line <pre>SPSR |= (1 << SPI2X);</pre> in function ''SD_L0_SpiSetHighSpeed()''. If this doesn't help, comment out also the first line and try again. If then init works you have a bad SD card shield.
 
== How to use 16-Bit audio? ==
If you want to use 16-Bit audio, you need 2 PWM outputs joined together with a resistor (see above). Select SSDA_MODE_STEREO if you want one 16-Bit output channel, select SSDA_MODE_QUAD if you want two 16-Bit output channels (works only on Mega-Arduinos or with Timer2 patch).
1.954
Bearbeitungen