HEXdump2BIN for OSX
Posted: Tue Sep 05, 2017 6:08 pm
Anticipating a new SP-version without Dropbox-acces, I developed a method to transfer binary files (e.g. soundfiles) from OSX to SB.
OSX has a command to make a hexadecimal dump of a file to a textfile.
That textfile can be transferred to SB via copy and paste and then recoded into a binary file.
I made an example with the soundfile "alarm.wav"
In the terminal-app in OSX that file is transferred into the hexdump file "alarm.wavHEXdump" with the command:
hexdump -C -v alarm.wav > alarm.wavHEXdump
More details are given in the attached file "HEXdump in OSX procedure" The following picture gives a screenshot of the terminal-window. With the following code the file "alarm.wavHEXdump" is then recoded to the binary soundfile and tested.
The hexdump-file "alarm.wavHEXdump" is also attached.
Remove the extension ".txt" before start of the the program
The complete folder "HEX2BIN" can also be downloaded from https://www.dropbox.com/sh/z9j037m0trn1 ... AfEFa?dl=0
OSX has a command to make a hexadecimal dump of a file to a textfile.
That textfile can be transferred to SB via copy and paste and then recoded into a binary file.
I made an example with the soundfile "alarm.wav"
In the terminal-app in OSX that file is transferred into the hexdump file "alarm.wavHEXdump" with the command:
hexdump -C -v alarm.wav > alarm.wavHEXdump
More details are given in the attached file "HEXdump in OSX procedure" The following picture gives a screenshot of the terminal-window. With the following code the file "alarm.wavHEXdump" is then recoded to the binary soundfile and tested.
Code: Select all
'HEXdump2BIN by Dutchman, September 2017
'Transform hexdump-file from OSX to binary file
'
'==== USER OPTIONS ====
Infile$="alarm.wavHEXdump"
HexFile$="alarm.wavHEX"
BinFile$="alarm.wav"
'
'==== CONSTANTS ====
'
'==== PRESETS ====
OPTION BASE 1
'
'==== MAIN ====
'--- determine sizes
filesize=FILE_SIZE(InFile$)
FILE InFile$ READLINE line$
linesize=LEN(Line$)
PRINT "Operating on file """&InFile$&""":"
PRINT "Filesize=";"#":filesize
PRINT "Line length=";"#":linesize
lines=CEIL(filesize/linesize)
ns=lines*16 ' size of string-array
PRINT "Number of lines=";"#":lines
PRINT "Number of bytes in binary file is <=";"#":ns
DIM Dump$(ns)
'
'--- Read data into array
nd=0 'number of binary data
WHILE NOT FILE_END(InFile$)
'cut final part
i=INSTR(line$,"|",1)
Line$=LEFT$(Line$,i-1)
SPLIT Line$ TO m$,n WITH " "
FOR i=1 TO n-1 ! Dump$(nd+i)=m$(i+1) ! NEXT i
nd+=n-1 ' exclude address-data
FILE InFile$ READLINE line$
END WHILE
PRINT nd;"hex codes read."
PRINT "Last line contained ";"#":nd%16;"codes."
DIM Bin(nd)
'
'--- Write to binary file
IF FILE_EXISTS(BinFile$) THEN FILE BinFile$ DELETE
FOR i=1 TO nd
Bin(i)=DEC(Dump$(i))
NEXT i
FILE BinFile$ WRITEDIM Bin
PRINT "Binary data written to """&BinFile$&"""."
'
'--- Test binary file
IF BinFile$="alarm.wav" THEN
PRINT "Test on binary file """&BinFile$&"""."
MUSIC 1 LOAD "alarm.wav"
FOR i=1 TO 3
MUSIC 1 PLAY
PAUSE 1
NEXT i
FILE BinFile$ DELETE
ENDIF
PRINT "Done"
END
The complete folder "HEX2BIN" can also be downloaded from https://www.dropbox.com/sh/z9j037m0trn1 ... AfEFa?dl=0