{"id":3809,"date":"2012-04-28T22:01:32","date_gmt":"2012-04-29T05:01:32","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=3809"},"modified":"2012-04-28T22:01:32","modified_gmt":"2012-04-29T05:01:32","slug":"how-to-write-an-oscilloscope","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/","title":{"rendered":"How To Write An Oscilloscope"},"content":{"rendered":"<p>I&#8217;m trying to figure out how to write a software oscilloscope audio visualization. It&#8217;s made more frustrating by the knowledge that I am certain that I have accomplished this task before.<\/p>\n<p>In this context, the oscilloscope is used to draw the time-domain samples of an audio wave form. <a href=\"http:\/\/xine.cvs.sourceforge.net\/viewvc\/xine\/xine-lib\/src\/post\/visualizations\/oscope.c?revision=HEAD&#038;view=markup\">I have written such a plugin as part<\/a> of <a href=\"http:\/\/www.xine-project.org\/home\">the xine project<\/a>. However, for that project, I didn&#8217;t have to write the full playback pipeline&#8211; my plugin was just handed some PCM data and drew some graphical data in response. Now I&#8217;m trying to write the entire engine in a standalone program and I&#8217;m wondering how to get it just right.<\/p>\n<p><center><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2012\/04\/duck-tales-moon-game-music-emu.png\" alt=\"\" title=\"Game Music Emu oscilloscope playing Duck Tales moon song\" width=\"514\" height=\"286\" class=\"aligncenter size-full wp-image-3810\" srcset=\"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2012\/04\/duck-tales-moon-game-music-emu.png 514w, https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2012\/04\/duck-tales-moon-game-music-emu-300x166.png 300w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><br \/>\n<\/center><\/p>\n<p>This is an <a href=\"http:\/\/www.libsdl.org\/\">SDL-based<\/a> oscilloscope visualizer and audio player for <a href=\"http:\/\/code.google.com\/p\/game-music-emu\/\">Game Music Emu library<\/a>. My approach is to have an audio buffer that holds a second of audio (44100 stereo 16-bit samples). The player updates the visualization at 30 frames per second. The o-scope is 512 pixels wide. So, at every 1\/30th second interval, the player dips into the audio buffer at position ((frame_number % 30) * 44100 \/ 30) and takes the first 512 stereo frames for plotting on the graph.<\/p>\n<p>It seems to be working okay, I guess. The only problem is that the A\/V sync seems to be slightly misaligned. I am just wondering if this is the correct approach. Perhaps the player should be performing some slightly more complicated calculation over those (44100\/30) audio frames during each update in order to obtain a more accurate graph? I described my process to an electrical engineer friend of mine and he insisted that I needed to apply <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hysteresis\">something called hysteresis<\/a> to the output or I would never get accurate A\/V sync in this scenario.<\/p>\n<p>Further, I know that some schools of thought on these matters require that the dots in those graphs be connected, that the scattered points simply won&#8217;t do. I guess it&#8217;s a stylistic choice.<\/p>\n<p>Still, I think I have a reasonable, workable approach here. I might just be starting the visualization 1\/30th of a second too late.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing a software oscilloscope doesn&#8217;t seem like it would be so hard&#8211; just graphing audio amplitude with respect to time; but there might be more to it<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[252,253,254],"class_list":["post-3809","post","type-post","status-publish","format-standard","hentry","category-general","tag-gme","tag-oscilloscope","tag-visualization"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Writing a software oscilloscope doesn&#039;t seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Multimedia Mike\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta property=\"og:description\" content=\"Writing a software oscilloscope doesn&#039;t seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2012-04-29T05:01:32+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2012-04-29T05:01:32+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Writing a software oscilloscope doesn&#039;t seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#article\",\"name\":\"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes\",\"headline\":\"How To Write An Oscilloscope\",\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/duck-tales-moon-game-music-emu.png\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#articleImage\",\"width\":514,\"height\":286},\"datePublished\":\"2012-04-28T22:01:32-07:00\",\"dateModified\":\"2012-04-28T22:01:32-07:00\",\"inLanguage\":\"en-US\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#webpage\"},\"articleSection\":\"General, gme, oscilloscope, visualization\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/general\\\/#listItem\",\"name\":\"General\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/general\\\/#listItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/general\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#listItem\",\"name\":\"How To Write An Oscilloscope\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#listItem\",\"position\":3,\"name\":\"How To Write An Oscilloscope\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/general\\\/#listItem\",\"name\":\"General\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/\",\"name\":\"Multimedia Mike\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Multimedia Mike\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#webpage\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/\",\"name\":\"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes\",\"description\":\"Writing a software oscilloscope doesn't seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/how-to-write-an-oscilloscope\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"datePublished\":\"2012-04-28T22:01:32-07:00\",\"dateModified\":\"2012-04-28T22:01:32-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes","description":"Writing a software oscilloscope doesn't seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it","canonical_url":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#article","name":"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes","headline":"How To Write An Oscilloscope","author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2012\/04\/duck-tales-moon-game-music-emu.png","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#articleImage","width":514,"height":286},"datePublished":"2012-04-28T22:01:32-07:00","dateModified":"2012-04-28T22:01:32-07:00","inLanguage":"en-US","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#webpage"},"isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#webpage"},"articleSection":"General, gme, oscilloscope, visualization"},{"@type":"BreadcrumbList","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/#listItem","position":1,"name":"Home","item":"https:\/\/multimedia.cx\/eggs\/","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/general\/#listItem","name":"General"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/general\/#listItem","position":2,"name":"General","item":"https:\/\/multimedia.cx\/eggs\/category\/general\/","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#listItem","name":"How To Write An Oscilloscope"},"previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#listItem","position":3,"name":"How To Write An Oscilloscope","previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/general\/#listItem","name":"General"}}]},{"@type":"Organization","@id":"https:\/\/multimedia.cx\/eggs\/#organization","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","url":"https:\/\/multimedia.cx\/eggs\/"},{"@type":"Person","@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author","url":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/","name":"Multimedia Mike","image":{"@type":"ImageObject","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Multimedia Mike"}},{"@type":"WebPage","@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#webpage","url":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/","name":"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes","description":"Writing a software oscilloscope doesn't seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/#website"},"breadcrumb":{"@id":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/#breadcrumblist"},"author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"creator":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"datePublished":"2012-04-28T22:01:32-07:00","dateModified":"2012-04-28T22:01:32-07:00"},{"@type":"WebSite","@id":"https:\/\/multimedia.cx\/eggs\/#website","url":"https:\/\/multimedia.cx\/eggs\/","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","inLanguage":"en-US","publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"}}]},"og:locale":"en_US","og:site_name":"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering","og:type":"article","og:title":"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes","og:description":"Writing a software oscilloscope doesn't seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it","og:url":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/","article:published_time":"2012-04-29T05:01:32+00:00","article:modified_time":"2012-04-29T05:01:32+00:00","twitter:card":"summary","twitter:title":"How To Write An Oscilloscope | Breaking Eggs And Making Omelettes","twitter:description":"Writing a software oscilloscope doesn't seem like it would be so hard-- just graphing audio amplitude with respect to time; but there might be more to it"},"aioseo_meta_data":{"post_id":"3809","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-31 21:44:34","updated":"2025-12-31 19:42:48","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\/category\/general\/\" title=\"General\">General<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow To Write An Oscilloscope\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/multimedia.cx\/eggs\/"},{"label":"General","link":"https:\/\/multimedia.cx\/eggs\/category\/general\/"},{"label":"How To Write An Oscilloscope","link":"https:\/\/multimedia.cx\/eggs\/how-to-write-an-oscilloscope\/"}],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/3809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=3809"}],"version-history":[{"count":5,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/3809\/revisions"}],"predecessor-version":[{"id":3815,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/3809\/revisions\/3815"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=3809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=3809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=3809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}