Old 11-29-2018, 10:37 AM   #1
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,328
Default Fastest and safest way to alter (write directly into) a wave file?

Hello!


I am creating some scripts for writing cue markers into wave files. The scripts I have done so far are (in ReaPack):
1) Add project markers as cue points to selected items and replace source file



2) amagalma_Remove selected items' cue points and replace source file (WAV only).


In the first one I use Reaper's rendering to create the new files with the markers, but I have 99% ready another version of the script that does the writing of the cues itself (without rendering any files).


In the second one, currently, I create a new file without the cue markers and replace the source file of the selected items with the new files.


What I want to ask is: what would be the safest and fastest way to do these operations:
1) write directly to the file? Certainly, this is the fastest and easiest way, but would it be safe? If anything goes wrong during the writting, say goodbye to the file forever! :S
2) write to a temp file, replace the source in the items with the new file and then delete the old one?
3) create a backup of the file, then write directly to the original and if all is good, delete the backup? This would be faster than 2) I guess, but again if something went wrong, you would have a project referring to files that do not exist (since the backups would have different names)
4) something else?


Thanks!
amagalma is offline   Reply With Quote
Old 11-29-2018, 04:24 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,230
Default

So I see you explore things I explore in thsi trhead !


Script: Wave File CUE Points / LIST Markers Editing


To be honnest, this is a rabbit hole :P Once you have read the Wave file documentation and chunk metadata, you will find that some softwares don't respect that and inject chunk in random orders, making things less predictable than it could be.


Quote:
1) write directly to the file? Certainly, this is the fastest and easiest way, but would it be safe? If anything goes wrong during the writting, say goodbye to the file forever! :S

This is the way to go, once it would have been deeply tested. The user could make backup on its own he it feels it (a warning could be displayed).



The safest way is to replace the initial cue point list by junk chunk if it is in the middle of the wave file, and it it is at the end, tehn you can safely deleted and replace it by your own.


For the moment my scripts are on old cause they worked by putting all the chunk in the RAM and create the wave file from there rather than erasing the initial chunk and replace by the own. It had the advantages of being able to put chunk in the right order and not needed junks chunk but it was a bit sensitive to non standard wave files.


Experiment with Riffpad and BWFMetaEdit to see how things are set up.
X-Raym is offline   Reply With Quote
Old 11-30-2018, 02:20 PM   #3
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,328
Default

Thanks X-Raym! Yes, I remember your thread and how far you had gone! You were using an external tool calling it with cmd.exe, right?


My other script, which creates directly the cue and list chunks (without rendering by Reaper, or calling any external program), works in this way:
1) checks if there is already a cue and list chunk in the WAV file and keeps the info into memory
2) reads the whole file and puts it to memory (throwing away the old cue/list chunks and riff header)
3) creates a new file and writes the new header, content and new cue/list chunks. I can make it overwrite the original file, without creating a new one, and about that was my question.


What if something goes wrong while overwriting the file? A power failure, or whatever. It would make the file useless and unrecoverable..


Another thing that I am not sure is if keeping the whole file into RAM is a good idea. I have 18GB of RAM but maybe some systems would struggle if they had to put a 4GB WAV file into RAM...


Hmm.. your idea of junk chunk is not bad... Maybe I could overwrite the old cue/list chunks and turn them into junk chunks, then append the new cue/list chunks to the file and finally overwrite the new header.. This would probably be the fastest and safest way!.. Wouldn't it?
amagalma is offline   Reply With Quote
Old 11-30-2018, 03:45 PM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,230
Default

My initial approach was using python scripts to handle that, called via command line yes, but I had a work in progress Lua script which works without any depencies. But just like you, it didn't write an existing chuncks, so I dropped it for the moment.




Quote:
then append the new cue/list chunks to the file and finally overwrite the new header.. This would probably be the fastest and safest way!.. Wouldn't it?
Yes, this is what I was suggesting :P


It should and it should be so fats that power shutdown shouldn't be an issue !


Yes, putting the whole file in RAM should be avoid. Yes most computer can handle 4Giga file in RAM (well, maybe not if we take other app and OS into aco****), but it is also ecological programming :P And it should be way more efficient anyway !
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.