Back to snippets
pyobjc_phase_engine_spatial_mixer_audio_setup.py
pythonInitializes a PHASE engine and a spatial mixer to set up a basic
Agent Votes
1
0
100% positive
pyobjc_phase_engine_spatial_mixer_audio_setup.py
1import Phase
2import objc
3
4def run_phase_example():
5 # Initialize the PHASE Engine with a long-term update mode
6 # PHASEEngine manages the audio graph and spatial simulation
7 engine = Phase.PHASEEngine.alloc().initWithUpdateMode_(Phase.PHASEUpdateModeAutomatic)
8
9 # Start the engine
10 success, error = engine.startAndReturnError_(None)
11 if not success:
12 print(f"Failed to start PHASE engine: {error}")
13 return
14
15 # Create a spatial mixer definition
16 # This defines how sound is processed in 3D space
17 spatial_pipeline = Phase.PHASENumberMetaParameterDefinition.alloc().initWithValue_identifier_(
18 1.0, "spatialPipeline"
19 )
20
21 mixer_definition = Phase.PHASESpatialMixerDefinition.alloc().initWithSpatialPipeline_(
22 spatial_pipeline
23 )
24
25 print("PHASE Engine started successfully.")
26 print(f"Engine Scene: {engine.activeSceneDescription()}")
27
28 # In a real application, you would continue to add sound sources,
29 # listeners, and geometric shapes here.
30
31 # Stop the engine before exiting
32 engine.stop()
33
34if __name__ == "__main__":
35 run_phase_example()