I’d like to see declares to AVFoundation too. I’ve tried it but not sure how to instantiate AV objects, only NS ones. Maybe with QTKit out this stuff can be easier to build in. Anyways, if you know how to build your waveform a brute force strategy is to write wav format files which are pretty raw. This example makes a 8bit, mono, 44.1khz, 2 second file then opens and plays it.
[code]//Pushbutton to create and write test.wav file on Desktop
Sub Action()
dim waveData As MemoryBlock = genWaveData
dim fileData As MemoryBlock = createWaveFileData(waveData)
dim f As FolderItem = SpecialFolder.Desktop.Child(“test.wav”)
dim bs As BinaryStream = BinaryStream.Create(f, true)
bs.Write(fileData)
bs.Close
End Sub
Function genWaveData() As MemoryBlock
dim res As integer = 44100 //hz
dim samplesCount As integer = 88200 //gen 2 seconds of samples
dim m As new MemoryBlock(samplesCount)
dim scaler As double = 6.28318 / res
dim lastSample As integer = samplesCount - 1
dim a As double
for i As integer = 0 to lastSample
a = i * scaler
m.UInt8Value(i) = 127 + 32sin(440a) + 16sin(882a) + 8sin(1761a) //sine sum
next
return m
End Function
Function createWaveFileData(waveData As MemoryBlock) As MemoryBlock
dim m As new MemoryBlock(44 + waveData.Size) //header is 44 bytes
m.LittleEndian = true
m.UInt32Value(0) = &h46464952 //“RIFF”
m.Int32Value(4) = m.Size - 8
m.UInt32Value(8) = &h45564157 //“WAVE”
m.UInt32Value(12) = &h20746d66 //"fmt "
m.UInt32Value(16) = 16 //fmt chunck size
m.UInt16Value(20) = 1 //PCM
m.UInt16Value(22) = 1 //mono
m.UInt32Value(24) = 44100 //sample rate
m.UInt32Value(28) = 44100 //44100 * 1 * 8 / 8 //SampleRate * NumChannels * BitsPerSample/8 //ByteRate
m.UInt16Value(32) = 1 //1 * 8 / 8 //NumChannels * BitsPerSample/8 //block align
m.UInt16Value(34) = 8 //bits per sample
m.UInt32Value(36) = &h61746164 //“data”
m.UInt32Value(40) = waveData.Size //waveData.Size * 1 * 8/8 //NumSamples * NumChannels * BitsPerSample/8
m.StringValue(44, waveData.Size) = waveData //copy in samples
return m
//format references
//https:/ /ccrma.stanford.edu/courses/422/projects/WaveFormat/
//http:/ /www.topherlee.com/software/pcm-tut-wavformat.html
End Function
//Pushbutton to open and play test.wav
Sub Action()
dim s As Sound = SpecialFolder.Desktop.Child(“test.wav”).OpenAsSound
if s = nil then break
s.Play
End Sub[/code]