<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: matej</title>
    <description>The latest articles on DEV Community by matej (@matejsarlija).</description>
    <link>https://dev.to/matejsarlija</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F591117%2Fc94123f3-e1a6-4e5a-b250-72c90853705d.jpg</url>
      <title>DEV Community: matej</title>
      <link>https://dev.to/matejsarlija</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matejsarlija"/>
    <language>en</language>
    <item>
      <title>Remixing songs using Chat GPT-4 and the command line</title>
      <dc:creator>matej</dc:creator>
      <pubDate>Thu, 16 Mar 2023 15:16:24 +0000</pubDate>
      <link>https://dev.to/matejsarlija/remixing-songs-using-chat-gpt-4-sox-and-ffmpeg-1h19</link>
      <guid>https://dev.to/matejsarlija/remixing-songs-using-chat-gpt-4-sox-and-ffmpeg-1h19</guid>
      <description>&lt;p&gt;I've recently heard a song that I really liked, and I've thought about how I wanted the tempo to be a bit slower.&lt;/p&gt;

&lt;p&gt;We've all heard Youtube "slowed, reverbed, bass boosted" versions of popular radio songs.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Fe0HTUPAK_E"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;Just playing it at 0.9x at Youtube wasn't going to be enough!&lt;/p&gt;

&lt;p&gt;Since we just got GPT-4 available and it's all the rage, I've decided to go to it and prompt it for the tips.&lt;/p&gt;

&lt;p&gt;First prompt was pretty basic - &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Could I do a basic song (mp3) remix via ffmpeg


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;and the answer was more in the line of mixing different songs together, so I had to be a bit more direct.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

It's more in the line that I have extracted vocals from a song, and a separate track for the instrumental of the song and I want to slow the instrumental by some 12 %, add bass boost and slight reverb, and then merge that again with the vocals, is that possible with ffmpeg?


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;I got back the following -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv0w32y6ubtmmxv265auo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv0w32y6ubtmmxv265auo.png" alt="ffmpeg commands part I"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7e4e7zr3wr3jwhiem4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7e4e7zr3wr3jwhiem4s.png" alt="ffmpeg commands part II"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcanx3rj7becixt2tnaat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcanx3rj7becixt2tnaat.png" alt="ffmpeg commands part III"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But then my session crashed and I realized I forgot to copy actual commands :). &lt;/p&gt;

&lt;p&gt;After a bit of back and forth with OpenAI's GPT and "Sidney" via Edge chat - I got the following pipeline to make a decent result - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Slow it down&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ffmpeg -i input.mp3 -filter: a "atempo=0.89" slowed_input.mp3



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Add some boost to bass frequencies&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ffmpeg -i slowed_input.mp3 -af "equalizer=f=100:width_type=h:200:g=6" input_boosted.mp3


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Add reverb with &lt;code&gt;sox&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sox input_boosted.mp3 reverb_input.mp3 reverb 30 50 100 50 0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And this is the result&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/p5ul_CM5KLc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I've also prompted GPT for a statement that I own no copyright of the song for Youtube video description (legal purposes), in Croatian (!!) and it handled that pretty well.&lt;/p&gt;

&lt;p&gt;NOTES&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I had to use sox, because there is some mismatch between my Fedora version of ffmpeg and it's filters to add reverb&lt;/li&gt;
&lt;li&gt;As you'll notice I've ignored my first idead to split the track into vocals and instrumental, since that ended me up with a too big of a mismatch between vocals and the music track&lt;/li&gt;
&lt;li&gt;When applying bass boost, the effect is modulated with the last 'g' variable, sometimes more than 5 gives loud thumps one would have to further clean&lt;/li&gt;
&lt;li&gt;There is ample room to play with the reverb effect but I like this as it's quick and dirty&lt;/li&gt;
&lt;li&gt;At times Sidney straight up refuses to give you a direct ffmpeg or sox command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is another one in my line of experimenting building stuff with the tiny shoggoths that LLMs are.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6r5npgrlu18lmca330f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6r5npgrlu18lmca330f.png" alt="LLM as a shoggoth"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've been using it as a math tutor, CRUD coding buddy, and to automate generating recipes from Youtube cooking videos.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Leetcode grind - Remove duplicates from a sorted linked list</title>
      <dc:creator>matej</dc:creator>
      <pubDate>Sun, 21 Nov 2021 14:52:29 +0000</pubDate>
      <link>https://dev.to/matejsarlija/leetcode-grind-remove-duplicates-from-a-sorted-linked-list-21e2</link>
      <guid>https://dev.to/matejsarlija/leetcode-grind-remove-duplicates-from-a-sorted-linked-list-21e2</guid>
      <description>&lt;p&gt;This one is pretty simple if there is just one duplicate, but if there are multiple, using just one pointer won't work, because we need to skip multiple duplicates.&lt;/p&gt;

&lt;p&gt;Going on solution from z3r0gravity7 from here &lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list/discuss/1589369/Python3-intuitive-O(n)-solution-with-seeking-pointer-faster-than-98-(with-explanation)"&gt;https://leetcode.com/problems/remove-duplicates-from-sorted-list/discuss/1589369/Python3-intuitive-O(n)-solution-with-seeking-pointer-faster-than-98-(with-explanation)&lt;/a&gt; -&amp;gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def deleteDuplicates(self, head: Optional[ListNode]) -&amp;gt; Optional[ListNode]:
        if head == None or head.next == None: # handle edge cases where linked list has no or one nodes
            return head

        p = head # initialize current node pointer
        while p.next: # until we have reached the last node (where next pointer is None)
            seek = p.next # seek pointer is initialized to the node after current node (guaranteed to be not None by while loop condition)
            while p.val == seek.val: # while the seeking pointer points to a duplicate of the current node
                seek = seek.next # keep seeking
                if seek == None: # if the seeking pointer has reached the end of the LL
                    p.next = None # then all nodes after the current node are duplicates, can truncate the LL after the current node
                    return head

            # the seeking node is at the first non-duplicate node (may not have moved at all, if there were no duplicates)
            p.next = seek # skip over all duplicate nodes (if any) by forwarding the next pointer of the current node to the seeked to node
            p = p.next

        return head
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can make it a bit more readable using suggestions from Elements of Programming interviews, and then we get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    def deleteDuplicates(self, head: Optional[ListNode]) -&amp;gt; Optional[ListNode]:
        first = head

        while first:
            second = first.next
            while second and first.val == second.val:
                second = second.next
            # skip over all duplicate nodes
            first.next = second
            first = first.next

        return head
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the end it's kinda simple.&lt;/p&gt;

&lt;p&gt;As usual it's really best to just work out the whole thing on paper, code will just get in the way.&lt;/p&gt;

&lt;p&gt;I'm new to the grind, the hardest thing so far is to just stick to it.&lt;/p&gt;

</description>
      <category>python</category>
      <category>leetcode</category>
      <category>codinginterview</category>
    </item>
  </channel>
</rss>
