MultiChannel Audio to Stereo Converter
This example shows how to convert five-channel audio to stereo using Simulink® Support Package for Android® Devices.
MultiChannel Audio to Stereo Converter considers several basic aspects of audio signal positioning. The listener occupies a location at the center of a circle, and the position of the sound source is varied such that it remains within the circle.
Audio spatialization is a sound panning technique of distributing a monaural source in a stereo or multichannel sound field. Spatialized audio gives the listener the impression that the audio is being played in a three-dimensional space. Audio spatialization includes two key components: direction and distance. The direction determines the channel that is playing the audio. The distance determines the volume of the audio being played.
In this example, the sound source is a monaural recording of a helicopter. The sound field is represented by five discrete speaker locations on the circumference of the circle and a low-frequency output at the center of the circle. The listener occupies a location at the center of the circle. The spatializing algorithm mixes the sound of the helicopter into six channels: front left, front center, front right, surround left, surround right, and a channel for the subwoofer.
The MultiChannel Audio to Stereo Converter then converts the multichannel audio to stereo.
Required Hardware
Android device
Headphones (recommended)
USB cable
Before you start this example, we recommend that you complete the Getting Started with Android Devices.
Task 1 - Connect the Android Device
1. Connect the Android device to your computer using the USB cable.
2. Connect a pair of headphones to the headphone jack of the device.
3. Using the Hardware Setup screen, configure the Android network.
Task 2 - Open MultiChannel Audio Simulink Model
Open the androidMultiChannelAudio
Simulink model.
The different parts of the model are described based on the functionality of the blocks used.
Audio Input
The MultiChannel Audio model accepts the position of the helicopter in two ways:
Drag the Helicopter to a Desired Position: When you perform the Monitor & Tune action in the model, with the Set Position Visually block as an input to the computeVol block, the model launches a user interface. The user interface has five discrete channels on the circumference of the circle and a low-frequency output at the center of the circle. The listener occupies a location at the center of the circle and is represented by a stick figure. Using the interface, you can change the position of the helicopter by dragging the helicopter to different locations within the circle. On changing the helicopter position, the model output gives the listener the impression that the audio is being played from the speaker that is nearest to the helicopter.
Compute Random Helicopter Positions: When you perform the Monitor & Tune action in the model, with the Set Position Randomly block as an input to the computeVol block, the randomLoc block calculates a random position of the helicopter within the circle at each sample time. The randomLoc block gives the position in Cartesian coordinates. The model output gives the listener the impression that the audio is being played from random speakers at each sample time. Unlike the Set Position Visually block, you cannot control the position of the helicopter.
Spatial Algorithm
The monaural audio source from the Audio File Read block is mixed into six channels, each of which correspond to a speaker. There is one low-frequency channel at the center of the circle and five speakers that lie on the circumference, as shown in the user interface. The following algorithm is used to determine the speaker amplitudes:
1. At the center of the circle, the amplitudes for each speaker are equal. The value for each speaker, including the low-frequency speaker, is set to 1/sqrt(5)
.
2. On the perimeter of the circle, the amplitudes of the speakers are determined using vector base amplitude panning (VBAP). This algorithm:
Determines the two speakers on either side of the source or, in the degenerate case, the single speaker.
Interprets the vectors determined by the speaker positions in (a) as basis vectors. These basis vectors to represent the normalized source position vector. The coefficients in this new basis represent the relative speaker amplitudes after normalization. For this part of the algorithm, the amplitude of the low-frequency channel is set to zero.
3. As the source moves from the center to the periphery, there is a transition from algorithm (1) to algorithm (2). This transition decays as a cubic function of the radial distance. The amplitude vectors are normalized, so the power is constant independent of source location.
4. Finally, the amplitudes decay as the distance from the center increases according to an inverse square law, such that the amplitude at the perimeter of the circle is one-quarter of the amplitude in the center.
For more details about vector base amplitude panning, see [1].
MultiChannel Converter
MultiChannel Converter block converts the five-channel audio data to stereo audio. Left channel audio data is obtained by adding front-left and rear-left audio data and subtracting the result from the center audio data. Right channel audio data is obtained by adding front-right and rear-right audio data and subtracting the result from the center audio data.
Audio Output
The Audio Playback block plays the converted stereo audio on the speaker of the device.
Task 3 - Configure the MultiChannel Audio Simulink Model
1. Go to Modeling tab and press Ctrl+E to open Configuration Parameters dialog box.
2. In the Configuration Parameters dialog box, navigate to Hardware Implementation > Hardware board and select Android Device
.
3. Go to Hardware board settings > Target hardware resources > Groups and select Device options.
4. From the Device list, select your Android device. If your device is not listed, click Refresh.
Note: If your device is not listed even after clicking Refresh, ensure that you have enabled the USB debugging option on your device. To enable USB debugging, enter androidhwsetup
in the MATLAB® Command Window and follow the onscreen instructions.
5. Click Apply. Click OK to save your changes.
Play the MultiChannel Audio from a Desired Position
1. In the MultiChannel Audio model, double-click the switch to connect the Set Position Visually block to the computeVol block.
2. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune. The lower-left corner of the model window displays status while support package generates the code. After successfully generating the code, the support package loads and runs the code on the hardware.
3. In the model, double-click the Set Position Visually block. The executable launches a user interface. The interface has five discrete channels on the circumference of the circle and a low-frequency output at the center of the circle. The listener occupies a location at the center of the circle and is represented by a stick figure. You can hear the spatialized audio through the headphones connected to the hardware. The audio appears to be played from the speaker that is located nearest to the helicopter. You can change the position of the helicopter by dragging the helicopter to different location within the circle. Observe the change in the location and the volume of the audio being played. Continue changing the position of the helicopter to observe the change in the volume of the audio at different helicopter positions.
Play the MultiChannel Audio from Random Positions
On the Hardware tab of the Simulink model, in the Mode section, Select Run on board and then click Monitor & Tune. The lower-left corner of the model window displays status as the support package generates the code. After successfully generating the code, the support package loads and runs the code on the hardware. The executable positions the helicopter at random positions within the circle and plays the spatialized audio through the headphones connected to the hardware. The audio appears to be played from random speakers at each sample time.
References
[1] Pulki, Ville. "Virtual Sound Source Positioning Using Vector Base Amplitude Panning." Journal of the Audio Engineering Society. Vol. 45, Issue 6, pp. 456-466.