{"id":36,"date":"2021-11-05T02:36:54","date_gmt":"2021-11-05T02:36:54","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/mccludav\/?p=36"},"modified":"2021-11-05T02:36:54","modified_gmt":"2021-11-05T02:36:54","slug":"audio-loop-station-4th-entry","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/mccludav\/2021\/11\/05\/audio-loop-station-4th-entry\/","title":{"rendered":"Audio Loop Station, 4th Entry"},"content":{"rendered":"\n<p>This last week I created a C++ class, <strong>WavFile<\/strong>, that has a function called <strong>reverse<\/strong>.\u00a0 The <strong>reverse<\/strong> function takes a stereo or mono WAV file and creates a new WAV file that plays the input file backwards.\u00a0 This task has given me a comfort level with C++ classes that I never had in CS-162.\u00a0 To my surprise it was smooth coding.\u00a0 It took me all weekend, but I got it to work properly.\u00a0 My ultimate test was taking a file, reversing it, then reversing it again to restore the original.  I play the audio files, and view them graphically in Audacity.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"600\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-1.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-1.png 908w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-1-300x198.png 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-1-768x507.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><figcaption>main() was simplified through creation of the WavFile class.<\/figcaption><\/figure>\n\n\n\n<p>Previously I took a <strong>main<\/strong> function that had ~98% of my code \u2013 all of the code except <strong>includes<\/strong> and transformed it into a class that contains ~98% of the code.&nbsp; The <strong>main<\/strong> is now very short as shown in the picture above.<\/p>\n\n\n\n<p>Now my focus is getting a Fast Fourier Transform to work.&nbsp; In order to get this done, the first thing I will do is write out the audio data points of each channel to an ASCII column file.&nbsp; This means I take binary data and have to convert it to ASCII numbers, 1 per line, in either hex or decimal format.&nbsp; This will make reading in the column data as a complex number array much more straight forward and easy to verify.<\/p>\n\n\n\n<p>One problem that I have had to deal with when extracting WAV data is that many of the header parameters, and data, is in little endian mode.\u00a0 It has been fun reading a byte, or char, at a time and shifting its value to the proper magnitude.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"399\" height=\"153\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-2.png\" alt=\"\" class=\"wp-image-38\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-2.png 399w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-2-300x115.png 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><figcaption>Little endian format of a binary file 32-bit number.<\/figcaption><\/figure>\n\n\n\n<p>We read only a character at a time in the binary file.\u00a0 We have to convert a <strong>char <\/strong>into an <strong>int <\/strong>\u2013 in this case <strong><em>unsigned <\/em><\/strong>as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"437\" height=\"186\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-3.png\" alt=\"\" class=\"wp-image-39\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-3.png 437w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4756\/files\/2021\/11\/Blog-6-Pic-3-300x128.png 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><figcaption>Extracting the value of a little endian 32-bit number from 4 <strong>char<\/strong>s.<\/figcaption><\/figure>\n\n\n\n<p>This assignment has definitely improved my programming skills.\u00a0 I do not think I will be disappointed with the final outcome.\u00a0 The journey itself is rewarding.<\/p>\n\n\n\n<p>I have also realized that when dealing with WAV files, I want to use uncompressed files.\u00a0 This means that the <strong>Compression Code<\/strong> should be 1.\u00a0 Previously I dealt with a WAV file having a <strong>Compression Code<\/strong> of 6.\u00a0 The Audacity app can convert a WAV file to uncompressed.\u00a0 I will use 16-bit <strong><em>signed <\/em><\/strong>data for FFT analysis.<\/p>\n\n\n\n<p>This is where I am at.&nbsp; If I can successfully complete FFT and inverse FFT work within the next week, our group should have plenty of time to integrate our work into a single Audio Loop Station.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This last week I created a C++ class, WavFile, that has a function called reverse.\u00a0 The reverse function takes a stereo or mono WAV file and creates a new WAV file that plays the input file backwards.\u00a0 This task has given me a comfort level with C++ classes that I never had in CS-162.\u00a0 To&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/mccludav\/2021\/11\/05\/audio-loop-station-4th-entry\/\">Continue reading <span class=\"screen-reader-text\">Audio Loop Station, 4th Entry<\/span><\/a><\/p>\n","protected":false},"author":11630,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/users\/11630"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":40,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/posts\/36\/revisions\/40"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/mccludav\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}