{"id":4150,"date":"2021-12-20T10:43:39","date_gmt":"2021-12-20T09:43:39","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=4150"},"modified":"2024-03-21T08:00:24","modified_gmt":"2024-03-21T07:00:24","slug":"ai-thinker-audio-kit-synthesizer-to-bluetooth","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/","title":{"rendered":"AI Thinker Audio Kit:  Synthesizer to Bluetooth"},"content":{"rendered":"<p>In the <a href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/19\/ai-thinker-audio-kit-building-a-simple-synthesizer-with-the-audiotools-library-continued\/\">last Blog, I have shown how to use the Synthesizer class<\/a>. I wanted to verify the audio quality issue by sending the output to Bluetooth<\/p>\n<p>Here is the sketch. I just added a callback method to feed the bluetooth source:<\/p>\n<h2>Arduino Sketch<\/h2>\n<pre><code>#define USE_MIDI\n#include \"BluetoothA2DPSource.h\"\n#include \"AudioTools.h\"\n#include \"AudioTools\/Synthesizer.h\"\n#include \"AudioLibs\/AudioKit.h\"\n\nBluetoothA2DPSource a2dp_source;\n\nAudioKitStream kit;\nSynthesizer synthesizer;\nGeneratedSoundStream&lt;int16_t&gt; in(synthesizer); \nSynthesizerKey keys[] = {{PIN_KEY1, N_C3},{PIN_KEY2, N_D3},{PIN_KEY3, N_E3},{PIN_KEY4, N_F3},{PIN_KEY5, N_G3},{PIN_KEY6, N_A3},{0,0}};\n\nint32_t get_sound_data(Frame *data, int32_t len) {\n  int16_t sample = synthesizer.readSamples((int16_t(*)[2])data,len);\n  delay(1);\n  return len;\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial,AudioLogger::Info);\n\n  \/\/ setup synthezizer keys\n  synthesizer.setKeys(kit.audioActions(), keys, AudioActions::ActiveLow);\n  synthesizer.setMidiName(\"AudioKit Synthesizer\");\n\n  \/\/ define generated audio format\n  auto cfg = in.defaultConfig();\n  cfg.channels = 2;\n  cfg.sample_rate = 44100;\n  in.begin(cfg);\n\n  a2dp_source.start(\"LEXON MINO L\", get_sound_data);  \n  a2dp_source.set_volume(20); \n}\n\nvoid loop() {\n  kit.processActions();\n  delay(1);\n}\n\n<\/code><\/pre>\n<p>I still need the AudioKitStream class, but just to handle the keys. In the get_sound_data callback method we can just forward the call to the synthezizer to provide the data. The delay(1) are necessary to avoid any errors from the Watchdog&#8230;<\/p>\n<p>Unfortunately I can confirm the issue with the polyphoinc sound generation: So at least I have narrowed down the source of the problem.<br \/>\nThere is also a lag between the key press and the audible sound, which if from my feeling a little bit too high to be practically useful!<\/p>\n<h1>Source Code<\/h1>\n<p>The (potentially updated) source code can be found in the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/tree\/main\/examples\/examples-audiokit\/streams-synth-a2dp\">samples directory<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last Blog, I have shown how to use the Synthesizer class. I wanted to verify the audio quality issue by sending the output to Bluetooth Here is the sketch. I just added a callback method to feed the bluetooth source: Arduino Sketch #define USE_MIDI #include &#8220;BluetoothA2DPSource.h&#8221; #include &#8220;AudioTools.h&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4151,"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":[46,28,26],"class_list":["post-4150","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-communications","tag-esp32audiokit","tag-synthesizer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AI Thinker Audio Kit: Synthesizer to Bluetooth - 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\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AI Thinker Audio Kit: Synthesizer to Bluetooth - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"In the last Blog, I have shown how to use the Synthesizer class. I wanted to verify the audio quality issue by sending the output to Bluetooth Here is the sketch. I just added a callback method to feed the bluetooth source: Arduino Sketch #define USE_MIDI #include &quot;BluetoothA2DPSource.h&quot; #include &quot;AudioTools.h&quot; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-20T09:43:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-21T07:00:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"AI Thinker Audio Kit: Synthesizer to Bluetooth\",\"datePublished\":\"2021-12-20T09:43:39+00:00\",\"dateModified\":\"2024-03-21T07:00:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/\"},\"wordCount\":158,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/A2DP.jpg\",\"keywords\":[\"Communications\",\"ESP32AudioKit\",\"Synthesizer\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/\",\"name\":\"AI Thinker Audio Kit: Synthesizer to Bluetooth - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/A2DP.jpg\",\"datePublished\":\"2021-12-20T09:43:39+00:00\",\"dateModified\":\"2024-03-21T07:00:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/A2DP.jpg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/A2DP.jpg\",\"width\":600,\"height\":450},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/20\\\/ai-thinker-audio-kit-synthesizer-to-bluetooth\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI Thinker Audio Kit: Synthesizer to Bluetooth\"}]},{\"@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":"AI Thinker Audio Kit: Synthesizer to Bluetooth - 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\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/","og_locale":"en_US","og_type":"article","og_title":"AI Thinker Audio Kit: Synthesizer to Bluetooth - Phil Schatzmann","og_description":"In the last Blog, I have shown how to use the Synthesizer class. I wanted to verify the audio quality issue by sending the output to Bluetooth Here is the sketch. I just added a callback method to feed the bluetooth source: Arduino Sketch #define USE_MIDI #include \"BluetoothA2DPSource.h\" #include \"AudioTools.h\" [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-12-20T09:43:39+00:00","article_modified_time":"2024-03-21T07:00:24+00:00","og_image":[{"width":600,"height":450,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg","type":"image\/jpeg"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"AI Thinker Audio Kit: Synthesizer to Bluetooth","datePublished":"2021-12-20T09:43:39+00:00","dateModified":"2024-03-21T07:00:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/"},"wordCount":158,"commentCount":3,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg","keywords":["Communications","ESP32AudioKit","Synthesizer"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/","name":"AI Thinker Audio Kit: Synthesizer to Bluetooth - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg","datePublished":"2021-12-20T09:43:39+00:00","dateModified":"2024-03-21T07:00:24+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/A2DP.jpg","width":600,"height":450},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/20\/ai-thinker-audio-kit-synthesizer-to-bluetooth\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"AI Thinker Audio Kit: Synthesizer to Bluetooth"}]},{"@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\/4150","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=4150"}],"version-history":[{"count":3,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4150\/revisions"}],"predecessor-version":[{"id":4159,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4150\/revisions\/4159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/4151"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=4150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=4150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=4150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}