{"id":412,"date":"2021-09-08T13:44:01","date_gmt":"2021-09-08T17:44:01","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/?p=412"},"modified":"2021-09-08T13:45:46","modified_gmt":"2021-09-08T17:45:46","slug":"grape-linewalk","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/grape\/09\/08\/grape-linewalk\/","title":{"rendered":"grape &#8211; LineWalk"},"content":{"rendered":"<p>I was mainly inspired by this old <a href=\"https:\/\/www.youtube.com\/watch?v=5EWEkJA5GM0&amp;ab_channel=smallgoblin\">Youtube clip<\/a> in which the person &#8220;plays&#8221; the Imperial March by writing a math equation. So for my line walk, I wanted something that didn&#8217;t necessarily &#8220;look&#8221; cool, but performed&#8230;cool. I wanted to see if the axidraw could sync up to the music. So I started looking through Processing&#8217;s Sound Library for anything on pitch detection. Instead I found amplitude and beat detectors which I turned into the following &#8220;records.&#8221;<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/waltz.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-513\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/waltz.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>waltz of the flowers<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/rock.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-514\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/rock.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>we will rock you<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/rick.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-516\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/rick.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>rickroll<\/p>\n<p>_______ beat detection\u00a0 ________<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/takeon.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-517\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/takeon.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>take on me<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/cantina.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-522\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/cantina.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>cantina band<\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/badguy.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-523\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/badguy.svg\" alt=\"\" width=\"640\" height=\"480\" \/><\/a><\/p>\n<p>bad guy<\/p>\n<p>I think in order to get closer to my goal of an axidraw performance I&#8217;m going to look for libraries with pitch detection + maybe smoothing on the output. Otherwise I&#8217;ll add an additional threshold to the amplitude and simplify the movement of the record to make different notes more distinct.<\/p>\n<p>code<\/p>\n<p><code><\/code><\/p>\n<pre>import processing.sound.*;\r\nimport processing.svg.*;\r\n\r\n\/\/ Declare the sound source and FFT analyzer variables\r\nSoundFile sample;\r\nAmplitude amp;\r\n\r\nint num = 3500;\r\nint range = 6;\r\n\r\nfloat[] ax = new float[num];\r\nfloat[] ay = new float[num]; \r\n\/\/ Define how many FFT bands to use (this needs to be a power of two)\r\nint bands = 256;\r\nfloat inc;\r\nfloat growth;\r\n\r\nfloat smoothingFactor = 0.3;\r\n\r\n\/\/ Create a vector to store the smoothed spectrum data in\r\nfloat[] sum = new float[bands];\r\n\r\n\/\/ Variables for drawing the spectrum:\r\n\/\/ Declare a scaling factor for adjusting the height of the rectangles\r\nint scale = 5;\r\n\/\/ Declare a drawing variable for calculating the width of the\r\nfloat barWidth;\r\nfloat rotater;\r\n\r\nvoid setup() {\r\n  size(768, 768);\r\n  background(255);\r\n  beginRecord(SVG, \"badguy.svg\");\r\n  rotater = 0.0;\r\n  inc = 0.0;\r\n  growth = 0.05;\r\n\r\n  for(int i = 0; i &lt; num; i++) {\r\n    ax[i] = 0;\r\n    ay[i] = 0;\r\n  }\r\n  frameRate(30);\r\n  \r\n  \/\/ Calculate the width of the rects depending on how many bands we have\r\n  barWidth = width\/float(bands);\r\n\r\n  \/\/ Load and play a soundfile and loop it.\r\n  sample = new SoundFile(this, \"badguy.aif\");\r\n  sample.loop();\r\n\r\n  \/\/ Create the FFT analyzer and connect the playing soundfile to it.\r\n  amp = new Amplitude(this);\r\n  amp.input(sample);\r\n}\r\n\r\nvoid draw() {\r\n  \/\/ Perform the analysis\r\n  translate(width\/2, height\/2);\r\n  for(int i = 1; i &lt; num; i++) {\r\n    ax[i-1] = ax[i];\/\/ *cos(rotater);\r\n    ay[i-1] = ay[i];\/\/ *sin(rotater);\r\n  }\r\n  float r = map(amp.analyze(), 0, 0.1, inc, 40+inc);\r\n  float x = r * cos(rotater);\r\n  float y = r * sin(rotater);\r\n  ax[num-1] = x;\r\n  ay[num-1] = y;\r\n  stroke(0);\r\n  for(int i=1; i&lt;num; i++) {    \r\n    line(ax[i-1], ay[i-1], ax[i], ay[i]);\r\n  }\r\n  \/\/stroke(255);\r\n  \/\/line(0,0,x,y);\r\n  inc += growth;\r\n  rotater+=0.01;\r\n  if(int(rotater)==360)rotater = 0;\r\n  if(int(inc) == 0) growth = 0.05;\r\n  if(int(inc) == height\/3) growth =-0.05;\r\n}\r\n\r\nvoid mousePressed() {\r\n  endRecord();\r\n  exit();\r\n} \r\n<\/pre>\n<p>the beat detection code is the same as above except you use a new BeatDetector (it also uses the analyze() function). Also my code is pretty terrible. In order to store all the measurements of beats\/amplitudes I just used an array (after looking at some brownian motion stuff) which is not good for optimization.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was mainly inspired by this old Youtube clip in which the person &#8220;plays&#8221; the Imperial March by writing a math equation. So for my line walk, I wanted something that didn&#8217;t necessarily &#8220;look&#8221; cool, but performed&#8230;cool. I wanted to see if the axidraw could sync up to the music. So I started looking through &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/grape\/09\/08\/grape-linewalk\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;grape &#8211; LineWalk&#8221;<\/span><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/412"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/412\/revisions\/541"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}