Page 1 of 2

Changing file extensions / saving custom file types

Posted: Sat Mar 22, 2014 9:49 pm
by KG_is_back
Is it possible in FS to create/save custom file types? Or change extension of files with flowstone?

basically I'm working on a project that uses .wav files to save coefficient presets. The algorithm is very sensitive to loading random files, so I would like to save the coefficients as file with custom extension, to prevent user accidentally loading an actual wave file and crashing his DAW.
The simplest solution I can think of is to change file extention of the wav file (containing coefficients) after it's been saved by "save wave" primitive. Would this prevent "load wave" primitive from loading the file? (if it would then I would need a way to change the extension back to .wav before load and back to the custom one after is loaded)

Re: Changing file extensions / saving custom file types

Posted: Sat Mar 22, 2014 10:27 pm
by RJHollins
Are these 'coefficients' being written into the WAV Header ???

I don't know if there use 'user space' available in this header to add 'general' info or data. The issue would be a type of corruption of the file in that the standard loading gets confused.

Re: Changing file extensions / saving custom file types

Posted: Sat Mar 22, 2014 11:01 pm
by tester
No problem. you can define it as you wish. There was a small project I made for that:
viewtopic.php?f=2&t=1832&p=8994

Let me know if you need more.

Re: Changing file extensions / saving custom file types

Posted: Sat Mar 22, 2014 11:31 pm
by KG_is_back
RJHollins wrote:Are these 'coefficients' being written into the WAV Header ???

I don't know if there use 'user space' available in this header to add 'general' info or data. The issue would be a type of corruption of the file in that the standard loading gets confused.

No, the data is stored only as samples of the actual wave. It is normal simple 44100hz/32bit-float wave file, just the values stored as samples are not actually a wave - they are used for something else.

tester wrote:No problem. you can define it as you wish. There was a small project I made for that:viewtopic.php?f=2&t=1832&p=8994Let me know if you need more.

Unfortunately it doesn't work for save wave (wave files are stored as .wav no matter what extension you enter). It works fine for preset files though, so I might go with that. Are floating point parameters in presets stored in full precision? Because when I connect float array to a text primitive the values get rounded to 7 decimal places. Does this happen when saving presets too?
because the coefficients I'm working with are used in upto 6th-order filters that are connected in feedback loop... so the precision is quite crucial (I'm not even satisfied with single precision floats to be honest). That is the reason why I went directly with the 32bit wav right away.

Re: Changing file extensions / saving custom file types

Posted: Sat Mar 22, 2014 11:55 pm
by tester
For dealing with wave load/save - there are prims savewave and wavefile. Are they overwriting filename extension set via message box, that delivers filepath and filename and selected extension? If so, then this would be a bug in FS.

Re: Changing file extensions / saving custom file types

Posted: Sun Mar 23, 2014 12:04 am
by KG_is_back
tester wrote:For dealing with wave load/save - there are prims savewave and wavefile. Are they overwriting filename extension set via message box, that delivers filepath and filename and selected extension? If so, then this would be a bug in FS.

Yes, they are... I don't think it's really a bug - to me it seems that they suppose to work that way (I bet the developers didn't count with a mad scientist like me trying to save other data than waves into WAV files :mrgreen: ). It's annoying though... especially in a situation I'm in right now.

Re: Changing file extensions / saving custom file types

Posted: Sun Mar 23, 2014 12:23 am
by tester
Welcome to mad scientists club. :-)

Filename/path handlers are however here to handle the filenames, paths AND extensions, no matter what is the content of a file. Thus - wave content should be saved under the cover provided by the handler.

Alternative would be to convert and import/export through ruby due to precision. I'm not sure if there is no project on that somewhere around.

Re: Changing file extensions / saving custom file types

Posted: Sun Mar 23, 2014 12:38 am
by KG_is_back
tester wrote:Welcome to mad scientists club. :-)

Filename/path handlers are however here to handle the filenames, paths AND extensions, no matter what is the content of a file. Thus - wave content should be saved under the cover provided by the handler.

Alternative would be to convert and import/export through ruby due to precision. I'm not sure if there is no project on that somewhere around.


If preset save files give enough precision to save 32bit float numbers, then I do not have to use wavs. If they don't, I can still save exponent and mantissa separately as two float numbers (It's actually not that hard to separate them).
BTW your suffix prefix system solved another issue I was working on. The coefficients are samplerate-specific ...using your schematics I can now automatically provide samplerate in the filename to avoid missloading wrong model. ;)

Re: Changing file extensions / saving custom file types

Posted: Sun Mar 23, 2014 12:59 am
by tester
Good to know that it helped a little bit.

I would be interested to see your way of saving/loading (bidirectional use) in the dual mode (exponent and mantissa separately). While I have a glimpse on how it may look like, my mad science is wandering somewhere else at the moment.

Re: Changing file extensions / saving custom file types

Posted: Sun Mar 23, 2014 1:14 am
by KG_is_back
tester wrote:Good to know that it helped a little bit.

I would be interested to see your way of saving/loading (bidirectional use) in the dual mode (exponent and mantissa separately). While I have a glimpse on how it may look like, my mad science is wandering somewhere else at the moment.


Well it loads the binary structure of a 32bit float number and separate upper and lower 16bits. converts these binary structures from integers to floats. The backward conversion is even simpler convert both floats back to integer, bitshift upper part by 16bit and preform logical OR.