'Salva il file WAV sul device, memoria interna
Dim output As OutputStream
output = StartWaveFile(MP.DBFolder&"/audio", mFileName, MP.mSampleRate, MP.mMono, MP.mBitRate)
For Each buffer() As Byte In buffers
output.WriteBytes(buffer, 0, buffer.Length)
Next
output.Close
CloseWaveFile(MP.DBFolder&"/audio", mFileName)
'Predispone output di WAV file
Sub StartWaveFile(Dir As String, FileName As String, SampleRate As Int, Mono As Boolean _
, BitsPerSample As Int) As OutputStream
File.Delete(Dir, FileName)
Dim raf As RandomAccessFile
raf.Initialize2(Dir, FileName, False, True)
raf.WriteBytes("RIFF".GetBytes("ASCII"), 0, 4, raf.CurrentPosition)
raf.CurrentPosition = 8 'skip 4 bytes for the size
raf.WriteBytes("WAVE".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteBytes("fmt ".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteInt(16, raf.CurrentPosition)
raf.WriteShort(1, raf.CurrentPosition)
Dim numberOfChannels As Int
If Mono Then numberOfChannels = 1 Else numberOfChannels = 2
raf.WriteShort(numberOfChannels, raf.CurrentPosition)
raf.WriteInt(SampleRate, raf.CurrentPosition)
raf.WriteInt(SampleRate * numberOfChannels * BitsPerSample / 8, raf.CurrentPosition)
raf.WriteShort(numberOfChannels * BitsPerSample / 8, raf.CurrentPosition)
raf.WriteShort(BitsPerSample, raf.CurrentPosition)
raf.WriteBytes("data".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.Close
Return File.OpenOutput(Dir, FileName, True)
End Sub
'Finalizza e chiude WAV file
Sub CloseWaveFile(Dir As String, FileName As String)
Dim raf As RandomAccessFile
raf.Initialize2(Dir, FileName, False, True)
raf.WriteInt(raf.Size - 8, 4)
raf.WriteInt(raf.Size - 44, 40)
Log(raf.size)
raf.Close
End Sub