{"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":[],"_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}]}}