<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[ChipMusic.org - mod sample ripper for ripping samples from mods]]></title>
	<link rel="self" href="https://chipmusic.org:80/forums/feed/atom/topic/12241/"/>
	<updated>2013-09-18T15:26:44Z</updated>
	<generator>PunBB</generator>
	<id>https://chipmusic.org/forums/topic/12241/mod-sample-ripper-for-ripping-samples-from-mods/</id>
		<entry>
			<title type="html"><![CDATA[Re: mod sample ripper for ripping samples from mods]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/184670/#p184670"/>
			<content type="html"><![CDATA[<p>fuckings to all rippers</p>]]></content>
			<author>
				<name><![CDATA[breakfastsquid]]></name>
				<uri>https://chipmusic.org/breakfastsquid</uri>
			</author>
			<updated>2013-09-18T15:26:44Z</updated>
			<id>https://chipmusic.org/forums/post/184670/#p184670</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[mod sample ripper for ripping samples from mods]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/184658/#p184658"/>
			<content type="html"><![CDATA[<p>rippers die!!!</p><div class="spoilerbox" id="spoiler3536957"><h3 onclick="$('#spoilerbox3536957').css('display','block');$('#spoiler3536957').css('display','none')">&#8250; Show Spoiler</h3></div><div class="spoilerbox" id="spoilerbox3536957" style="display:none"><h3 onclick="$('#spoilerbox3536957').css('display','none');$('#spoiler3536957').css('display','block')">&#8249; Hide Spoiler</h3><div class="codebox"><pre><code>#!/usr/bin/tclsh

# rip all samples from all .mods in the current directory
# to wav files numbered 0001.wav onwards
# should handle both 15-instrument and 31-instrument mods
# but i&#039;m not really sure
# needs sox (and tcl obviously) installed

# the various documents about mod formats on ftp.modland.com/pub/documents/format_documentation were very helpful
# the format is not really very complex
set samplenumber 0
file mkdir &quot;ripped-wavs&quot;
foreach filename [glob *.mod] {
    set fh [open $filename r]
    fconfigure $fh -translation binary
    set samples [list]
    set modname [read $fh 20]
    puts $modname

    # 31-instrument mods are marked with an identifier
    # in a 15-instrument mod this position will be in the middle of the mod data
    # so it&#039;s unlikely to match one of these identifiers
    seek $fh [expr (30 * 31) + 130] current
    set format [read $fh 4]
    set bigformats [list &quot;M.K.&quot; &quot;M!K!&quot; &quot;FLT4&quot; &quot;FLT8&quot; &quot;4CHN&quot; &quot;6CHN&quot; &quot;8CHN&quot;]
    set instruments 15
    if { [lsearch $bigformats $format] &gt; -1 } {
        set instruments 31
    }
    seek $fh 20

    # collect sample lengths
    for {set i 0} {$i &lt; $instruments} {incr i} {
        set name [read $fh 22]
        binary scan [read $fh 2] Su1 length
        lappend samples [expr $length * 2]
        seek $fh 6 current
    }

    seek $fh 2 current

    # find highest pattern
    set maxpattern 0
    for {set i 0} {$i &lt; 128} {incr i} {
        binary scan [read $fh 1] cu pattern
        if {$pattern &gt; $maxpattern} {
            set maxpattern $pattern
        }
    }

    seek $fh 4 current
    set maxpattern [expr $maxpattern + 1]

    # a normal 4 channel pattern is 1024 bytes
    set patternsize 1024
    # maybe some formats aren&#039;t? i don&#039;t know
    if [string equal $format &quot;FLT8&quot;] {
        # set patternsize 2048
        # i dont think this is how it works
        # one of the 8 channel formats just plays
        # pattern 0 and pattern 1 at the same time
        # etc
        # to make it compatible with protracker
        # not sure which though
        # or if both?
    } elseif [string equal $format &quot;8CHN&quot;] {
        # set patternsize 2048
        # see above
    } elseif [string equal $format &quot;6CHN&quot;] {
        set patternsize 1536
        # gonna assume this is how 6chn works
        # dont really have a clue though
    }

    # jump to end of pattern data
    seek $fh [expr $maxpattern * $patternsize] current

    # rip samples
    for {set i 0} {$i &lt; $instruments} {incr i} {
        set length [lindex $samples $i]
        if {$length &gt; 2} {
            incr samplenumber
            set sfh [open [format &quot;ripped-wavs/%05d.s8&quot; $samplenumber] w]
            fconfigure $sfh -translation binary
            fcopy $fh $sfh -size $length
            close $sfh
        } else {
            seek $fh $length current
        }
    }

    close $fh
}

# convert to wav with sox
foreach filename [glob &quot;ripped-wavs/*.s8&quot;] {
    set outfilename $filename
    regsub {\.s8$} $outfilename &quot;.wav&quot; outfilename
    exec sox -r8363 -c1 $filename $outfilename
    file delete $filename
}</code></pre></div></div><p>get all the .wav files from the .mod files<br />ignore this thread if you dont like it!</p>]]></content>
			<author>
				<name><![CDATA[sandneil]]></name>
				<uri>https://chipmusic.org/sandneil</uri>
			</author>
			<updated>2013-09-18T14:01:49Z</updated>
			<id>https://chipmusic.org/forums/post/184658/#p184658</id>
		</entry>
</feed>
