Last active
May 12, 2019 07:48
-
-
Save RGBA-CRT/0c71ee700865f1b502f2e2fc7a9d54c5 to your computer and use it in GitHub Desktop.
GBの波形メモリデータをwavに変換するプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #console | |
| #include<RGBALib.sbp> | |
| 'GBの波形メモリデータをwavに変換するプログラム for ActiveBasic4 | |
| '波形メモリデータはNezplugのDumpとかで取得 | |
| printf(ex"GB CH3 Wave To 16bit PCM Tool ::: RGBA_CRT 2019\n") | |
| Dim buf[16] AS Byte | |
| Dim pcmbuf[32] AS Integer | |
| Dim infile AS File | |
| Dim outfile AS File | |
| Dim arg AS CommandLine | |
| if arg.GetCount()<>2 Then | |
| Print "Usage: gbwave2pcm dmg_reg_dump_ff30-ff3f.bin" | |
| end | |
| End If | |
| '波形メモリをバッファに読み込み | |
| infile.openFile(arg.GetCmd(1),GENERIC_READ) | |
| infile.read(buf,16) | |
| infile.close() | |
| '波形メモリを16ビットPCMに変換 | |
| Dim i AS Long, zoomCount AS Long, s aS Long | |
| For i=0 To 15 | |
| pcmbuf[i*2] = ( (((buf[i]>>4) And &H0F) As Long -8)*2047 ) As Integer | |
| pcmbuf[i*2+1] = ( (((buf[i]>>0) And &H0F) As Long -8)*2047 ) AS Integer | |
| Next i | |
| '出力ファイルを作成 | |
| outfile.openFile(arg.GetCmdString(1)+"_16bit.wav",GENERIC_WRITE) | |
| 'wavヘッダを作る | |
| Dim wavHeader As RIFF_FORMAT_HEADER | |
| CreateRiffHeader(wavHeader,16,1,25600) | |
| 'ファイルに書き込む | |
| outfile.write(VarPtr(wavHeader),sizeof(RIFF_FORMAT_HEADER)) | |
| Dim datasize AS Long | |
| For s=0 to 0 | |
| For i=0 To 31 | |
| For zoomCount=0 To 16 | |
| outfile.write(VarPtr(pcmbuf[i]),2) | |
| datasize+=2 | |
| Next zoomCount | |
| Next i | |
| Next s | |
| 'wavヘッダ更新 | |
| wavHeader.DataSize=datasize | |
| wavHeader.riffSize = datasize + sizeof(RIFF_FORMAT_HEADER) | |
| printf("ds=%d %d",datasize,sizeof(RIFF_FORMAT_HEADER)) | |
| outfile.setFilePtr(0) | |
| outfile.write(VarPtr(wavHeader),sizeof(RIFF_FORMAT_HEADER)) | |
| outfile.close() | |
| End | |
| Type RIFF_FORMAT_HEADER | |
| RIFF As DWord | |
| riffSize As DWord | |
| RType AS DWord | |
| fmt As DWORD | |
| fSize As DWORD | |
| FormatCode As WORD | |
| ch As WORD | |
| Sample As DWORD | |
| SecByte As DWORD | |
| Block As WORD | |
| Bit As WORD | |
| DATA As DWORD | |
| DataSize As DWORD | |
| EndType | |
| Sub CreateRiffHeader(ByRef header_buf As RIFF_FORMAT_HEADER, bits AS Word, num_channel As Word, sample_rate AS DWord) | |
| With header_buf | |
| .RIFF=Str2Dw("RIFF") | |
| .RType=Str2Dw("WAVE") | |
| .riffSize=0 | |
| .Bit=bits | |
| .ch=num_channel | |
| .fmt=Str2Dw("fmt ") | |
| .FormatCode=1 | |
| .Sample=sample_rate | |
| .fSize=16 | |
| .Block=bits/8 * num_channel | |
| .SecByte=.Block *.Sample | |
| .DATA=Str2Dw("data") | |
| .DataSize=4 | |
| Endwith | |
| endsub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment