This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreMotion | |
// [ Elided other imports ] | |
class ViewController: UIViewController, ARSession { // [ Elided other protocols ] | |
let hmm = CMHeadphoneMotionManager() | |
var deviceTransform: simd_float4x4 = matrix_identity_float4x4; | |
var headphoneTransform: simd_float4x4 = matrix_identity_float4x4; | |
override func viewDidLoad() { | |
hmm.startDeviceMotionUpdates(to: OperationQueue.current!, withHandler: {[weak self] motion, error in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func session(_ session: ARSession, didUpdate frame: ARFrame) { | |
let transform = frame.camera.transform | |
phaseListener.transform = transform | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let distanceModelParameters = PHASEGeometricSpreadingDistanceModelParameters() | |
distanceModelParameters.fadeOutParameters = | |
PHASEDistanceModelFadeOutParameters(cullDistance: cull_distance_for_this_source) // For you to specify... | |
distanceModelParameters.rolloffFactor = rolloff_factor_for_this_source // ... as is this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let spatialPipelineFlags : PHASESpatialPipeline.Flags = [.directPathTransmission, .lateReverb] | |
let spatialPipeline = PHASESpatialPipeline(flags: spatialPipelineFlags)! | |
spatialPipeline.entries[PHASESpatialCategory.lateReverb]!.sendLevel = send_level_for_this_source; // Likewise, this is for you to decide on :-) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let spatialMixerDefinition = PHASESpatialMixerDefinition(spatialPipeline: spatialPipeline) //spatial Pipeline not yet defined | |
spatialMixerDefinition.distanceModelParameters = distanceModelParameters // distanceModelParameters not yet defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mesh = MDLMesh.newIcosahedron(withRadius: 2.0, inwardNormals: false, allocator: nil) | |
let shape = PHASEShape(engine: phaseEngine, mesh: mesh) | |
let source = PHASESource(engine: phaseEngine, shapes: [shape]) | |
source.transform = the_position_of_the_object_in_our_world // you'll need to provide this :-) | |
try! phaseEngine.rootObject.addChild(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mixerParameters = PHASEMixerParameters() | |
mixerParameters.addSpatialMixerParameters( | |
identifier: phaseSpatialMixerDefinition.identifier, //phaseSpatialMixerDefinition not yet defined | |
source: source, listener: phaseListener // source not yet defined | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let samplerNodeDefinition = PHASESamplerNodeDefinition( | |
soundAssetIdentifier: "a_unique_asset_identifier", | |
mixerDefinition: phaseSpatialMixerDefinition! // As yet undefined | |
) | |
samplerNodeDefinition.playbackMode = .looping | |
samplerNodeDefinition.setCalibrationMode( | |
calibrationMode: .relativeSpl, level: 12 | |
) | |
samplerNodeDefinition.cullOption = .sleepWakeAtRealtimeOffset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try! phaseEngine.assetRegistry.registerSoundAsset( | |
url: url, identifier: "a_unique_asset_identifier", | |
assetType: .resident, channelLayout: nil, | |
normalizationMode: .dynamic | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fileName = "piano" // piano.mp3 in the app bundle root. | |
let url = Bundle.main.url(forResource: fileName, withExtension: "mp3")! |
NewerOlder