From 2aa979ec2cb3c7b971d023dda8c1fd07ce0af8fa Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Tue, 23 Feb 2010 16:59:06 +0000 Subject: riff wave instead of raw recording (experimental) correction of alt-tab bugfix git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1 Challenge MOD@2149 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 96 +++++++++++++++++++++++++++++++++++++-- Game/Code/Classes/UMain.pas | 2 +- Game/Code/Screens/UScreenSing.pas | 4 +- 3 files changed, 96 insertions(+), 6 deletions(-) (limited to 'Game/Code') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 9d20d2f1..16473318 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -173,24 +173,114 @@ begin end; procedure TLog.LogVoice(SoundNr: integer); +type + TRiffHeader = record + riff: Array[0..3] OF Char; + filesize: LongInt; + typeStr: Array[0..3] OF Char; + end; + TChunkRec = record + id: Array[0..3] OF Char; + size: LongInt; + end; + TWaveFormatRec = record + tag: Word; + channels: Word; + samplesPerSec: LongInt; + bytesPerSec: LongInt; + blockAlign: Word; + bitsPerSample: Word; + end; + TPCMWaveFormatRec = record + wf: TWaveFormatRec; + end; + TWAVHeader = record { WAV Format } + riffHdr: TRiffHeader; + fmtChunk: TChunkRec; + fmt: TPCMWaveFormatRec; + dataChunk: TChunkRec; + { data follows here } + end; + +procedure HeadInit(var Header: TWAVHeader); +begin + with Header do + begin + with riffHdr do + begin + //Schreibe 'RIFF' in die ersten 4 bytes + riff[0] := 'R'; riff[1] := 'I'; riff[2] := 'F'; riff[3] := 'F'; + // wird spaeter gesetzt; + filesize := 0; + //Schreibe 'WAVE' in die naechsten 4 bytes + typeStr[0] := 'W'; typeStr[1] := 'A'; typeStr[2] := 'V'; typeStr[3] := 'E'; + end; + with fmtChunk do + begin + //Schreibe 'fmt' + char($20) in die naechsten 4 bytes + id[0] := 'f'; id[1] := 'm'; id[2] := 't'; id[3] := ' '; + size := 16; + end; + with fmt.wf do + begin + //its 16 bit, 44.1kHz Mono + tag := 1; channels := 1; + samplesPerSec := 44100; + bytesPerSec := 44100*2; + blockAlign := 2; + bitsPerSample := 16; + end; + with dataChunk do + begin + //Schreibe 'data' in die naechsten 4 bytes + id[0] := 'd'; id[1] := 'a'; id[2] := 't'; id[3] := 'a'; + size := 0; + end; + end; +end; + + var FileVoice: File; FS: TFileStream; FileName: string; Num: integer; BL: integer; + Header: TWAVHeader; + ms: TMemoryStream; + s: LongInt; + begin for Num := 1 to 9999 do begin FileName := IntToStr(Num); while Length(FileName) < 4 do FileName := '0' + FileName; - FileName := LogPath + 'Voice' + FileName + '.raw'; + FileName := LogPath + 'Voice' + FileName + '.wav'; if not FileExists(FileName) then break end; - FS := TFileStream.Create(FileName, fmCreate); - for BL := 0 to High(Sound[SoundNr].BufferLong) do begin + HeadInit(Header); + s := 0; + for BL := 0 to High(Sound[SoundNr].BufferLong) do + s := s + Sound[SoundNr].BufferLong[BL].Size; + + Header.Datachunk.size := s; + //FileSize = DataSize + HeaderSize + Header.riffHdr.FileSize := Header.Datachunk.size + 24; + + ms := TMemoryStream.Create; + ms.Seek(0, soBeginning); + //Write Header to Stream + ms.Write(Header, sizeof(header)); + ms.Seek(0, soBeginning); + + FS.CopyFrom(ms, ms.Size); + FS.Seek(0, soEnd); + ms.Free; + + for BL := 0 to High(Sound[SoundNr].BufferLong) do + begin Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); FS.CopyFrom(Sound[SoundNr].BufferLong[BL], Sound[SoundNr].BufferLong[BL].Size); end; diff --git a/Game/Code/Classes/UMain.pas b/Game/Code/Classes/UMain.pas index 1d94aa23..35c84059 100644 --- a/Game/Code/Classes/UMain.pas +++ b/Game/Code/Classes/UMain.pas @@ -163,7 +163,7 @@ Begin Case Event.type_ Of SDL_ACTIVEEVENT: //workaround for alt-tab bug begin - if (Event.active.gain=0) then + if (Event.active.gain=1) then SDL_SetModState(KMOD_NONE); end; diff --git a/Game/Code/Screens/UScreenSing.pas b/Game/Code/Screens/UScreenSing.pas index 690f2b64..202b02c3 100644 --- a/Game/Code/Screens/UScreenSing.pas +++ b/Game/Code/Screens/UScreenSing.pas @@ -1408,8 +1408,8 @@ begin if Ini.SavePlayback = 1 then begin Log.BenchmarkStart(0); Log.LogVoice(0); - Log.LogVoice(1); - Log.LogVoice(2); + //Log.LogVoice(1); + //Log.LogVoice(2); Log.BenchmarkEnd(0); Log.LogBenchmark('Creating files', 0); end; -- cgit v1.2.3