{"id":827,"date":"2009-11-22T23:36:45","date_gmt":"2009-11-23T05:36:45","guid":{"rendered":"http:\/\/alliwalk.com\/blog\/?p=827"},"modified":"2009-12-13T16:49:40","modified_gmt":"2009-12-13T22:49:40","slug":"phys-comp-final-iii-wav-shield","status":"publish","type":"post","link":"https:\/\/alliwalk.com\/blog\/2009\/11\/phys-comp-final-iii-wav-shield\/","title":{"rendered":"Using the wave shield"},"content":{"rendered":"<p>Introduction: The idea behind this post was to describe how I attempted to use a wave shield to play a sound using a photocell as the trigger.<\/p>\n<p>Description: Just for the record, the code for the wave shield is really confusing, but I have gotten it to work &#8211; though that was a painful process. After about 45-60 minutes, it became apparent that the problem I had with playing the .wav files on the SD card was due to the SD card being formatted as FAT 12, not FAT 16. Then at least another 30 minutes was spent trying to find a Windows computer to reformat the card. (We don&#8217;t have authority on the computer lab PCs.)<\/p>\n<p>Now, it plays &#8220;ominous noise&#8221; and the intro to BBC America news.<\/p>\n<p><object type=\"application\/x-shockwave-flash\" width=\"400\" height=\"225\" data=\"http:\/\/www.flickr.com\/apps\/video\/stewart.swf?v=71377\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"flashvars\" value=\"intl_lang=en-us&#038;photo_secret=d00ef946b9&#038;photo_id=4127345114\"><\/param><param name=\"movie\" value=\"http:\/\/www.flickr.com\/apps\/video\/stewart.swf?v=71377\"><\/param><param name=\"bgcolor\" value=\"#000000\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><embed type=\"application\/x-shockwave-flash\" src=\"http:\/\/www.flickr.com\/apps\/video\/stewart.swf?v=71377\" bgcolor=\"#000000\" allowfullscreen=\"true\" flashvars=\"intl_lang=en-us&#038;photo_secret=d00ef946b9&#038;photo_id=4127345114\" height=\"225\" width=\"400\"><\/embed><\/object><br \/>\n<a href=\"http:\/\/www.flickr.com\/photos\/alliwalk\/4127345114\/\">Testing the WAV shield<\/p>\n<p><\/a><\/p>\n<p>For my next trick, what I&#8217;d like to do is to put this code inside the loop for the LED-shadow sketch.<\/p>\n<pre>#include &lt;AF_Wave.h&gt;\r\n#include &lt;avr\/pgmspace.h&gt;\r\n#include \"util.h\"\r\n#include \"wave.h\"\r\n\r\nAF_Wave card;\r\nFile f;\r\nWavefile wave;\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ only one!\r\n\r\n#define redled 9\r\n\r\nuint16_t samplerate;\r\n\r\nvoid setup() {\r\n\u00a0 Serial.begin(9600);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ set up Serial library at 9600 bps\r\n\u00a0 Serial.println(\"Wave test!\");\r\n\r\n\u00a0 pinMode(2, OUTPUT);\r\n\u00a0 pinMode(3, OUTPUT);\r\n\u00a0 pinMode(4, OUTPUT);\r\n\u00a0 pinMode(5, OUTPUT);\r\n\u00a0 pinMode(redled, OUTPUT);\r\n\r\n\u00a0 if (!card.init_card()) {\r\n\u00a0\u00a0\u00a0 putstring_nl(\"Card init. failed!\"); return;\r\n\u00a0 }\r\n\u00a0 if (!card.open_partition()) {\r\n\u00a0\u00a0\u00a0 putstring_nl(\"No partition!\"); return;\r\n\u00a0 }\r\n\u00a0 if (!card.open_filesys()) {\r\n\u00a0\u00a0\u00a0 putstring_nl(\"Couldn't open filesys\"); return;\r\n\u00a0 }\r\n\r\n\u00a0if (!card.open_rootdir()) {\r\n\u00a0\u00a0\u00a0 putstring_nl(\"Couldn't open dir\"); return;\r\n\u00a0 }\r\n\r\n\u00a0 putstring_nl(\"Files found:\");\r\n\u00a0 ls();\r\n}\r\n\r\nvoid ls() {\r\n\u00a0 char name[13];\r\n\u00a0 int ret;\r\n\r\n\u00a0 card.reset_dir();\r\n\u00a0 putstring_nl(\"Files found:\");\r\n\u00a0 while (1) {\r\n\u00a0\u00a0\u00a0 ret = card.get_next_name_in_dir(name);\r\n\u00a0\u00a0\u00a0 if (!ret) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 card.reset_dir();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 Serial.println(name);\r\n\u00a0 }\r\n}\r\n\r\nuint8_t tracknum = 0;\r\n\r\nvoid loop() {\r\n\u00a0\u00a0 uint8_t i, r;\r\n\u00a0\u00a0 char c, name[15];\r\n\r\n\u00a0\u00a0 card.reset_dir();\r\n\u00a0\u00a0 \/\/ scroll through the files in the directory\r\n\u00a0\u00a0 for (i=0; i&lt;tracknum+1; i++) {\r\n\u00a0\u00a0\u00a0\u00a0 r = card.get_next_name_in_dir(name);\r\n\u00a0\u00a0\u00a0\u00a0 if (!r) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ ran out of tracks! start over\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tracknum = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return;\r\n\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0 }\r\n\u00a0\u00a0 putstring(\"\\n\\rPlaying \"); Serial.print(name);\r\n\u00a0\u00a0 \/\/ reset the directory so we can find the file\r\n\u00a0\u00a0 card.reset_dir();\r\n\u00a0\u00a0 playcomplete(name);\r\n\u00a0\u00a0 tracknum++;\r\n}\r\n\r\nvoid playcomplete(char *name) {\r\n\u00a0 uint16_t potval;\r\n\u00a0 uint32_t newsamplerate;\r\n\r\n\u00a0 playfile(name);\r\n\u00a0 samplerate = wave.dwSamplesPerSec;\r\n\u00a0 while (wave.isplaying) {\r\n\u00a0\u00a0\u00a0 \/\/ you can do stuff here!\r\n\u00a0\u00a0\u00a0 delay(500);\r\n\u00a0\u00a0 }\r\n\u00a0 card.close_file(f);\r\n}\r\n\r\nvoid playfile(char *name) {\r\n\u00a0\u00a0 f = card.open_file(name);\r\n\u00a0\u00a0 if (!f) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 putstring_nl(\" Couldn't open file\"); return;\r\n\u00a0\u00a0 }\r\n\u00a0\u00a0 if (!wave.create(f)) {\r\n\u00a0\u00a0\u00a0\u00a0 putstring_nl(\" Not a valid WAV\"); return;\r\n\u00a0\u00a0 }\r\n\u00a0\u00a0 \/\/ ok time to play!\r\n\u00a0\u00a0 wave.play();\r\n}<\/pre>\n<p>Considering how strung out I feel regarding finishing my finals before I head to London, I hope to make it alive through this particular process. It seems doubtful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: The idea behind this post was to describe how I attempted to use a wave shield to play a sound using a photocell as the trigger. Description: Just for the record, the code for the wave shield is really confusing, but I have gotten it to work &#8211; though that was a painful process. &hellip; <a href=\"https:\/\/alliwalk.com\/blog\/2009\/11\/phys-comp-final-iii-wav-shield\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using the wave shield&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[77,76],"tags":[82,161],"_links":{"self":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/827"}],"collection":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":10,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"predecessor-version":[{"id":881,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions\/881"}],"wp:attachment":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}