mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Write out .wav files instead of hardcoded binary format. Need to update the client to support this method.
This commit is contained in:
parent
5f61e3f02a
commit
843da643c4
@ -31,11 +31,9 @@ namespace Launcher {
|
|||||||
public void DownloadItems( AsyncDownloader downloader, Action<string> setStatus ) {
|
public void DownloadItems( AsyncDownloader downloader, Action<string> setStatus ) {
|
||||||
this.downloader = downloader;
|
this.downloader = downloader;
|
||||||
DownloadMusicFiles();
|
DownloadMusicFiles();
|
||||||
digPatcher = new SoundPatcher( digSounds, "dig_",
|
digPatcher = new SoundPatcher( digSounds, "dig_", "step_cloth1" );
|
||||||
"step_cloth1", digPath );
|
|
||||||
digPatcher.FetchFiles( digSoundsUri, altDigSoundsUri, this );
|
digPatcher.FetchFiles( digSoundsUri, altDigSoundsUri, this );
|
||||||
stepPatcher = new SoundPatcher( stepSounds, "step_",
|
stepPatcher = new SoundPatcher( stepSounds, "step_", "classic jar" );
|
||||||
"classic jar", stepPath );
|
|
||||||
stepPatcher.FetchFiles( stepSoundsUri, altStepSoundsUri, this );
|
stepPatcher.FetchFiles( stepSoundsUri, altStepSoundsUri, this );
|
||||||
if( !defaultZipExists ) {
|
if( !defaultZipExists ) {
|
||||||
downloader.DownloadData( jarClassicUri, false, "classic_jar" );
|
downloader.DownloadData( jarClassicUri, false, "classic_jar" );
|
||||||
|
@ -11,21 +11,16 @@ namespace Launcher {
|
|||||||
|
|
||||||
string[] files, identifiers;
|
string[] files, identifiers;
|
||||||
string prefix, nextAction;
|
string prefix, nextAction;
|
||||||
FileStream outData;
|
|
||||||
StreamWriter outText;
|
|
||||||
RawOut outDecoder;
|
|
||||||
public bool Done;
|
public bool Done;
|
||||||
|
|
||||||
public SoundPatcher( string[] files, string prefix,
|
public SoundPatcher( string[] files, string prefix, string nextAction ) {
|
||||||
string nextAction, string outputPath ) {
|
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.nextAction = nextAction;
|
this.nextAction = nextAction;
|
||||||
InitOutput( outputPath );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||||
public void FetchFiles( string baseUrl, string altBaseUrl, ResourceFetcher fetcher ) {
|
public void FetchFiles( string baseUrl, string altBaseUrl, ResourceFetcher fetcher ) {
|
||||||
identifiers = new string[files.Length];
|
identifiers = new string[files.Length];
|
||||||
for( int i = 0; i < files.Length; i++ )
|
for( int i = 0; i < files.Length; i++ )
|
||||||
identifiers[i] = prefix + files[i].Substring( 1 );
|
identifiers[i] = prefix + files[i].Substring( 1 );
|
||||||
@ -51,7 +46,6 @@ namespace Launcher {
|
|||||||
|
|
||||||
// TODO: setStatus( next );
|
// TODO: setStatus( next );
|
||||||
if( i == identifiers.Length - 1 ) {
|
if( i == identifiers.Length - 1 ) {
|
||||||
Dispose();
|
|
||||||
Done = true;
|
Done = true;
|
||||||
setStatus( fetcher.MakeNext( nextAction ) );
|
setStatus( fetcher.MakeNext( nextAction ) );
|
||||||
} else {
|
} else {
|
||||||
@ -63,35 +57,44 @@ namespace Launcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DecodeSound( string name, byte[] rawData ) {
|
void DecodeSound( string name, byte[] rawData ) {
|
||||||
long start = outData.Position;
|
string path = Path.Combine( Program.AppDirectory, "audio" );
|
||||||
using( MemoryStream ms = new MemoryStream( rawData ) ) {
|
path = Path.Combine( path, prefix + name + ".wav" );
|
||||||
OggContainer container = new OggContainer( ms );
|
|
||||||
outDecoder.PlayStreaming( container );
|
using( FileStream dst = File.Create( path ) )
|
||||||
|
using ( MemoryStream src = new MemoryStream( rawData ) )
|
||||||
|
{
|
||||||
|
dst.SetLength( 44 );
|
||||||
|
RawOut output = new RawOut( dst, true );
|
||||||
|
OggContainer container = new OggContainer( src );
|
||||||
|
output.PlayStreaming( container );
|
||||||
|
|
||||||
|
dst.Position = 0;
|
||||||
|
BinaryWriter w = new BinaryWriter( dst );
|
||||||
|
WriteWaveHeader( w, dst, output );
|
||||||
}
|
}
|
||||||
|
|
||||||
long len = outData.Position - start;
|
|
||||||
outText.WriteLine( format, name, outDecoder.Frequency,
|
|
||||||
outDecoder.BitsPerSample, outDecoder.Channels,
|
|
||||||
start, len );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string format = "{0},{1},{2},{3},{4},{5}";
|
void WriteWaveHeader( BinaryWriter w, Stream stream, RawOut data ) {
|
||||||
void InitOutput( string outputPath ) {
|
WriteFourCC( w, "RIFF" );
|
||||||
outData = File.Create( outputPath + ".bin" );
|
w.Write( (int)(stream.Length - 8) );
|
||||||
outText = new StreamWriter( outputPath + ".txt" );
|
WriteFourCC( w, "WAVE" );
|
||||||
outDecoder = new RawOut( outData, true );
|
|
||||||
|
|
||||||
outText.WriteLine( "# This file indicates where the various raw decompressed sound data " +
|
WriteFourCC( w, "fmt " );
|
||||||
"are found in the corresponding raw .bin file." );
|
w.Write( 16 );
|
||||||
outText.WriteLine( "# Each line is in the following format:" );
|
w.Write( (ushort)1 ); // audio format, PCM
|
||||||
outText.WriteLine( "# Identifier, Frequency/Sample rate, BitsPerSample, " +
|
w.Write( (ushort)data.Channels );
|
||||||
"Channels, Offset from start, Length in bytes" );
|
w.Write( data.Frequency );
|
||||||
|
w.Write((data.Frequency * data.Channels * data.BitsPerSample) / 8 ); // byte rate
|
||||||
|
w.Write( (ushort)((data.Channels * data.BitsPerSample) / 8) ); // block align
|
||||||
|
w.Write( (ushort)data.BitsPerSample );
|
||||||
|
|
||||||
|
WriteFourCC( w, "data" );
|
||||||
|
w.Write( (int)(stream.Length - 44) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dispose() {
|
void WriteFourCC( BinaryWriter w, string fourCC ) {
|
||||||
outDecoder.Dispose();
|
w.Write( (byte)fourCC[0] ); w.Write( (byte)fourCC[1] );
|
||||||
outData.Close();
|
w.Write( (byte)fourCC[2] ); w.Write( (byte)fourCC[3] );
|
||||||
outText.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user