The Audio Player patch combined with either the Single-Clip or Multi-Clip Controller patch can be used to connect audio clips to the speaker in your scene, and add additional complexity. For example, to:
Unlike the audio playback controller, these patches can receive pulse signals from other patches.
The graph in the image below will play an audio clip when the screen is tapped:
To play audio as soon as the effect is opened you can replace the Screen Tap patch with a Pulse patch. There are also lots of other interaction patches to choose from.
Similar behavior can be achieved with the audio playback controller. However, these patches provide inputs and outputs that can be connected to other patches to add more complexity.
Let’s take a closer look at how each patch works in this graph.
The speaker patch
This patch represents the Audio property of the speaker. To it, select the speaker in the Scene panel and click the arrow to the left of Audio in the Inspector:
It’ll receive information from the rest of the graph and play audio in the scene as a result.
The audio asset patch
This patch represents the audio file you’ve added to your project. To create this patch, drag it from the Assets panel into the Patch Editor:
The Single-Clip Controller and Audio Player patches
The Single-Clip Controller causes the the audio clip to play in response to a pulse signal from the Screen Tap patch.
The Audio Player patch connects the audio clip and the Single or Multi-Clip Controller patch to the speaker.
Create these patches using the menu in the Patch Editor.
With a Single-Clip Controller, the audio clip will stop and start again if a signal is received from the input patch while the audio clip is still playing. In this example, taps on the device screen would stop the playback and start it again from the beginning. To play overlapping audio clips in response to successive signals instead of restarting the audio clip, use the Multi-Clip Controller patch.
You can also configure the Single-Clip Controller patch to stop or loop an audio file in response to a signal, using the Stop and Loop inputs.
Below we’ve connected a Distortion patch between the Audio Player and speaker patch. This will distort the sound from the audio clip before it’s played in the scene.
There are lots of audio effect patches available to add all kinds of distortion and modifications to sounds in your effects.
In this example, the Multi-Clip Controller and Single-Clip Controller patches play the same audio clip in response to 2 different interactions:
The Screen Tap patch detects a tap on the device screen. It’s connected to a Single-Clip Controller and Audio Player patch. The Audio Player patch is then connected to a Pitch Shifter patch. This is an audio effect patch with a value that can be adjusted to change the pitch of the input sound. As a result the clip will play once when the screen is tapped, at a higher pitch. If the screen was tapped again while the sound was still playing, the clip would start from the beginning.
The Object Tap patch detects a tap on a specific object. It's connected to a Multi-Clip Controller patch. Every time the object is tapped, the clip will play. Unlike with the Single-Clip Controller, if the sound was is still playing when the object is tapped, it won't stop and start from the beginning. A new clip will play over the top of the previous one. The clip will play at the original pitch, because we haven't modified it with an audio effect patch.
There are 2 different audio clips in this example, represented by the 2 orange asset patches. Both asset patches are connected to Audio Player patches, which are then both connected to patches representing the Audio property of 2 speakers:
The Controller output port of a Single-Clip Controller is connected to the Controller input port of both Audio Player patches. This means when the screen is tapped, both audio clips play.
You can test audio effects in the Simulator. Click the gear and select Simulate Touch, then click anywhere in the Simulator. Your OS audio output settings will be used for Simulator audio playback, and you may need to re-open Spark if your system settings change.
You can also use the Spark AR Player app to test audio effects.