首頁 > 評(píng)測(cè) > 8位機(jī)也玩音頻-Arduino+SD+DAC+運(yùn)放打造的播放器

8位機(jī)也玩音頻-Arduino+SD+DAC+運(yùn)放打造的播放器

8位機(jī)   Arduino   SD   DAC   
  • 作者:zhanzr
  • 來源:21ic
  • [導(dǎo)讀]
  • 比如本文要介紹的Adafruit Wave Shield,就能是專門為Arduino設(shè)計(jì)的音頻模塊.確切的說是為AVR這一類的8位機(jī)而設(shè)計(jì)的音頻模塊.下文將從硬件到軟件詳細(xì)介紹一下子此模塊的設(shè)計(jì)細(xì)節(jié)與使用方法.

FatReader root; // This holds the information for the volumes root directory

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names (for prettyprinting)

dir_t dirBuf; // buffer for directory reads

/*

* Define macro to put error messages in flash memory

*/

#define error(msg) error_P(PSTR(msg))

// Function definitions (we define them here, but the code is below)

void play(FatReader &dir);

//Arduino程序的初始化函數(shù),主要是加載文件系統(tǒng)

void setup() {

Serial.begin(9600); // set up Serial library at 9600 bps for debugging

putstring_nl("\nWave test!"); // say we woke up!

putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad

Serial.println(FreeRam());

// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you

if (!card.init()) { //play with 8 MHz spi (default faster!)

error("Card init. failed!"); // Something went wrong, lets print out why

}

// enable optimize read - some cards may timeout. Disable if you're having problems

card.partialBlockRead(true);

// Now we will look for a FAT partition!

uint8_t part;

for (part = 0; part < 5; part++) { // we have up to 5 slots to look in

if (vol.init(card, part))

break; // we found one, lets bail

}

if (part == 5) { // if we ended up not finding one :(

error("No valid FAT partition!"); // Something went wrong, lets print out why

}

// Lets tell the user about what we found

putstring("Using partition ");

Serial.print(part, DEC);

putstring(", type is FAT");

Serial.println(vol.fatType(), DEC); // FAT16 or FAT32?

// Try to open the root directory

if (!root.openRoot(vol)) {

error("Can't open root dir!"); // Something went wrong,

}

// Whew! We got past the tough parts.

putstring_nl("Files found (* = fragmented):");

// Print out all of the files in all the directories.

root.ls(LS_R | LS_FLAG_FRAGMENTED);

}

//主循環(huán)就是播放,播放是通過中斷來進(jìn)行的,所以也可以同時(shí)做其他操作

void loop() {

root.rewind();

play(root);

}

//一些出錯(cuò)報(bào)告函數(shù)

/*

* print error message and halt

*/

void error_P(const char *str) {

PgmPrint("Error: ");

SerialPrint_P(str);

sdErrorCheck();

while(1);

}

/*

* print error message and halt if SD I/O error, great for debugging!

*/

void sdErrorCheck(void) {

if (!card.errorCode()) return;

PgmPrint("\r\nSD I/O error: ");

Serial.print(card.errorCode(), HEX);

  • 本文系21ic原創(chuàng),未經(jīng)許可禁止轉(zhuǎn)載!

網(wǎng)友評(píng)論

  • 聯(lián)系人:巧克力娃娃
  • 郵箱:board@21ic.com
  • 我要投稿
  • 歡迎入駐,開放投稿

熱門標(biāo)簽
項(xiàng)目外包 more+