Touhou Wiki
Advertisement



*Return to BGM



<?php

$sample_size = 4; // 16-bit stereo

$files = scandir('.');

foreach( $files as $file )
{
	if( 0 == preg_match('/^(.*?)\.ogg$/i', $file, $match) )
		continue;
	$name = $match[1];

	if( name2title($name) == null )
		continue;

	// decode ogg file
	exec("oggdec.exe $name.ogg");

	// retrieve loop information
	$sfl = @fopen($name.'.sfl', 'r');
	if( $sfl )
	{
		fseek($sfl, 28, SEEK_SET);
		$start = 0x2C + $sample_size * b32_ul(fread($sfl, 4));

		fseek($sfl, 72, SEEK_SET);
		$length = $sample_size * b32_ul(fread($sfl, 4));

		// write titles file
		$fp = fopen("titles.txt", "w");
		fprintf($fp, "0000002C,%08X,%08X,%s\n", $start, $length, $name);
		fclose($fp);

		// process wav file
		exec("thbgmtowav.exe -l titles.txt $name.wav");

		// rename output
		rename("thbgm_01.wav", name2title($name).".wav");

		unlink("$name.wav");
	}
	else
	{// no sfl file, just copy
		rename("$name.wav", name2title($name).".wav");
	}
}

function b32_ul($tt)
{
   $nn = 0;
   for($i = 0; $i < 4; $i++){
      $nn += (int)(pow(256, $i)) * ord($tt[$i]);
   }
   return $nn;
}

function name2title($name)
{
	$titles = array (
	"op"   => "th105 - 01 - Evening Sky",
	"ta00" => "th105 - 02 - Usual Days",
	"st00" => "th105 - 03 - The Ground's Color is Yellow",
	"ta01" => "th105 - 04 - Argue for and Against",
	"ta03" => "th105 - 05 - Beautiful Nature Sight",
	"st01" => "th105 - 06 - Fragrant Plants",
	"st02" => "th105 - 07 - Dancing Water Spray",
	"ta05" => "th105 - 08 - Swing a Fish to Drive Away Flies",
	"ta08" => "th105 - 09 - Free and Easy",
	"st03" => "th105 - 10 - Ridiculous Game",
	"ta04" => "th105 - 11 - Drunk as I Like",
	"ta02" => "th105 - 12 - Skies Beyond the Clouds",
	"st04" => "th105 - 13 - Crimson in the Black Sea ~ Legendary Fish",
	"ta07" => "th105 - 14 - Flawless Clothing of the Celestials",
	"st05" => "th105 - 15 - Catastrophe in Bhava-agra ~ Wonderful Heaven",
	"st06" => "th105 - 16 - Bhava-agra As Seen Through a Child's Mind",
	"ta06" => "th105 - 17 - Darkening Dusk",
	"sr"   => "th105 - 18 - Oriental Evening Sky",
	"st10" => "th105 - 19 - Mystic Oriental Love Consultation",
	"st11" => "th105 - 20 - Vessel of Stars ~ Casket of Star",
	"st12" => "th105 - 21 - Flowering Night",
	"st13" => "th105 - 22 - The Doll Maker of Bucharest",
	"st14" => "th105 - 23 - Hiroari Shoots a Strange Bird ~ Till When_",
	"st15" => "th105 - 24 - Locked Girl ~ Girl's Secret Room",
	"st16" => "th105 - 25 - Bloom nobly, cherry blossoms of Sumizome ~ Border of Life",
	"st17" => "th105 - 26 - Septette for the Dead Princess",
	"st18" => "th105 - 27 - Night Falls ~ Evening Star",
	"st19" => "th105 - 28 - Broken Moon",
	"st20" => "th105 - 29 - Lunatic Eyes ~ Invisible Full Moon",
	"st21" => "th105 - 30 - Wind God Girl",
	"st22" => "th105 - 31 - Higan Retour ~ Riverside View",
	);
	return @$titles[$name];
}

?>



Advertisement