Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Audio Plugin, MBS Tools Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/LTC/LTC Test
This example is the version from Sat, 14th Feb 2020.
Project "LTC Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
// we keep library here:
// https://www.monkeybreadsoftware.de/xojo/download/plugin/Libs/
Dim f As FolderItem
#If TargetMacOS Then
// MacOS
f = GetFolderItem("libltc.mac.dylib")
#ElseIf TargetWin32 Then
// Windows
#If Target64Bit Then
f = GetFolderItem("libltcWin64.dll")
#Else
f = GetFolderItem("libltcWin32.dll")
#EndIf
#Else
// Linux
f = GetFolderItem("libltc.so")
#EndIf
If LTCMBS.LoadLibrary(f) Then
// okay
Else
MsgBox LTCMBS.LibraryLoadErrorMessage
Quit
End If
End EventHandler
End Class
Class MainWindow Inherits Window
Control LogList Inherits Listbox
ControlInstance LogList Inherits Listbox
End Control
Control PlayButton Inherits PushButton
ControlInstance PlayButton Inherits PushButton
EventHandler Sub Action()
If ps <> Nil Then
Call ps.stop
ps = Nil
End If
Const fps = 25
Const sampleRate = 48000
Dim deviceInfo As PortAudioDeviceInfoMBS = PopupDevice.RowTag(PopupDevice.ListIndex)
Dim pasp As New PortAudioStreamParametersMBS
pasp.ChannelCount = 1
pasp.Device = deviceInfo.Index
pasp.SampleFormat = pasp.paFloat32 ' PortAudioStreamBufferedMBS needs float pasp.paUInt8
pasp.SuggestedLatency = 0.2
ps = New PortAudioStreamBufferedMBS
Dim e As Integer = ps.OpenStream(pasp, sampleRate, 0, 0)
Log "OpenDefaultStream: "+Str(e)
if e <> 0 then return
Dim st As New LTCSMPTETimecodeMBS
st.timezone = "+0100"
st.date = New date // now
st.Frame = 0
//* prepare encoder */
Dim TVStandard As Integer = If (fps = 25, LTCMBS.LTC_TV_625_50, LTCMBS.LTC_TV_525_60)
encoder = New LTCEncoderMBS(sampleRate, fps, TVStandard, LTCMBS.LTC_USE_DATE)
encoder.TimeCode = st
//* ready To go, Print some info first */
Log "sample rate: " + Str(sampleRate)
Log "frames/sec: " + Str(fps)
Log "sample format: 8bit unsigned mono"
SendTimecode
SendTimecode
SendTimecode
SendTimer.mode = timer.ModeMultiple
e = ps.Start
Log "Start: "+Str(e)
StopButton.Enabled = True
End EventHandler
End Control
Control PopupDevice Inherits PopupMenu
ControlInstance PopupDevice Inherits PopupMenu
EventHandler Sub Change()
If Me.ListIndex >= 0 Then
PlayButton.Enabled = True
End If
End EventHandler
End Control
Control StopButton Inherits PushButton
ControlInstance StopButton Inherits PushButton
EventHandler Sub Action()
If ps <> Nil Then
Call ps.Stop
End If
End EventHandler
End Control
Control SendTimer Inherits Timer
ControlInstance SendTimer Inherits Timer
EventHandler Sub Action()
SendTimecode
End EventHandler
End Control
EventHandler Sub Open()
po = New PortAudioMBS
'For i As Integer = 1 To 100
TestLTCEncoder
TestLTCDecoder
'Next
FillDeviceList
End EventHandler
Sub FillDeviceList()
Dim DefaultOutputDeviceID As Integer = po.DefaultOutputDeviceID
Dim PopupDeviceIndex As Integer
Dim HostApiCount As Integer = po.HostApiCount-1
For HostApiIndex As Integer = 0 To HostApiCount
Dim host As PortAudioHostApiInfoMBS = po.HostApiInfo(HostApiIndex)
If host<>Nil Then
Dim HostDeviceCount As Integer = host.deviceCount-1
For HostDeviceIndex As Integer = 0 To HostDeviceCount
Dim DeviceIndex As Integer = po.HostApiDeviceIndexToDeviceIndex(host.Index, HostDeviceIndex)
Dim deviceInfo As PortAudioDeviceInfoMBS = po.DeviceInfo(DeviceIndex)
If deviceInfo.maxOutputChannels > 0 Then
PopupDevice.AddRow host.Name+": "+deviceInfo.Name
PopupDevice.RowTag(PopupDeviceIndex) = deviceInfo
If DeviceIndex = DefaultOutputDeviceID Then
PopupDevice.ListIndex = PopupDeviceIndex
End If
PopupDeviceIndex = PopupDeviceIndex + 1
End If
Next
End If
Next
End Sub
Sub SendTimecode()
// send a second of timecode
Dim vframe_cnt As Integer = 0
Dim vframe_last As Integer = 25 // 25 fps
Dim Total As Integer
While (vframe_cnt < vframe_last)
encoder.EncodeFrame
// we use string to avoid conversion from MemoryBlock to string
Dim m As MemoryBlock = encoder.CopyBuffer
Call ps.AddAudio(m, 0, m.size, 8, False)
Call encoder.IncrementTimecode
vframe_cnt = vframe_cnt + 1
Wend
End Sub
Sub TestLTCDecoder()
Dim f As FolderItem = SpecialFolder.Desktop.Child("ltctest")
Dim b As BinaryStream = BinaryStream.open(f)
Dim apv As Integer = 1920 // = 48000 / 25
Dim total As UInt64
total = 0
Dim decoder As New LTCDecoderMBS(apv, 32)
Dim frame As New LTCFrameExtMBS
Dim stime As New LTCSMPTETimecodeMBS
While Not b.EOF
Dim sound As String = b.Read(10000)
Dim n As Integer = LenB(sound)
decoder.WriteUInt8(sound, total)
While decoder.read(frame)
LTCMBS.FrameToTime(stime, frame, LTCMBS.LTC_USE_DATE)
dim d as date = stime.Date
Dim l1 As String = d.SQLDateTime
Dim year As Integer = If((stime.years < 67), 2000+stime.years, 1900+stime.years)
Dim l2 As String = Str(year, "0000")+"-"+_
Str(stime.months, "00")+"-"+_
Str(stime.days, "00")+" "+_
stime.TimeZone
Dim l3 As String = Str(stime.Hours, "00")+":"+_
Str(stime.mins, "00")+":"+_
Str(stime.secs, "00")+_
If (frame.dfbit = 1, ".", ":")+_
Str(stime.frame, "00")+" | "+_
Str(frame.offStart, "00000000")+" "+_
Str(frame.offEnd, "00000000")+" "+_
If (frame.reverse = 1, " R", "")
Log l1+" "+l2+" "+l3
Wend
total = total + n
Wend
End Sub
Sub TestLTCEncoder()
Dim length As Double = 2 // in seconds
Dim fps As Double = 25
Dim sampleRate As Double = 48000
Dim st As New LTCSMPTETimecodeMBS
st.timezone = "+0100"
st.years = 8
st.months = 12
st.days = 31
st.hours = 23
st.mins = 59
st.secs = 59
st.frame = 0
Dim f As FolderItem = SpecialFolder.Desktop.Child("ltctest")
Dim b As BinaryStream = BinaryStream.Create(f, True)
//* prepare encoder */
Dim TVStandard As Integer = If (fps = 25, LTCMBS.LTC_TV_625_50, LTCMBS.LTC_TV_525_60)
Dim encoder As New LTCEncoderMBS(sampleRate, fps, TVStandard, LTCMBS.LTC_USE_DATE)
encoder.TimeCode = st
//* ready To go, Print some info first */
Log "sample rate: " + Str(sampleRate)
Log "frames/sec: " + Str(fps)
Log "secs to write: " + Str(length)
Log "sample format: 8bit unsigned mono"
Dim vframe_cnt As Integer = 0
Dim vframe_last As Integer = length * fps
Dim Total As Integer
While (vframe_cnt < vframe_last)
encoder.EncodeFrame
// we use string to avoid conversion from MemoryBlock to string
Dim m As String = encoder.CopyBufferString
b.Write m
total = total + m.LenB
'Dim m As MemoryBlock = encoder.CopyBuffer
'
'If m.size > 0 then
'b.Write m
'total = total + m.size
'End If
Call encoder.IncrementTimecode
vframe_cnt = vframe_cnt + 1
Wend
b.Close
encoder = Nil
Log "Done: wrote "+Str(Total) +" samples to file."
End Sub
Sub log(s as string)
System.DebugLog s
LogList.AddRow s
End Sub
Property encoder As LTCEncoderMBS
Property po As PortAudioMBS
Property ps As PortAudioStreamBufferedMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS Tools Plugin.