WAV file splitter program? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: WAV file splitter program? (/showthread.php?tid=1631) Pages:
1
2
|
WAV file splitter program? - madscijr - 04-20-2023 Has anyone done or seen any QB/QB64/QB64PE code that takes a WAV file "MyAlbum.wav" and a text file with track times, in a format like: 0:00 song title #1 3:01 my song #2 4:18 another track 9:49 a long one etc. and cuts up the WAV file into separate files for each track based on the track times, with the files named after the titles, like: MyAlbum 01 song title #1.wav MyAlbum 02 my song #2.wav MyAlbum 03 another track.wav MyAlbum 04 a long one.wav etc. ? I need to go back and study the WAV file format, but it would help if there is some working code to study. RE: WAV file splitter program? - bplus - 04-20-2023 Start by getting the .wav file header format https://docs.fileformat.com/audio/wav/ Then figure out WTH? all that stuff is ;-)) RE: WAV file splitter program? - madscijr - 04-20-2023 (04-20-2023, 02:08 PM)bplus Wrote: Start by getting the .wav file header format Yep, it all starts with the WAV file format spec. Thanks! RE: WAV file splitter program? - mnrvovrfc - 04-20-2023 I have Lua code that (slowly) loads a mono 44100Hz 16-bit wave file into a table which could be split up and written to separate wave files. However, doing it by "markers" requires being able to read chunks in the wave file. The loop point of a WAV sample is a separate chunk. I haven't been able to completely master the ability of reading chunks beyond the "data" chunk. Also keep in mind that programs like Audacity like to save the chunk with "marker" listing before the "data" chunk. In addition, Wavosaur saves its own "saur" chunk to be able to recall a volume envelope without having to save another file that could be easily lost. The second chunk of the file could usually be discovered after the first 40 bytes of the WAV file. The first one is "fmt " (with space as fourth character) which describes the attributes such as sampling rate, bit rate and compression technique. Compressed WAV files are a pain, need to be able to work with a codec for that. With stereo files, the difference from mono files is that the data is interlaced, ie. left side, then right side, then left side, then right side etc. I haven't looked at a WAV which has more than two channels but it should be alike, but few programs support such a thing even for 5.1 Surround sound. Dealing with 32-bit float WAV is another monster but might be necessary today, as many digital audio workstations support it. For a QB64 program, sadly have to read the WAV file twice. Once with the programming system's means to get the sample data, and again separately in the old-fashioned way in order to go hunting for those chunks. It might be easier than expected to interpret the sample frames, taken directly from "marker" information, so that the programmer knows where in the sample data buffer to start or finish copying from. I had to read the first post again. If it has nothing to do with "markers" already in a wave file then this should be even easier. Find the way to convert a time like 4:50 into sample frame value. IINM it should be 22050 for one second of 44100Hz sampling rate, regardless of bit rate because QB64(PE) has code to convert from a different sampling rate and perhaps from a different bit rate as well. This sample frame number is invariably needed for using with _MEMCOPY, to copy from the big WAV file into a new buffer obviously created with another _MEM variable. Could steal the WAV file header for output file but have to fill in the size of the wave file at byte position 5, and the size of the "data" chunk at the position just after that word as it appears. EDIT: If you don't need to do this in a QB64 program, and if audiophile sound quality isn't important, convert WAV to OGG Vorbis and then use "vcut" to split: https://github.com/xiph/vorbis-tools This is what I recommend, although there are different tools for MP3 and maybe for FLAC. RE: WAV file splitter program? - Petr - 04-20-2023 I can write it, but I need to know what format your WAV file is in. Is it mono, stereo, 16 bit, 8 bit, 32 bit? I've worked with it quite a bit in the past. You can find the header of the WAV file in my thread, for example here https://staging.qb64phoenix.com/showthread.php?tid=1491 I only work with uncompressed format. RE: WAV file splitter program? - Ultraman - 04-21-2023 I would say that as long as you know how the header is formatted and can look for those tags, you should be able to split based on each occurrence of these headers. I had code for reading various music files and displaying the contents of the ID3 tags. Worked quite well, especially with FLACs that I ripped from Tidal. Those even had the lyrics and album art embedded as tags. RE: WAV file splitter program? - mnrvovrfc - 04-21-2023 Welcome to the forums. It looks like the OP is asking for a program that takes a text-file description, each line first with time hint and then with "song name", to tell a program how to slice a big WAV file. If the topic starter also expects the program to find the "marker" chunks in a WAV then, well, it gets more complicated for the programmer if he/she is not used to the format. RE: WAV file splitter program? - Petr - 04-21-2023 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. Code: (Select All) 'wav splitter in attachement my txt file as example. RE: WAV file splitter program? - madscijr - 04-21-2023 (04-21-2023, 02:26 PM)mnrvovrfc Wrote: Welcome to the forums. The source file is actually MP4 video, which I would convert to WAV (to burn to audio CD) or MP3 (for mp3 players). I asked about WAV because I don't need or want to deal with the video, and WAV is the format I want to work with for editing, and anything for working with WAV files will come in handy later! I don't know about markers or chunks, the audio doesn't have any metadata or anything special (such as what a DAW might add or use), all I have is a separate text file with the track title listing with each track's length. Slicing up the file automatically would be nice, but actually the track times might not account for any space between songs (I'd need to check when back at the PC), and if that's the case, then I would have the program go to the end of the first track and search forward to determine when the next track begins. The track times can be used as guides, but the actual begin and end locations are approximate, if they don't include the blank space at the end of each track. I did google some more and found a ton of Python scripts that split up sound files, using whatever Python libraries for working with WAV and MP3. QB64PE doesn't have any WAV or MP3 file libraries that I'm aware of, so I think I would need to write all the code to handle reading/parsing/processing/writing the files. As bplus said (and I already figured) the first step is to study the WAV file spec, which I will do as I have time, but I figured it can't hurt to ask here and see if there is any pre-existing QB-like code I could reuse or study to figure out how to do this. (I could always just use Python, but where would the fun be?? LoL) RE: WAV file splitter program? - mnrvovrfc - 04-21-2023 From MP4 it might be possible with FFMPEG but the command-line syntax is very complicated and convoluted. At around this time last year LOL I downloaded the first six episodes of "Silver Moon" Anime cartoon series from "archive-dot-org". It was slow, over six hours! It came as a bunch of VOB files that I had to put together into a single MP4 file using FFMPEG on Windows. But that's putting together the pieces, not taking the big one apart! I'm saying this because it should be possible to get smaller WAV files out of a single MP4, but the utility to do it is difficult to deal with for the average user. Because you want audio only it's easier than video to video. As I've said in my first post in this topic, all it requires is parsing the time, from the text file that you provided as input, then find the way to turn that into a sample frame number. Then just use _SNDOPEN() to load the WAV, use _MEMSOUND() to get a _MEM variable for it, then allocate another _MEM variable [not necessary to use the new syntax for _SNDOPEN() because there's no direct way to save that to disk] for the output buffer to hold a piece of the large sample data buffer. Could use _MEMGET and _MEMPUT for the "slow" way, or if you know what you are really doing, could just use _MEMCOPY with the right size of one song from the sample data. Adding silence at front or back is up to you, will require additional programming (trickery) but not really that difficult. I wish I could cobble up an example for you. Doing sample markers inside a WAV isn't going to get the names of the songs in many cases. It depends on a WAV prepared by the original author, or if conversion to WAV was able to go that far. That's why "your way" is better: I give you a wave file and a text file for how to chop it up. LOL. EDIT: I had ignored Petr's contribution. That should be enough. Just fix it for the sake of absolute elapsed times over the big wave file. |