« MBS Xojo Conference i… | Home | Xojo Conferences and … »

Tip of day: Write WAV file

Sometimes you write an audio app in Xojo and need to write your audio data to a file. Using the WAV file format is very easy and this code is from an app we made today. Samples are stored in memoryblock in LittleEndian byte order and with stereo. The code to write WAV file looks like this:

Sub WriteWAV(f as FolderItem, m as MemoryBlock) // write samples in Int16 format with stereo to a WAV file dim b as BinaryStream = BinaryStream.Create(f, true) b.LittleEndian=true b.Write "RIFF" b.WriteInt32 6+4+16+4+m.Size // size of file b.Write "WAVE" b.Write "fmt " b.WriteInt32 16 // size of following data b.WriteInt16 1 // format, uncompressed b.WriteInt16 2 // 2 Channels b.WriteInt32 44100 // Samples per Second b.WriteInt32 44100*4 // Bytes per Second b.WriteInt16 4 // Block align, Size of Sample in Bytes b.WriteInt16 16 // bits per sample b.Write "data" b.WriteInt32 m.Size b.Write m return f End Sub
The biggest plugin in space...
20 09 15 - 10:03