{"id":9992,"date":"2014-02-16T02:53:39","date_gmt":"2014-02-16T02:53:39","guid":{"rendered":"http:\/\/zerokidz.com\/ideas\/?p=9992"},"modified":"2014-06-20T12:34:00","modified_gmt":"2014-06-20T16:34:00","slug":"rtl-sdr-pd-max-and-mac","status":"publish","type":"post","link":"https:\/\/reactivemusic.net\/?p=9992","title":{"rendered":"rtl-sdr: Pd, Max and Mac"},"content":{"rendered":"<p class=\"lead\">Notes on compiling rtl_sdr in Mac OS &#8211; writing Max and Pd Externals.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"panel callout\">\n<p>update 3\/31\/2014<\/p>\n<\/div>\n<p>Today I got the Pd external running &#8211; using essentially same source code as Max. There is occasional weirdness going on with audio clicks when starting\/stopping the radio, but other than that it seems fine and it runs. wooHOO. More to follow&#8230;<\/p>\n<p>&nbsp;<\/p>\n<div class=\"panel\">\n<p>update 3\/28\/2014<\/p>\n<\/div>\n<p>Now have set up a skeleton for Pd, called rtlfmz~ (inside the Pd application bundle) which does absolutely nothing but compiles all of the project files and calls a function in rtl_fm. \u00a0Next step will be to port the actual Max external code and do the conversion.<\/p>\n<div class=\"panel callout\">\n<p>updates 3\/38\/2014 before working on Pd version<\/p>\n<\/div>\n<p>There is now a fairly solid max external (rtlfmz~) using a recent version for rtl_fm. Also there is a simple Makefile that compiles local version of rtl_fm3.c in:<\/p>\n<p>tkzic\/rtl-sdr-new\/rtl-sdr\/rtl-fm3<\/p>\n<p>There are very minor changes to rtl_fm.c (for includes) and also a local version of librtlsdr.a (librtlsdr32.a) that is 32 bit.<\/p>\n<p>The current state of the Max external does both pre-demodulated and raw IQ output, but you can only run one copy \u00a0of the object due to excess use of global variables and my uncertainty over how to run multiple devices, threading, etc., \u00a0&#8211; but we&#8217;ll go with it an try porting to Pd now.<\/p>\n<div class=\"panel\">\n<p>update 2\/27 &#8211; converted to using new version of rtl_fm<\/p>\n<\/div>\n<p>I had been using an older version of rtl_fm &#8211;<\/p>\n<p>renamed external to rtlfmz~ and now using new version as (rtl_fm3.c) in the project<\/p>\n<p>In addition to recopying the librtlsdr.a &#8211; I also recopied all of the include files and added two new files<\/p>\n<p>convenience.c convenience.h<\/p>\n<p>There is a different method of threading and reading which I haven&#8217;t looked at yet, but it is now doing what it did before inside Max, which is read FM for a few seconds and write audio data to a file<\/p>\n<p>plan: Set up a circular buffer accessible to the output thread and to the max perform function. &#8211; then see if we can get it to run for a few seconds.<\/p>\n<p>The main thing to think about is how to let the processing happen in another thread while returning control to max. Then there really should be a way to interrupt processing from max.<\/p>\n<p>There needs to be a max instance variable that tells whether the radio is running or not. Then, when its time to stop &#8211; you just do all the cleanup stuff that is at the end of the rtl_fm main() function.<\/p>\n<p><span style=\"line-height: 1.6;\">\u00a0<\/span><\/p>\n<div class=\"panel\">\n<p>update 2\/18\/2014 &#8211; Max external<\/p>\n<\/div>\n<p>Now have rtl_fm function within the plussztz~ external<\/p>\n<p>It detects, opens device, demodulates about 30 seconds of FM, and writes audio at 44.1kHz. to a file \/tmp\/radio.bin &#8211; which can be played by the play command<\/p>\n<p>Changes to code included:<\/p>\n<ul>\n<li>removing exit calls<\/li>\n<li>changing printf to post()<\/li>\n<li>removing signal interrupt handling<\/li>\n<\/ul>\n<div><span style=\"line-height: 22px;\">remaining to do:<\/span><\/div>\n<div><\/div>\n<div>\n<ul>\n<li><span style=\"line-height: 1;\">Need a way to get the device to read in the background &#8211; so its not blocking the Max thread<\/span><\/li>\n<li><span style=\"line-height: 1;\">Need a way to stop\/restrart the device &#8211; because if we aren&#8217;t, the continual sync_reads will waste a lot of cpu cycles.<\/span><\/li>\n<\/ul>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div class=\"panel callout\">\n<p>update 2\/15\/2014 &#8211; Max external<\/p>\n<\/div>\n<p>Have now successfully \u00a0compiled a test external in Max 6.1.4 &#8211; name is plussztz~ and it includes the rtl_fm code. \u00a0Made 2 changes so far:<\/p>\n<ul>\n<li>in build settings, set architectures to i386<\/li>\n<li>in rtl_fm2, changed &lt;include&gt; libusb.h to &#8220;include&#8221; libusb.h<\/li>\n<li><\/li>\n<\/ul>\n<div class=\"panel\">\n<p>original post<\/p>\n<\/div>\n<p>Today I was able to write a simple makefile to compile the rtl_fm app using the libusb and librtlsdr dynamic libraries.<\/p>\n<p>Pd requires i386 architecture for externals (i386) so I then compiled the app using static libraries and the i386 architecture.<\/p>\n<p>libusb-1.0 already had a 32 bit version in \/usr\/local\/lib\/libusb32-1.0.a (note that this version also requires compiling these frameworks:<\/p>\n<div class=\"panel\">\n<p>-framework foundation -framework iokit<\/p>\n<\/div>\n<p>For librtlsdr, I rebuilt, using cmake with the following flags:<\/p>\n<div class=\"panel\">\n<p>cmake ..\/ -DCMAKE_OSX_ARCHITECTURES=i386 -DINSTALL_UDEV_RULES=ON<\/p>\n<\/div>\n<p>But did not install the result. See this link for details on building with cmake:\u00a0<a href=\"http:\/\/sdr.osmocom.org\/trac\/wiki\/rtl-sdr\">http:\/\/sdr.osmocom.org\/trac\/wiki\/rtl-sdr<\/a><\/p>\n<p>This produced a 32 bit static version of librtlsdr.a that could be used for building the app.<\/p>\n<p>See this Stack Overflow post for more on cmake and architectures:\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/5334095\/cmake-multiarchitecture-compilation\">http:\/\/stackoverflow.com\/questions\/5334095\/cmake-multiarchitecture-compilation<\/a><\/p>\n<p><strong>local files:<\/strong><\/p>\n<p>currently local version of this test is in: tkzic\/rtl-sdr-tz\/rtl_fm2\/<\/p>\n<p>The default makefile builds the 32 bit architecture.<\/p>\n<p><strong>Next:<\/strong><\/p>\n<ul>\n<li>try to move the makefile into Xcode<\/li>\n<li>try compiling rtl_sdr or rtl_fm as a simple max object &#8211; the fm app might be better to start with since it gives an audio signal output.<\/li>\n<li>then try in pd<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes on compiling rtl_sdr in Mac OS &#8211; writing Max and Pd Externals. &nbsp; update 3\/31\/2014 Today I got the Pd external running &#8211; using essentially same source code as Max. There is occasional weirdness going on with audio clicks when starting\/stopping the radio, but other than that it seems fine and it runs. wooHOO. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/reactivemusic.net\/?p=9992\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;rtl-sdr: Pd, Max and Mac&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[230,21,28,249],"tags":[190,57,243],"class_list":["post-9992","post","type-post","status-publish","format-standard","hentry","category-development","category-dsp","category-maxmsp","category-pd-2","tag-portfolio","tag-radio","tag-software-defined-radio"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>rtl-sdr: Pd, Max and Mac - reactive music<\/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:\/\/reactivemusic.net\/?p=9992\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"rtl-sdr: Pd, Max and Mac - reactive music\" \/>\n<meta property=\"og:description\" content=\"Notes on compiling rtl_sdr in Mac OS &#8211; writing Max and Pd Externals. &nbsp; update 3\/31\/2014 Today I got the Pd external running &#8211; using essentially same source code as Max. There is occasional weirdness going on with audio clicks when starting\/stopping the radio, but other than that it seems fine and it runs. wooHOO. &hellip; Continue reading &quot;rtl-sdr: Pd, Max and Mac&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/reactivemusic.net\/?p=9992\" \/>\n<meta property=\"og:site_name\" content=\"reactive music\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-16T02:53:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-06-20T16:34:00+00:00\" \/>\n<meta name=\"author\" content=\"Tom Zicarelli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tom Zicarelli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992\"},\"author\":{\"name\":\"Tom Zicarelli\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\"},\"headline\":\"rtl-sdr: Pd, Max and Mac\",\"datePublished\":\"2014-02-16T02:53:39+00:00\",\"dateModified\":\"2014-06-20T16:34:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992\"},\"wordCount\":806,\"keywords\":[\"portfolio\",\"radio\",\"software defined radio\"],\"articleSection\":[\"development\",\"DSP\",\"Max\\\/MSP\",\"Pd\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992\",\"name\":\"rtl-sdr: Pd, Max and Mac - reactive music\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\"},\"datePublished\":\"2014-02-16T02:53:39+00:00\",\"dateModified\":\"2014-06-20T16:34:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/reactivemusic.net\\\/?p=9992\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=9992#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/reactivemusic.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"rtl-sdr: Pd, Max and Mac\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/\",\"name\":\"reactive music\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/reactivemusic.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/56224d281582df7e5518e037ca63e571\",\"name\":\"Tom Zicarelli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g\",\"caption\":\"Tom Zicarelli\"},\"sameAs\":[\"http:\\\/\\\/tomzicarelli.com\"],\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"rtl-sdr: Pd, Max and Mac - reactive music","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:\/\/reactivemusic.net\/?p=9992","og_locale":"en_US","og_type":"article","og_title":"rtl-sdr: Pd, Max and Mac - reactive music","og_description":"Notes on compiling rtl_sdr in Mac OS &#8211; writing Max and Pd Externals. &nbsp; update 3\/31\/2014 Today I got the Pd external running &#8211; using essentially same source code as Max. There is occasional weirdness going on with audio clicks when starting\/stopping the radio, but other than that it seems fine and it runs. wooHOO. &hellip; Continue reading \"rtl-sdr: Pd, Max and Mac\"","og_url":"https:\/\/reactivemusic.net\/?p=9992","og_site_name":"reactive music","article_published_time":"2014-02-16T02:53:39+00:00","article_modified_time":"2014-06-20T16:34:00+00:00","author":"Tom Zicarelli","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Tom Zicarelli","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/reactivemusic.net\/?p=9992#article","isPartOf":{"@id":"https:\/\/reactivemusic.net\/?p=9992"},"author":{"name":"Tom Zicarelli","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571"},"headline":"rtl-sdr: Pd, Max and Mac","datePublished":"2014-02-16T02:53:39+00:00","dateModified":"2014-06-20T16:34:00+00:00","mainEntityOfPage":{"@id":"https:\/\/reactivemusic.net\/?p=9992"},"wordCount":806,"keywords":["portfolio","radio","software defined radio"],"articleSection":["development","DSP","Max\/MSP","Pd"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/reactivemusic.net\/?p=9992","url":"https:\/\/reactivemusic.net\/?p=9992","name":"rtl-sdr: Pd, Max and Mac - reactive music","isPartOf":{"@id":"https:\/\/reactivemusic.net\/#website"},"datePublished":"2014-02-16T02:53:39+00:00","dateModified":"2014-06-20T16:34:00+00:00","author":{"@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571"},"breadcrumb":{"@id":"https:\/\/reactivemusic.net\/?p=9992#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/reactivemusic.net\/?p=9992"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/reactivemusic.net\/?p=9992#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/reactivemusic.net\/"},{"@type":"ListItem","position":2,"name":"rtl-sdr: Pd, Max and Mac"}]},{"@type":"WebSite","@id":"https:\/\/reactivemusic.net\/#website","url":"https:\/\/reactivemusic.net\/","name":"reactive music","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/reactivemusic.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/56224d281582df7e5518e037ca63e571","name":"Tom Zicarelli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0da58cf21a2707dd335b204b8ed3cd9194dcbf9d9814ac5d71195a65c76c8a72?s=96&d=mm&r=g","caption":"Tom Zicarelli"},"sameAs":["http:\/\/tomzicarelli.com"],"url":"https:\/\/reactivemusic.net\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/9992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9992"}],"version-history":[{"count":16,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/9992\/revisions"}],"predecessor-version":[{"id":9994,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/9992\/revisions\/9994"}],"wp:attachment":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}