<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by André Gil on Medium]]></title>
        <description><![CDATA[Stories by André Gil on Medium]]></description>
        <link>https://medium.com/@andre-gil?source=rss-53e30bce026f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*XwBrGFmXWddYl0F1bJo3cg.png</url>
            <title>Stories by André Gil on Medium</title>
            <link>https://medium.com/@andre-gil?source=rss-53e30bce026f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 20:14:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andre-gil/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 Things to know before starting scripting in Bash Shell]]></title>
            <link>https://andre-gil.medium.com/5-things-to-know-before-starting-scripting-in-bash-shell-c81ed695dfe5?source=rss-53e30bce026f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c81ed695dfe5</guid>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[bash-shell]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[André Gil]]></dc:creator>
            <pubDate>Mon, 04 Jan 2021 21:09:02 GMT</pubDate>
            <atom:updated>2021-01-04T21:09:02.860Z</atom:updated>
            <content:encoded><![CDATA[<p>Don’t make the same mistakes than me!</p><p><strong>Note</strong>: this story is for developers that are used to high-level languages, like C, C#, Javascript or Python, and are new to Bash Shell scripts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrwwXakDPQ34hl1Rp5chZA.png" /></figure><h3>#1 Command Lifecycle</h3><p>When a command is given to the shell, the interpreter does the following main steps:</p><ol><li><em>Variable substitution</em> — replaces all variables with their values</li><li><em>Line parsing</em> — the interpreter re-scans again the line and trims additional spaces between arguments+ parses special chars</li><li><em>Command execution </em>— Executes given command</li></ol><p>For an example, what you think it would be the output of the script bellow?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8793721153113edbedd2192c876a628/href">https://medium.com/media/e8793721153113edbedd2192c876a628/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*CES8j3sNpdL7dyLo7luTCg.png" /><figcaption>Output from lifecycle.sh script</figcaption></figure><p>Let’s have a look why:</p><ol><li>First the shell replaces the <em>$ahah</em> variable with it’s initial value</li><li>Then, it re-scans the line and because the value of <em>$ahah</em> is not quoted, it trims all the additional spaces (resulting in “<strong>Several spaces *</strong>”) and finally it parses the special char “<em>*</em>”, that in this case, lists all the files of the current directory, separated by a space</li><li>Finally <em>echo </em>is executed with the following arguments: “<em>Several</em>”, “<em>spaces</em>”, “<em>lifecycle.sh</em>” and “<em>phones.txt</em>”</li></ol><h3>#2 Every variable is a string!</h3><p>In Bash every variable is treated as a string! That’s why the following script outputs “<strong>Not Equal</strong>”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9002bab72c8510f944bb33f4da9d890/href">https://medium.com/media/a9002bab72c8510f944bb33f4da9d890/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*EWVYfXXUZoII0jQafayM3w.png" /></figure><p>To compare two integers we have to use specific options like <em>-eq</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94f3ff4f0a736ef8e5f6629b51dc8bcc/href">https://medium.com/media/94f3ff4f0a736ef8e5f6629b51dc8bcc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*7LBn_JLbs5FaRnfncTSiQA.png" /></figure><p>PS: For integer operations, such as addition, subtraction, multiplication or division you should use <em>expr</em> or <em>$(())</em></p><h3>#3 [ is a command</h3><p>A funny fact about the Bash is that <strong>[</strong> is an actual command. Test this out:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0d5f13965fcc460299672c10b5b818e/href">https://medium.com/media/c0d5f13965fcc460299672c10b5b818e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*f5F723K9FzjOnl818VTcuQ.png" /></figure><p>The <strong>[ </strong>command is basically the <strong>test</strong> command but it also requires a closing tag <strong>]</strong>.</p><p><strong>Note</strong>: That’s why spaces between the <strong>[ </strong>and<strong> ] </strong>are so important, because they separate the command arguments! Otherwise the <strong>[ </strong>command will not properly recognise its arguments</p><h3>#4 Don’t loop over $*</h3><p>Looping over <em>$* </em>almost always means bug! Check what happens when the argument given has spaces (second run):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5547f5762a7e830750c3b66b79aef57/href">https://medium.com/media/e5547f5762a7e830750c3b66b79aef57/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*-MP5tT8smWFmpzuAKliu3g.png" /></figure><p>And this is not solved by adding double quotes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0eb984dcec2272667ebd763ce54c701/href">https://medium.com/media/c0eb984dcec2272667ebd763ce54c701/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*DRdoVq-PvFWlp-w5-nnL8A.png" /></figure><p>What we commonly expected is to loop over <em>“$@” </em>(<strong>double quotes included</strong>), like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d868c02e5e49dae416ea8ccd7f07031/href">https://medium.com/media/6d868c02e5e49dae416ea8ccd7f07031/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*R_EbR9A6_owOBzX_0P9N4Q.png" /></figure><h3>#5 Use -x option for debugging</h3><p>We all know that traditional <em>echo</em> commands can be handy for debugging, but most of the times the <em>-x </em>option can make things easier! Take a look of what happens when we enable this option:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abc1d79c60b72c10722c40ed087d3d03/href">https://medium.com/media/abc1d79c60b72c10722c40ed087d3d03/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*IkNvzrZs3XwYWPeU8iHggg.png" /></figure><p>For more about the Bash Shell you could read the book <em>Shell Programming in Unix, Linux and OS X</em> from Stephen G. Kochan and Patrick Wood</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c81ed695dfe5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing a game in Assembly without having a clue…]]></title>
            <link>https://andre-gil.medium.com/developing-a-game-in-assembly-without-having-a-clue-31732da4615f?source=rss-53e30bce026f------2</link>
            <guid isPermaLink="false">https://medium.com/p/31732da4615f</guid>
            <category><![CDATA[divide-and-conquer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[fast-learning]]></category>
            <category><![CDATA[assembly-language]]></category>
            <dc:creator><![CDATA[André Gil]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 17:12:38 GMT</pubDate>
            <atom:updated>2020-03-28T19:51:38.431Z</atom:updated>
            <content:encoded><![CDATA[<p>Nowadays, programming languages like Python and Java makes the life of Software Developers much easier.</p><p>These high-level languages abstract you from memory management (that is actually one of the most common problems regarding low-level languages) as well as, reducing the amount of work needed to achieve a given goal.</p><p>However, I believe that sometimes its good to invest some time in low-level languages, like Assembly, to have a better insight into how those high-level languages work.</p><h3>The game</h3><p>The game that I decided to implement was the Snake. As a kid, I used to play the Snake quite a lot. Never been an Ace player but it was fine. At least, I had fun playing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*zptROt-SJg7GBsQ7NRJ7iw.png" /><figcaption>The Snake game</figcaption></figure><p>This game would be composed of three main screens: 1) loading screen, 2) game screen and finally 3) a game over screen.</p><p>I know that it’s super simple, but that was the purpose! Don’t forget that we are implementing a game in Assembly, not in Unity or Unreal Engine…</p><h4>External C libraries</h4><p>Even though the main game logic is implemented in Assembly I decided to use some external libraries, to reduce the amount of work:</p><ul><li><a href="https://www.libsdl.org/">Simple DirectMedia Layer 2 (SDL2)</a> -&gt; For graphics.</li><li><a href="https://www.libsdl.org/projects/SDL_ttf/">SDL_ttf 2.0</a> — For text rendering.</li><li><a href="https://github.com/jakebesworth/Simple-SDL2-Audio">Simple-SDL2-Audio</a> — For playing sounds.</li></ul><h3>Let’s get started</h3><p>As a developer, one thing that we need to be good at is: at <strong>debugging code</strong>. Sometimes we use debuggers, other times we comment parts of the code and the majority of the times we just add console logs… No worries, even though that debuggers are cool and awesome, being able to find the tricky bug with only console logs it’s much more gratifying.</p><p>The point here is that if you take advantage of that skill, you can build stuff faster in less time. Thus, my first step was to actually build the game — or at least the main parts of it — in C using the SDL library. Like that, not only I learnt about the framework itself (because honestly I didn’t had a clue about it) as well as, I could inspect the generated Assembly file.</p><p>However, in the end, I realised that I learnt a lot about the framework itself, but the generated Assembly code was quite hard to follow (too many instructions to follow).</p><h4>Divide-and-conquer</h4><p>The <em>divide-and-conquer </em>approach is one of my favourite ways of solving a complex problem. It’s such a simple approach and it just (usually) works!</p><p>The idea, is to divide a complex problem into several sub-problems, and then, solve each problem individually. Thus, what I did was:</p><ul><li>Implement a small step in C (even if it doesn’t really run).</li><li>Compile it.</li><li>Inspect the generated Assembly file.</li><li>Repeat process until implementing the game.</li></ul><h4>The end result</h4><p>Well, in the end, this was the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ceZD58rza-t3lHb0OqnN-w.png" /><figcaption>The image in the left represents the loading screen, the middle one, the game screen and the right one the game over screen.</figcaption></figure><blockquote>Not only I learnt about Assembly programming language but how C works under the hood — tricks and standards like registers used for passing function parameters.</blockquote><p>Hope you enjoyed the story. Stay well, stay safe and keep coding!</p><p>PS: You may find the source code in: <a href="https://bitbucket.org/matapatos/snake_assembly/src/master/">https://bitbucket.org/matapatos/snake_assembly/src/master/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31732da4615f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving a music transcription system using post-processing techniques]]></title>
            <link>https://andre-gil.medium.com/improving-a-music-transcription-system-using-post-processing-techniques-453cb0fd6d8?source=rss-53e30bce026f------2</link>
            <guid isPermaLink="false">https://medium.com/p/453cb0fd6d8</guid>
            <category><![CDATA[music-transcription]]></category>
            <category><![CDATA[multi-pitch]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[post-processing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[André Gil]]></dc:creator>
            <pubDate>Thu, 02 May 2019 14:54:50 GMT</pubDate>
            <atom:updated>2019-05-06T12:34:48.589Z</atom:updated>
            <content:encoded><![CDATA[<p>This story describes several types of post-processing techniques that can be useful to improve a music transcription system. These techniques were originally proposed from <a href="https://bitbucket.org/matapatos/mei-cm_ml_pitchdetection/raw/c1064fde20d5b4df9d01360f217b45b3e53c1788/Dissertation.pdf">[1]</a> by Gil, Grilo, Reis and Domingues.</p><p>For those who are already familiar with the automatic music transcription field you can skip the <em>Background</em> section.</p><h3><strong>Background</strong></h3><p>Automatic music transcription (AMT) consists on the process of detecting the notes being played in a musical piece via a machine. This problem comprises several fields of research like digital processing methods, music theory and many more. Thus, a suitable solution is harder to find.</p><p>In this work, we mainly focus in a sub-problem called <strong>multi-pitch estimation</strong>. In general, multi-pitch estimation consists in transcribing a polyphonic<strong> </strong>musical piece by splitting it into small chunks, technically referred as <em>frames</em>, and then, transcribe each frame, individually. In the end, the set of estimated/transcribed frames represents the resultant transcription (piano roll).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*We6vu4Fa8PmboMAa8vBE4Q.png" /><figcaption>A common approach to multi-pitch estimation. a) Splitting a musical piece into individual frames. b) Estimate the pitch in each frame.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOwmA-_Ou_N_sXM4L7V45Q.png" /><figcaption>Piano roll representation. a) Splitting musical piece into frames. b) Conversion of estimated frames to piano roll.</figcaption></figure><h3>Post-processing techniques</h3><p>After the transcription process, errors are common. We mean that, notes predicted as being in a frame are not actually present, and notes that are present in a frame are not correctly identified.</p><p>To attenuate those errors, post-processing techniques can be applied. However, most of those post-processing techniques are statistically-based methods, like Hidden Markov Models <a href="https://arxiv.org/pdf/1508.01774.pdf">[2</a><a href="https://pdfs.semanticscholar.org/e151/83d841463774b2ea95069706d10b083ab46f.pdf">, 3]</a>. I am not against to statistical methods but, I believe that in most scenarios, artificial methods like Artificial Neural Networks (ANNs), can perform much better than those ones. As a result, we experimented three different approaches using ANNs: i) <em>fix notes duration — </em>step 1, ii) <em>fix notes duration according to onsets</em> — step 2 and iii) <em>fix onsets — </em>step 3.</p><h4><strong>Fix notes duration</strong></h4><p>One of the aims of a post-processing technique is to smooth the resultant transcription, using previous states. In this case, using previously transcribed frames. This is good scenario but because we do not need a real time transcription we have adopted a slightly different approach where, not only the previous transcribed frames were considered but also the following ones.</p><p>We can think of this post-processing technique as a slidding window that tries to predict the actual transcription for the frame in the middle of the sequence contained in it (see figure bellow).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*oitwhx5STHlOKw2bP9PeCA.png" /><figcaption>Representation of how the fix notes duration post-processing unit works. The 1’s represent a frame that was identified with a specific musical note and the 0’s the opposite scenario. The <strong>blue number</strong> represent the frame that the post-processing unit will try to predict the actual transcription and the <strong>green number</strong> the predicted transcription for it. The <strong>orange window</strong> represent the sequence given to the unit. Note that this window will slide one frame at a time to the right side, until the end.</figcaption></figure><p>This type of post-processing technique have significantly improved our transcription results from 66.89% up to 79.78% on <em>frame-based</em> metrics and our <em>onset only</em> from 33.08% up to 51.61%. For those who are not familiar with these metrics, the <em>frame-based</em> metrics illustrates how much of those frames are correctly transcribed and, the <em>onset only </em>represents, from all those set of transcribed frames, the musical notes that were correctly transcribed with a precised starting time within a tolerance of 50 miliseconds.</p><h4><strong>Fix notes duration according to onsets</strong></h4><p>For further improvement, an additional post-processing technique similar to the previous one was created. This one receives as input, not only a sequence of previouslly transcribed frames (<em>fix notes duration</em> — step 1) but also a sequence with the initial transcription and the output of an onset algorithm <a href="https://repositorio-aberto.up.pt/bitstream/10216/58570/1/000129328.pdf">[4]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*TGdtNBs6Sr0-7gheVK6_kg.png" /></figure><p>This additional post-processing technique have improved our <em>frame-based</em> results from 79.78% up to 80.23% and our <em>onset only</em> metrics from 51.61% up to 55.97%.</p><h4><strong>Fix onsets</strong></h4><p>After an analyse of the current transcription, we noticed that several note onsets, were missed by only one frame of difference. For instance, if an onset have happen in the fifth frame of a musical piece, its identification was only in the fourth or sixth frame.</p><p>Thus, we proposed an additional post-processing technique to tackle this problem, where it will predict if a readjustment of an onset was needed, and, if yes, which way shoud be shifted: 1) <em>SHIFT LEFT</em> or 2) <em>SHIFT RIGHT</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*oFLvZhofFOzU0FtdMZDscA.png" /><figcaption>Representation of the three possible transformations regarding fix note onsets post-processing unit. Note that the numbers in red represent incorrect transcriptions and the ones in green fixed transcriptions. a) Prediction to shift the note onset to the left. b) Prediction where no readjustment is needed. c) Prediction to shifht the note onset to the right.</figcaption></figure><p>This last one, was able to improve our <em>frame-based</em> results from 80.23% up to 80.47% and our <em>onset only</em> metrics from 55.97% up to 61.64%.</p><h3>Audible versions</h3><p>To have a better perception of the improvements gained through the steps of the post-processing stage, an audible version of the musical piece <em>BMW 846 Prelude in C Major</em> from J. S. Bach can be listened in the following links.</p><p><strong>Expected version:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F602415207%26show_artwork%3Dtrue&amp;url=https%3A%2F%2Fsoundcloud.com%2Fandre-gil-736654230%2Fbach-846-prelude-c-major-expected-version&amp;image=http%3A%2F%2Fa1.sndcdn.com%2Fimages%2Ffb_placeholder.png%3F1554458816&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e6b02a4a408455c884723558926302c/href">https://medium.com/media/0e6b02a4a408455c884723558926302c/href</a></iframe><p><strong>Initial version</strong> — Before any post-processing technique being applied:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F602415216%26show_artwork%3Dtrue&amp;url=https%3A%2F%2Fsoundcloud.com%2Fandre-gil-736654230%2Fbach-846-prelude-c-major-initial-version&amp;image=http%3A%2F%2Fa1.sndcdn.com%2Fimages%2Ffb_placeholder.png%3F1554458816&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/110b399c1cfae8926b69484243f302f7/href">https://medium.com/media/110b399c1cfae8926b69484243f302f7/href</a></iframe><p><strong>Final version</strong> — After all the post-processing techniques:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F602415237%26show_artwork%3Dtrue&amp;url=https%3A%2F%2Fsoundcloud.com%2Fandre-gil-736654230%2Fbach-846-prelude-c-major-final-version&amp;image=http%3A%2F%2Fa1.sndcdn.com%2Fimages%2Ffb_placeholder.png%3F1554458816&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/68e3a366a8f2b31ddda98aa4d57307d8/href">https://medium.com/media/68e3a366a8f2b31ddda98aa4d57307d8/href</a></iframe><h3>Summary</h3><p>As it is possible to notice, these post-processing techniques were fundamental to improve the efficiency of the transcription system. Our <em>frame-based</em> results have improved from 66.89% up to 80.47% and the <em>onset only</em> from 33.08% up to 61.64%.</p><p>A relevant point here is that the last two types of post-processing steps are dependent to the performance of the onset algorithm used, and thus, if a better onset algorithm is applied the end results would be positively impacted (a demonstration can be viewed in section 6.5 from <a href="https://bitbucket.org/matapatos/mei-cm_ml_pitchdetection/raw/c1064fde20d5b4df9d01360f217b45b3e53c1788/Dissertation.pdf">[1]</a>).</p><p><strong>Source code: </strong><a href="https://bitbucket.org/matapatos/mei-cm_ml_pitchdetection/src/master/">https://bitbucket.org/matapatos/mei-cm_ml_pitchdetection/src/master/</a></p><h3>References</h3><p>[1] — Gil, Grilo, Reis, &amp; Domingues. (2019). Automatic Transcription of Music using Deep Learning Techniques.</p><p>[2] — Sigtia, S., Benetos, E., &amp; Dixon, S. (2016). An end-to-end neural network for polyphonic piano music transcription. <em>IEEE/ACM Transactions on Audio, Speech, and Language Processing</em>, <em>24</em>(5), 927–939.</p><p>[3] — Zalani, A., &amp; Mittal, A. (2014). Polyphonic Music Transcription A Deep Learning Approach.</p><p>[4] — Martins, L. G. P. M. (2008). A computational framework for sound segregation in music signals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=453cb0fd6d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>