
{"id":478,"date":"2009-02-18T09:00:24","date_gmt":"2009-02-18T08:00:24","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/?p=478"},"modified":"2009-04-26T03:16:57","modified_gmt":"2009-04-26T02:16:57","slug":"loop-mp3-in-flash","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2009\/02\/18\/loop-mp3-in-flash\/","title":{"rendered":"Loop mp3 in Flash"},"content":{"rendered":"<p>Oke, here come my problem. I&#8217;m trying to create a sound looping engine in Flash, and because I don&#8217;t want files to be embedded in the FLA (in the library) I only can use MP3 as a sound file which I can load dynamically. <\/p>\n<p>I didn&#8217;t know this, but mp3 has a silence at the end of the song, and sometimes also at the beginning of the song (and sometimes both).<br \/>\nOther file, files without compression like WAV, don&#8217;t have this problem.<\/p>\n<p>I don&#8217;t want to get to deep into this problem, but if you&#8217;re interested in the problem and you need to read more about it: about gapless playback: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Gapless_playback\">Gapless playback<\/a> and <a href=\"http:\/\/lame.sourceforge.net\/tech-FAQ.txt\">LAME tech FAQ<\/a>.<\/p>\n<p>I remember from AS2 the looping problem, but I hoped it was fixed in AS3.<br \/>\nSo this is what I tried to do:<\/p>\n<p>A colleague of mine (<a href=\"http:\/\/profile.myspace.com\/index.cfm?fuseaction=user.viewprofile&#038;friendid=300449619\">Boy Wonder<\/a>) gave me a beat so I could go to work.<\/p>\n<h3>#1 &#8211; First try<\/h3>\n<p>First convert the beat from WAV to MP3: I used <a href=\"http:\/\/audacity.sourceforge.net\/\">Audacity<\/a>, an open source software for recording and editing sound.<\/p>\n<p>Oke, the only thing I needed is to load the file (because it&#8217;s a local test, there is no loading) and hear if it worked:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ AS3\r\nprivate var url:String = \"MySound.mp3\";\r\nprivate var song:SoundChannel;\r\nvar request:URLRequest = new URLRequest(url);\r\nvar soundFactory:Sound = new Sound();\r\nsoundFactory.load(request);\r\nsong = soundFactory.play(0, int.MAX_VALUE); \r\n<\/pre>\n<p><strong>No, it didn&#8217;t loop correctly<\/strong><\/p>\n<h3>#2 &#8211; Second try<\/h3>\n<p>Open the newly generated MP3, and there they are: the silence at the beginning and at the end of the song. I could use Audacity to remove it, but I use another program for that: <a href=\"http:\/\/www.mptrim.com\/\">mptrim<\/a>. <\/p>\n<blockquote><p>mpTrim is a simple and easy to use MP3 editor.<\/p>\n<ul>\n<li>mpTrim can trim MP3s &#8211; removing silent or unwanted parts.<\/li>\n<li>mpTrim can adjust the volume of MP3s. Volume change can be manual or automatic (volume normalization).<\/li>\n<li>mpTrim can fade-in\/out MP3s (to fix abrupt beginning\/ending).<\/li>\n<li>mpTrim can clean-up MP3s and recover wasted disk space.<\/li>\n<li>mpTrim keeps the music quality intact, no matter how many times you process an MP3, because it works directly in the MP3 format without having to decode\/re-encode. That also makes it very fast.<\/li>\n<\/ul>\n<\/blockquote>\n<p>mpTrim has an auto function for removing silent, so that&#8217;s very easy.<\/p>\n<p>But after loading the new mp3 without silence, the hiccup was much smaller, but still there.<\/p>\n<h3>#3 &#8211; Third try (neeeh forget it)<\/h3>\n<p>The last try would be to fix it in code: I was thinking about a earlier starting a loop (0.02 second) but with a lot of tracks this would probably be very cpu intensive.<br \/>\nA quick search on the Internet, I couldn&#8217;t find a solution in code. It&#8217;s a bug in Flash and people that are more into sound then I am, are working hard to move Adobe to change some of the sound features in Flash: <a href=\"http:\/\/www.make-some-noise.info\/\">http:\/\/www.make-some-noise.info\/<\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>Because I have a hard head, and I need to make the same mistakes everyone makes&#8230;.<br \/>\nBut after all I have to conclude: It <strong>can&#8217;t<\/strong> be done, you will eventually get a hiccup in the loop.<br \/>\nIt&#8217;s impossible to fix this problem.<\/p>\n<p>So a dynamically loaded MP3 loops in flash will never work. The only way to get good loops is with WAV imported in the FLA (library) and use linkage<\/p>\n<p>\ud83d\ude41<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oke, here come my problem. I&#8217;m trying to create a sound looping engine in Flash, and because I don&#8217;t want files to be embedded in the FLA (in the library) I only can use MP3 as a sound file which I can load dynamically. I didn&#8217;t know this, but mp3 has a silence at the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,3],"tags":[39,408,189,398,191,190,42,188],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-as3","category-flash","tag-as2","tag-as3","tag-audacity","tag-flash","tag-gapless-playback","tag-mptrim","tag-open-source","tag-open-source-software"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":10,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":944,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions\/944"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}