{"_id":"5b4e90b9d9ea0b00031c6184","category":{"_id":"5b4e90b9d9ea0b00031c615e","project":"5a065a6134873d0010b396ab","version":"5b4e90b9d9ea0b00031c6194","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2018-05-24T14:46:44.164Z","from_sync":false,"order":3,"slug":"enhanced-scenes","title":"Enhanced Scenes"},"parentDoc":null,"project":"5a065a6134873d0010b396ab","user":"578c4a62bd223d2000cc143e","version":{"_id":"5b4e90b9d9ea0b00031c6194","project":"5a065a6134873d0010b396ab","__v":0,"forked_from":"5b3678bdbb84cb0003b1d8db","createdAt":"2018-04-18T18:19:34.288Z","releaseDate":"2018-04-18T18:19:34.288Z","categories":["5b4e90b9d9ea0b00031c6159","5b4e90b9d9ea0b00031c615a","5b4e90b9d9ea0b00031c615b","5b05923ea5a2f9000357b452","5b05f793c2c86c0003cbe414","5b4e90b9d9ea0b00031c615c","5b4e90b9d9ea0b00031c615d","5b4e90b9d9ea0b00031c615e"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.8.2","version":"1.8.2"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-07-18T20:16:13.167Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"Viro supports three forms of audio: stereo sound, spatial sound, and ambisonic sound fields. Sprinkling environments with sound helps to add true immersion to your scenes; they draw the listener's attention and provide cues on where to look next. Viro supports three forms of sound.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Stereo Sound\"\n}\n[/block]\nMany scenes benefit from having a background sound track, either in the form of music or ambient noise like wind or ocean waves. You can add background audio to your scene by utilizing the [Sound](https://developer.viromedia.com/virocore/reference/com/viro/core/Sound.html) object. The audio to be played is specified with a URI, as in the following example. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Sound sound = new Sound(context, Uri.parse(\\\"http://www.website.com/mysound.mp3\\\"), null);\\nsound.setLoop(true);\\nsound.setVolume(1.0);\\nsound.play();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSound can also be used for short sound effects. To replay such a sound, either set ```loop``` to true, or toggle between ```pause()``` and ```play()```. Finally, these sounds also provide callbacks via the [PlaybackListener](https://developer.viromedia.com/virocore/reference/com/viro/core/Sound.PlaybackListener.html).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Spatial Sound\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Not supported on iOS\",\n  \"body\": \"Spatial sound is currently supported on Cardboard (Android), Daydream, and Gear VR\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Mono sounds only\",\n  \"body\": \"Spatial sound only works with single-channel sounds.\"\n}\n[/block]\n\nSpatial sound is positioned audio that can travel throughout a scene. For example, you can create a spatial sound that animates along with a bird, chirping as it flies through the scene. To create spatial sounds, use [SpatialSound](https://developer.viromedia.com/virocore/reference/com/viro/core/SpatialSound.html). This component supports all the properties of Sound, and adds new properties that define how the sound travels.\n\nThe new properties are:\n\n* ```position``` indicates the position of the sound within the coordinate space of its parent node\n* ```distanceRolloff``` specifies the distance from the sound at which it starts and ends attenuating, and the curve of the attenuation\n\nMost importantly, SpatialSounds can be attached to Nodes in the scene graph, and can be animated along with visual objects. In the example below, the 'chirp' sound follows the bird 3D object. We can do this by adding both the sound and the 3D object to the same node. Then we simply have to animate this parent node.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SpatialSound chirp = new SpatialSound(context, Uri.parse(\\\"chirp.mp3\\\"), null);\\nchirp.setLoop(true);\\n\\nObject3D bird = new Objec3D();\\nbird.loadModel(Uri.parse(\\\"bird.vrx\\\"), Type.FBX, new AsyncObject3DListener() {\\n    public void onObject3DFailed(String error) {\\n        Log.w(TAG, \\\"Failed to load the model\\\");\\n    }\\n    public void onObject3DLoaded(Object3D object, Object3D.Type type)\\n        // Start chirping after the bird is loaded\\n  \\t    chirp.play();\\n    }  \\n));\\n\\nNode node = new Node();\\nnode.addChildNode(bird);\\nnode.addSound(chirp);\\n\\n// Animate the bird to the right; this will animate the chirp sound as well\\nAnimationTransaction.begin();\\nAnimationTransaction.setAnimationDuration(5000);\\nnode.setPosition(new Vector(10, 0, 0));\\nAnimationTransaction.commit();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Ambisonic Sound Fields\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Not supported on iOS\",\n  \"body\": \"Ambisonic sound fields are currently supported on Cardboard (Android), Daydream, and GearVR\"\n}\n[/block]\nAmbisonic sound fields emit environmental sound from every direction. They are the audio equivalent of a skybox or 360 image, providing atmospheric background noise. These sounds respond to the user's head rotation.\n\nProducing ambisonic sound is beyond the scope of this document, but if you have ambisonic sound files, you can load them into Viro via the [SoundField](https://developer.viromedia.com/virocore/reference/com/viro/core/SoundField.html) object. This object shares the same properties as Sound, and can additionally be rotated about the Z axis with the ```rotation``` property. Reverb properties for SoundField can also be set to simulate various environments and materials.","excerpt":"Adding audio to your scenes","slug":"audio","type":"basic","title":"Sound"}

Sound

Adding audio to your scenes

Viro supports three forms of audio: stereo sound, spatial sound, and ambisonic sound fields. Sprinkling environments with sound helps to add true immersion to your scenes; they draw the listener's attention and provide cues on where to look next. Viro supports three forms of sound. [block:api-header] { "type": "basic", "title": "Stereo Sound" } [/block] Many scenes benefit from having a background sound track, either in the form of music or ambient noise like wind or ocean waves. You can add background audio to your scene by utilizing the [Sound](https://developer.viromedia.com/virocore/reference/com/viro/core/Sound.html) object. The audio to be played is specified with a URI, as in the following example. [block:code] { "codes": [ { "code": "Sound sound = new Sound(context, Uri.parse(\"http://www.website.com/mysound.mp3\"), null);\nsound.setLoop(true);\nsound.setVolume(1.0);\nsound.play();", "language": "java" } ] } [/block] Sound can also be used for short sound effects. To replay such a sound, either set ```loop``` to true, or toggle between ```pause()``` and ```play()```. Finally, these sounds also provide callbacks via the [PlaybackListener](https://developer.viromedia.com/virocore/reference/com/viro/core/Sound.PlaybackListener.html). [block:api-header] { "type": "basic", "title": "Spatial Sound" } [/block] [block:callout] { "type": "info", "title": "Not supported on iOS", "body": "Spatial sound is currently supported on Cardboard (Android), Daydream, and Gear VR" } [/block] [block:callout] { "type": "info", "title": "Mono sounds only", "body": "Spatial sound only works with single-channel sounds." } [/block] Spatial sound is positioned audio that can travel throughout a scene. For example, you can create a spatial sound that animates along with a bird, chirping as it flies through the scene. To create spatial sounds, use [SpatialSound](https://developer.viromedia.com/virocore/reference/com/viro/core/SpatialSound.html). This component supports all the properties of Sound, and adds new properties that define how the sound travels. The new properties are: * ```position``` indicates the position of the sound within the coordinate space of its parent node * ```distanceRolloff``` specifies the distance from the sound at which it starts and ends attenuating, and the curve of the attenuation Most importantly, SpatialSounds can be attached to Nodes in the scene graph, and can be animated along with visual objects. In the example below, the 'chirp' sound follows the bird 3D object. We can do this by adding both the sound and the 3D object to the same node. Then we simply have to animate this parent node. [block:code] { "codes": [ { "code": "SpatialSound chirp = new SpatialSound(context, Uri.parse(\"chirp.mp3\"), null);\nchirp.setLoop(true);\n\nObject3D bird = new Objec3D();\nbird.loadModel(Uri.parse(\"bird.vrx\"), Type.FBX, new AsyncObject3DListener() {\n public void onObject3DFailed(String error) {\n Log.w(TAG, \"Failed to load the model\");\n }\n public void onObject3DLoaded(Object3D object, Object3D.Type type)\n // Start chirping after the bird is loaded\n \t chirp.play();\n } \n));\n\nNode node = new Node();\nnode.addChildNode(bird);\nnode.addSound(chirp);\n\n// Animate the bird to the right; this will animate the chirp sound as well\nAnimationTransaction.begin();\nAnimationTransaction.setAnimationDuration(5000);\nnode.setPosition(new Vector(10, 0, 0));\nAnimationTransaction.commit();", "language": "java" } ] } [/block] [block:api-header] { "title": "Ambisonic Sound Fields" } [/block] [block:callout] { "type": "info", "title": "Not supported on iOS", "body": "Ambisonic sound fields are currently supported on Cardboard (Android), Daydream, and GearVR" } [/block] Ambisonic sound fields emit environmental sound from every direction. They are the audio equivalent of a skybox or 360 image, providing atmospheric background noise. These sounds respond to the user's head rotation. Producing ambisonic sound is beyond the scope of this document, but if you have ambisonic sound files, you can load them into Viro via the [SoundField](https://developer.viromedia.com/virocore/reference/com/viro/core/SoundField.html) object. This object shares the same properties as Sound, and can additionally be rotated about the Z axis with the ```rotation``` property. Reverb properties for SoundField can also be set to simulate various environments and materials.