How can I create and store a wav file generated from code

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
drhoward
Posts: 22
Joined: Tue Dec 10, 2013 9:03 am

How can I create and store a wav file generated from code

Post by drhoward » Tue Dec 10, 2013 9:36 am

I have a project that requires my being able to use the sine function to generate data points for a sine wave generator and store it in a wav file format, which can then be read and played on a computer. This will permit me to generate several different waves at specific frequencies and add them together to make a composite audio wave form. This type of wave form has potential healing applications and the code will be made available to whoever wants to use it for experimenting with sounds, light, or other forms of modulated energy, as well as any other use that they may have for such a program. I need to be able to create or modify both the data array and appropriate wav header information to specify the sampling rate, length of the file, and any other necessary header information. Does anyone know how to go about doing this? I had originally hoped to have access to the audio class module where the header and data for audio files are stored, but can't find any reference on how to do this. Will I have to create a binary file from scratch and fill in the header and data the hard way using binary? I would rather not have to do it that way. Please advise! Thank you!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How can I create and store a wav file generated from cod

Post by FourthWorld » Tue Dec 10, 2013 3:21 pm

While the WAV format is often used for uncompressed data, it's designed as a wrapper around any number of codecs. It's possible to use LiveCode's binary functions to write those codecs, but impractical from an engineering standpoint, and possibly from a legal standpoint as well when it comes to codecs that may still be protected by patents.

In your case, since you're writing the data, it may be slightly easier to do so since you have control over the data. It would still be a tough job though, and the best way to determine just how tough would be to review Microsoft's documentation for the WAV format.

It may be more practical to consider writing an external for this, using C or C# calling MS' APIs directly. I haven't done this myself, but given the number of waveform displays out there I would imagine they have an API for that as well as for wrapping the audio stream into the WAV format.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

drhoward
Posts: 22
Joined: Tue Dec 10, 2013 9:03 am

Re: How can I create and store a wav file generated from cod

Post by drhoward » Thu Dec 12, 2013 9:44 am

Thank you for your quick reply. I suspected that this might be the case. I looked at the wav format specs and they are not complicated. The file consists of a simple header block, with minimal entries, especially with no compression, followed by the data. I should be able to handle it using an array and a LiveCode binary file write function. I'll see what happens. Thanks again.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How can I create and store a wav file generated from cod

Post by FourthWorld » Thu Dec 12, 2013 3:48 pm

Please let me know how it goes. I admire your ambition.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Multimedia”