{"id":29,"date":"2014-11-29T20:22:00","date_gmt":"2014-11-29T20:22:00","guid":{"rendered":"http:\/\/www.celesteh.com\/blog\/2014\/11\/29\/broken-bmp-converter\/"},"modified":"2015-06-19T00:22:54","modified_gmt":"2015-06-18T23:22:54","slug":"broken-bmp-converter","status":"publish","type":"post","link":"https:\/\/www.celesteh.com\/blog\/2014\/11\/29\/broken-bmp-converter\/","title":{"rendered":"Broken bmp converter"},"content":{"rendered":"<div class=\"separator\" style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-PAF4ReiQQCs\/VHon63TCbDI\/AAAAAAAABFk\/G1v2clJFaQQ\/s1600\/min.au.bmp\" imageanchor=\"1\" style=\"clear: right; float: right; margin-bottom: 1em; margin-left: 1em;\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-PAF4ReiQQCs\/VHon63TCbDI\/AAAAAAAABFk\/G1v2clJFaQQ\/s320\/min.au.bmp\" \/><\/a><\/div>\n<p>I&#8217;ve spent all evening trying to convert from .au files to bmp, and I&#8217;ve realised I&#8217;m really doing this the wrong way. This realisation partly brought about becase the conversion is obviously not working.  The images are kind of pretty, though, so I thought I&#8217;d post the script. It runs in <a href=\"http:\/\/processing.org\">Processing<\/a>, which is a simplified version of java.<br \/>\nHow this code works is that it opens a file dialogue, in which the user is expected to select an .au audio file, but it doesn&#8217;t enforce this, so try data bending any file if you want.  It then prints the file out onto the screen as if it were made up of integers giving pixel colours. Then, it saves that as a bmp.<br \/>\nWhat it <em>should<\/em> do is just put a bmp header at the top of an existing file, but I thought I was being smart.<br \/>\nthe code is below. This was developed for a new commission I&#8217;m trying to get done. Hopefully, I&#8217;ll sort this out properly tomorrow, or if not, it will have to wait for the next digital commission (which could be yours!).<br \/>\nCommissions make excellent gifts! <a href=\"https:\/\/www.etsy.com\/shop\/celesteh\">Order now<\/a> and delivery is guaranteed in time for Christmas or Hanukkah. <\/p>\n<div class=\"separator\" style=\"clear: both; text-align: center;\">\n    <a href=\"https:\/\/www.etsy.com\/shop\/celesteh\"><br \/>\n        <img decoding=\"async\" border=\"0\" data-src=\"http:\/\/www.celesteh.com\/blog\/wp-content\/uploads\/2014\/11\/bammer.png\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 400px; --smush-placeholder-aspect-ratio: 400\/52;\"><\/img><br \/>\n    <\/a>\n<\/div>\n<pre>\n\n\/\/ look at au header\n\/\/ get the offset (32 bit word #1 (starting from 0))\n\/\/ get the size (32 bit word #2) -- nevermind that\n\/\/ set the sketch to that size, roughly square\n\/\/ write from the the offset to the end to all the pixels\n\/\/ save as bmp\n\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.DataInputStream;\n\nint x, y;\nlong length;\n\nDataInputStream din;\nFileInputStream fin;\n\nString name;\n\n\nvoid setup()\n{\n  x = 100; y = 100;\n  size(4410, 600); \/\/ 1 minute\n  selectInput(\"Select a file to process:\", \"fileSelected\");\n  frame.setResizable(true);\n  noLoop();\n\n}\n\nvoid fileSelected(File file){\n  \n    try {\n    \/\/File file = new File(\"\/home\/celesteh\/Documents\/inProgress\/shorts\/rh\/auToBmp\/data\/sine.au\");\n    name = file.getName();\n    \n    fin = new FileInputStream(file);\n    din = new DataInputStream(fin);\n    din.readInt(); \/\/ magic number\n    int offset = din.readInt();\n    System.out.println(offset);\n    int skipTo = 16;\/\/offset-8;\/\/ (32 bits + 32 bits) \/ 8\n    din.skipBytes(skipTo);\n    length = file.length() \/*864*\/ - skipTo;\n    length = length \/4; \/\/ 32 bit ints\n    System.out.println(length);\n    float root = sqrt(length);\n    x = ceil(root);\n    y = floor(root);\n    while( (x * y) &lt; length)\n      x++;\n    System.out.println(x);\n    frame.setSize(x, y);\n    redraw();\n  } catch (IOException fe)\n  {  exit();\n  }\n  \n\n  \n  \/\/redraw();\n  \/\/redraw();\n}\n\nvoid draw() {\n    int b;\n    \n    frame.setSize(x, y);\n    \n    if (din != null) {\n      try {\n        loadPixels();\n        for (int i = 0; (i &lt; length) && (i &lt; pixels.length); i++)  {\n          pixels[i] = din.readInt(); \/\/readByte();\n          \/\/din.readByte(); din.readByte();\n        }\n        \/\/updatePixels();\n        din.close(); \n      } catch (IOException fe) {\n        \n      } finally {\n        updatePixels();\n        saveFrame(name.concat(\".bmp\"));\n        \n      }\n              \n     \n\n    }\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve spent all evening trying to convert from .au files to bmp, and I&#8217;ve realised I&#8217;m really doing this the wrong way. This realisation partly brought about becase the conversion is obviously not working. The images are kind of pretty, though, so I thought I&#8217;d post the script. It runs in Processing, which is a &hellip; <a href=\"https:\/\/www.celesteh.com\/blog\/2014\/11\/29\/broken-bmp-converter\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Broken bmp converter<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[1],"tags":[35,36],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-code","tag-processing"],"_links":{"self":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":1,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":2193,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/29\/revisions\/2193"}],"wp:attachment":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}