Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/AudioPlayThru Old
This example is the version from Sun, 17th Mar 2012.
Project "AudioPlayThru Old.xojo_binary_project"
Class App Inherits Application
EventHandler Sub Open()
'Audio Play Thru Example by Jay Lichtenauer
'jay@macinmind.com
End EventHandler
End Class
Class Window1 Inherits Window
Control MicOutPopup Inherits PopupMenu
ControlInstance MicOutPopup Inherits PopupMenu
End Control
Control MicInPopup Inherits PopupMenu
ControlInstance MicInPopup Inherits PopupMenu
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
if a<>nil then
me.Caption="Play Thru"
a.stop
if a.Lasterror<>0 then
MsgBox "Error "+str(a.Lasterror)+" on Stop method!?"
end if
a=nil // kill it
Else
me.Caption="Stop"
' for default buffer size:
'a=new AudioPlayThruMBS(MicInDeviceIDs(MicInPopup.ListIndex),MicOutDeviceIDs(MicOutPopup.ListIndex))
a=new AudioPlayThruMBS(MicInDeviceIDs(MicInPopup.ListIndex),MicOutDeviceIDs(MicOutPopup.ListIndex),100000)
if a.lasterror<>0 then
MsgBox "Failed to create connection. "+str(a.Lasterror)
a=nil // failed
else
a.Start
if a.Lasterror<>0 then
MsgBox "Error "+str(a.Lasterror)+" on Start method!?"
end if
end if
End if
End EventHandler
End Control
EventHandler Sub Open()
const kAudioHardwarePropertyDevices="dev#"
const kAudioDevicePropertyDeviceName = "name"
Dim m,ids as MemoryBlock
Dim numDevices,outSize,i,id as integer
Dim deviceName as string
dim outWriteable as boolean
Dim isInput as Boolean
Dim c as CoreAudioMBS
Dim micInSel,micOutSel as integer
if TargetMachO then
else
MsgBox "This example is only for Mac OS X in MachO applications"
end if
c = new CoreAudioMBS
'MsgBox c.kAudioHardwarePropertyDevices
c.AudioHardwareGetPropertyInfo kAudioHardwarePropertyDevices, outSize, outWriteable
ids=c.AudioHardwareGetPropertyMemory(kAudioHardwarePropertyDevices)
numDevices = outSize / 4
//Get the default input and output device IDs
m=c.AudioHardwareGetPropertyMemory(c.kAudioHardwarePropertyDefaultInputDevice)
micInSel=m.Long(0)
m=c.AudioHardwareGetPropertyMemory(c.kAudioHardwarePropertyDefaultOutputDevice)
micOutSel=m.Long(0)
// Get the device IDs for each device
ids=c.AudioHardwareGetPropertyMemory(kAudioHardwarePropertyDevices)
for i=0 to numDevices-1
id=ids.Long(i*4) // 4 bytes per integer
m=c.AudioDeviceGetPropertyMemory(id, 0, false, kAudioDevicePropertyDeviceName)
if m<>nil then
deviceName=m.CString(0)
'MsgBox deviceName+":"+str(id)
End if
//Determine whether our device supports input and/or output.
//If format is "" then it doesn't support it.
if c.AudioDeviceGetPropertyString(id, 0, true, c.kAudioDevicePropertyStreamFormat)<>"" then
MicInPopup.AddRow deviceName
micInDeviceIDs.Append id
if id=micInSel then
MicInPopup.ListIndex=MicInPopup.ListCount-1
End if
End if
if c.AudioDeviceGetPropertyString(id, 0, false, c.kAudioDevicePropertyStreamFormat)<>"" then
MicOutPopup.AddRow deviceName
micOutDeviceIDs.Append id
if id=micOutSel then
MicOutPopup.ListIndex=MicOutPopup.ListCount-1
End if
End if
Next
End EventHandler
Property MicInDeviceIDs() As Integer
Property MicOutDeviceIDs() As Integer
Property Protected a As audioPlayThruMBS
Property c As coreAudioMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
End MenuBar
End Project
The items on this page are in the following plugins: MBS MacOSX Plugin.