I had to try it. I only tested it on 16 bit format. stereo, but it should work on all types. The created WAV files (cut original) have the same bitrate, the same number of channels, etc., only the length is different according to the text file.
Text file format:
First line: number specifying the number of tracks to be cut
Second line: source file name in quotes
third and following lines: destination file name in quotes followed by a comma and a time in colon format (required), eg 1:25 means minute, 25 seconds.
The new file always starts exactly after the end of the previous file. For example, if you need to cut recordings with silence, write it in a text file like this (example - the source uncompressed WAV file is called allinone.wav, you want to cut it into three WAV files, with lengths of 1:10, 2:20, 3:00 but you need to cut three seconds of silence between each of these recordings) - do it like this:
txt file content:
5
"allinone"
"Track 01", 1:10
"Silent 1", 0:3
"Track 02", 2:20
"Silent 2", 0:3
"Track 03", 3:00
end of txt file
then just delete created "silent" waves, tracks begin without this part.
Yes, This is really very good fun.
in attachement my txt file as example.
Text file format:
First line: number specifying the number of tracks to be cut
Second line: source file name in quotes
third and following lines: destination file name in quotes followed by a comma and a time in colon format (required), eg 1:25 means minute, 25 seconds.
The new file always starts exactly after the end of the previous file. For example, if you need to cut recordings with silence, write it in a text file like this (example - the source uncompressed WAV file is called allinone.wav, you want to cut it into three WAV files, with lengths of 1:10, 2:20, 3:00 but you need to cut three seconds of silence between each of these recordings) - do it like this:
txt file content:
5
"allinone"
"Track 01", 1:10
"Silent 1", 0:3
"Track 02", 2:20
"Silent 2", 0:3
"Track 03", 3:00
end of txt file
then just delete created "silent" waves, tracks begin without this part.
Yes, This is really very good fun.
Code: (Select All)
'wav splitter
'STEP 1: verify text file
'text file format:
'first line is number - total files to create
'4
'next row contains wav source file name
'next 4 rows is new file name and track lenght "FileName", 0:27
'wav extension is add automaticaly
Type TrackType
Time As Single
Song As String
End Type
Type WAVHead
chunk As String * 4 ' 4 bytes (RIFF)
size As _Unsigned Long ' 4 bytes (file size) velikost souboru
fomat As String * 4 ' 4 bytes (WAVE)
sub1 As String * 4 ' 4 bytes (fmt )
subchunksize As Long ' 4 bytes (lo / hi), $00000010 for PCM audio
format As Integer ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM)
channels As Integer ' 2 bytes (1 = mono, 2 = stereo)
rate As Long ' 4 bytes (sample rate, standard is 44100)
ByteRate As Long ' 4 bytes (= sample rate * number of channels * (bits per channel /8))
Block As Integer ' 2 bytes (block align = number of channels * bits per sample /8)
Bits As Integer ' 2 bytes (bits per sample. 8 = 8, 16 = 16)
subchunk2 As String * 4 ' 4 bytes ("data") contains begin audio samples
lenght As _Unsigned Long ' 4 bytes Data block size
End Type ' 44 bytes total
Dim WavHead As WAVHead
Dim WavNew As WAVHead
SplitTxt$ = "split.txt"
ff = FreeFile
If _FileExists(SplitTxt$) Then
Open SplitTxt$ For Input As ff
If LOF(ff) > 0 Then
Input #ff, tracks$
Tracks = Val(tracks$)
If Tracks <= 0 Then
Print "Can not create negative or zero new tracks.": End
Else
Input #ff, source$
If LCase$(Right$(source$, 4)) <> ".wav" Then source$ = source$ + ".wav"
If _FileExists(source$) Then
Dim tracks(Tracks) As TrackType
While Not EOF(ff)
Input #ff, TrackName$, TrackTime$
If LCase$(Right$(TrackName$, 4)) <> ".wav" Then TrackName$ = TrackName$ + ".wav"
tracks(ti).Song = TrackName$
separator = InStr(1, TrackTime$, ":")
If separator = 0 Then Print "Invalid track time. Use format Min:Sec": End
Min = Val(Left$(TrackTime$, separator - 1))
Sec = Val(Right$(TrackTime$, separator))
tracks(ti).Time = Min * 60 + Sec
ti = ti + 1
If ti > Tracks Then Print "Txt file contains more records than is declared on line 1 in txt file "; SplitTxt$; Tracks; ti: End
Wend
Else
Print "Source file: "; source$; " not exists.": End
End If
End If
Else
Print "File lenght "; SplitTxt$; " is not valid.": End
End If
Else
Print "File: "; SplitTxt$; " not exists."
End If
Print "Total declared tracks:"; Tracks
Print "Source WAV sound file: "; source$
Close ff
For TimeTest = 0 To Tracks
TotalTime = TotalTime + tracks(TimeTest).Time
Next
Print "Total Time in "; Tracks; " tracks is:"; TotalTime
ff = FreeFile
Open source$ For Binary As ff
Get ff, , WavHead
If WavHead.chunk <> "RIFF" Then Print "Invalid source file WAV format: "; WavHead.chunk
SAFLEN = WavHead.lenght / (WavHead.Bits / 8) / WavHead.channels / WavHead.rate
If SAFLEN < TotalTime Then Print "Source audio file is shorter than the total required length. Some audio tracks may therefore have silence at the end."
Print "Source audio file lenght:"; SAFLEN
Print "Source audio file format:"; WavHead.Bits
Print "Source audio file channels:"; WavHead.channels
all$ = Space$(LOF(ff))
Get ff, 1, all$
Start = InStr(1, all$, "data") + 4
Seek #ff, Start
all$ = ""
For split = 0 To Tracks - 1
Print "Creating track "; tracks(split).Song; " ["; LTrim$(Str$(tracks(split).Time)); "S]"
DataSize& = (WavHead.Bits / 8) * WavHead.channels * WavHead.rate * tracks(split).Time
datas$ = Space$(DataSize&)
Get #ff, , datas$
WavNew.Bits = WavHead.Bits
WavNew.channels = WavHead.channels
WavNew.rate = WavHead.rate
WavNew.chunk = "RIFF"
WavNew.size = DataSize& + 44
WavNew.fomat = WavHead.fomat
WavNew.sub1 = WavHead.sub1
WavNew.subchunksize = WavHead.subchunksize
WavNew.ByteRate = WavHead.ByteRate
WavNew.Block = WavHead.Block
WavNew.subchunk2 = WavHead.subchunk2
WavNew.format = WavHead.format
WavNew.lenght = DataSize&
' Print "New WAV bits: "; WavNew.Bits
' Print "New WAV channels: "; WavNew.channels
' Print "New WAV sound rate: "; WavNew.rate
' Print "New WAV size: "; WavNew.size
ff2 = FreeFile
Open tracks(split).Song For Binary As ff2
Put ff2, , WavNew
Put ff2, , datas$
Close ff2
datas$ = ""
Next
in attachement my txt file as example.