{"id":6400,"date":"2024-10-25T10:17:52","date_gmt":"2024-10-25T08:17:52","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=6400"},"modified":"2024-10-21T19:21:41","modified_gmt":"2024-10-21T17:21:41","slug":"tinyusb-audio-testing-the-microphone-quality","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/","title":{"rendered":"TinyUSB Audio: Testing the Microphone Quality using a Stream"},"content":{"rendered":"<p>In my <a href=\"https:\/\/www.pschatzmann.ch\/home\/tag\/TinyUSB\/\">last blogs<\/a>, I described how I managed to extend TinyUSB to provide an simple <strong>USB Audio device<\/strong> in Arduino.<\/p>\n<p>So far I have been using some <strong>randon numbers<\/strong> to generate noise. This is not very helpful to check if we lost some samples. A <strong>SawTooth wave<\/strong> is much more convinient.<\/p>\n<p>We can use the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">AudioTools<\/a> to generate this. Here is the example sketch, that also shows how we can define an Arduino Stream as input (as an alternative to the callbacks) that we have used so far.<\/p>\n<pre><code>#include \"Adafruit_TinyUSB.h\"\n#include \"AudioTools.h\"  \/\/ https:\/\/github.com\/pschatzmann\/arduino-audio-tools\n\nAdafruit_USBD_Audio usb;\nAudioInfo info(44100, 2, 16);\nSawToothGenerator&lt;int16_t&gt; sawtooth;               \nGeneratedSoundStream&lt;int16_t&gt; sawthooth_stream(sawtooth);\n\nvoid setup() {\n  Serial.begin(115200);\n  \/\/while(!Serial);  \/\/ wait for serial\n\n  \/\/ generate 493 hz (note B4)\n  sawtooth.begin(info, 493.0f);\n\n  \/\/ Start USB device as Audio Source\n  usb.setInput(sawthooth_stream);\n  usb.begin(info.sample_rate, info.channels, info.bits_per_sample);\n}\n\nvoid loop() {\n  \/\/ optional: use LED do display status\n  usb.updateLED();\n}\n<\/code><\/pre>\n<p>We just define a SawTooth, convert it to a GeneratedSoundStream and start the sawtooth by calling begin.<\/p>\n<p>And here is the result, visualized with the help of Audacity:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth-300x184.png\" alt=\"\" width=\"70%\" height=\"184\" class=\"alignnone size-medium wp-image-6401\" srcset=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth-300x184.png 300w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth-768x471.png 768w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png 1058w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Dependencies<\/h3>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Arduino AudioTools<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/Adafruit_TinyUSB_Arduino\">My fork of Adafruit_TinyUSB_Arduino<\/a><\/li>\n<\/ul>\n<p>Please <strong>note<\/strong> that this example is the conventions used at the time of posting. This might change, so you better double check with the examples that are provided with the TinyUSB project!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last blogs, I described how I managed to extend TinyUSB to provide an simple USB Audio device in Arduino. So far I have been using some randon numbers to generate noise. This is not very helpful to check if we lost some samples. A SawTooth wave is much [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22],"tags":[48],"class_list":["post-6400","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-tinyusb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"In my last blogs, I described how I managed to extend TinyUSB to provide an simple USB Audio device in Arduino. So far I have been using some randon numbers to generate noise. This is not very helpful to check if we lost some samples. A SawTooth wave is much [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-25T08:17:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1058\" \/>\n\t<meta property=\"og:image:height\" content=\"649\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"TinyUSB Audio: Testing the Microphone Quality using a Stream\",\"datePublished\":\"2024-10-25T08:17:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/\"},\"wordCount\":167,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Sawtooth.png\",\"keywords\":[\"TinyUSB\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/\",\"name\":\"TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Sawtooth.png\",\"datePublished\":\"2024-10-25T08:17:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Sawtooth.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Sawtooth.png\",\"width\":1058,\"height\":649},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/10\\\/25\\\/tinyusb-audio-testing-the-microphone-quality\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TinyUSB Audio: Testing the Microphone Quality using a Stream\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/","og_locale":"en_US","og_type":"article","og_title":"TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann","og_description":"In my last blogs, I described how I managed to extend TinyUSB to provide an simple USB Audio device in Arduino. So far I have been using some randon numbers to generate noise. This is not very helpful to check if we lost some samples. A SawTooth wave is much [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/","og_site_name":"Phil Schatzmann","article_published_time":"2024-10-25T08:17:52+00:00","og_image":[{"width":1058,"height":649,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png","type":"image\/png"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"TinyUSB Audio: Testing the Microphone Quality using a Stream","datePublished":"2024-10-25T08:17:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/"},"wordCount":167,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png","keywords":["TinyUSB"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/","url":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/","name":"TinyUSB Audio: Testing the Microphone Quality using a Stream - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png","datePublished":"2024-10-25T08:17:52+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/10\/Sawtooth.png","width":1058,"height":649},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/10\/25\/tinyusb-audio-testing-the-microphone-quality\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"TinyUSB Audio: Testing the Microphone Quality using a Stream"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=6400"}],"version-history":[{"count":10,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6400\/revisions"}],"predecessor-version":[{"id":6411,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6400\/revisions\/6411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/6401"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=6400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=6400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=6400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}