6.1-roAudioPlayer

ON THIS PAGE


An audio player is used to play back audio files using the generic ifMediaTransport interface. If the message port is set, the object will send events of the type roAudioEvent. All object calls are asynchronous. In other words, audio playback is handled in a different thread from the script. The script may continue to run while audio is playing.

IfIdentity

GetIdentity() As Integer

ifMessagePort

SetPort(As Object) As Void
SetPort(a As Object)

ifUserData

SetUserData(user_data As Object)

Sets the user data that will be returned when events are raised.

GetUserData() As Object

Returns the user data that has previously been set via SetUserData(). It will return Invalid if no data has been set.

ifMediaTransport 

See roVideoPlayer for a description of ifMediaTransport methods.

ifAudioControl

SetPcmAudioOutputs(outputs As roArray) As Boolean

Specifies which audio connectors should output PCM audio. This method accepts one or more outputs in the form of an roArray of roAudioOutput instances.

SetCompressedAudioOutputs(outputs As roArray) As Boolean

Specifies which audio connectors should output compressed audio (e.g. Dolby AC3 encoded audio). This method accepts one or more outputs in the form of an roArray of roAudioOutput instances. When one or both of the above output methods are called, they will override the settings of the following ifAudioControl methods: SetAudioOutput(), MapStereoOutput(), SetUsbAudioPort(), MapDigitalOutput().

SetMultichannelAudioOutputs(array As Object) As Boolean
 
SetAudioOutput(audio_output As Integer) As Boolean
 
SetAudioMode(audio_mode As Integer) As Boolean
 
MapStereoOutput(mapping As Integer) As Boolean
 
MapDigitalOutput(mapping As Integer) As Boolean
 
SetVolume(volume As Dynamic) As Boolean

Specifies the volume of the audio output as either a percentage or decibel amount. To use a percentage measurement, pass an integer value between 0 and 100. To use a decibel measurement, pass an roAssociativeArray containing a single {db:<value As Float>} parameter. The decibel measurement is an absolute value: passing 0 specifies no change to the audio output, and the effective range of measurements is from aprroximately -80 to 20 decibels.

SetChannelVolumes(channel_mask As Integer, volume As Integer) As Boolean
 
SetUsbAudioPort(a As Integer) As Boolean
 
SetSpdifMute(a As Boolean) As Boolean
 
StoreEncryptionKey(a As String, b As String) As Boolean
 
StoreObfuscatedEncryptionKey(a As String, b As String) As Boolean
 
SetStereoMappingSpan(a As Integer) As Boolean
 
ConfigureAudioResources() As Boolean
 
SetAudioStream(stream_index As Integer) As Boolean
 
SetAudioDelay(delay_in_milliseconds As Integer) As Boolean

Adds a presentation time stamp (PTS) offset to the audio. This makes it possible to adjust for file multiplexing differences. Delays are limited to 150ms or less. Currently, the system software only supports positive delays; therefore, if you need to set the audio ahead of the video, you will need to use SetVideoDelay() instead.

SetVideoDelay(delay_in_milliseconds As Integer) As Boolean

Adds a presentation time stamp (PTS) offset to the video. This makes it possible to adjust for file multiplexing differences. Delays are limited to 150ms or less.
 

HD2000 Only:

SetAudioOutputAux(audio_output As Integer) As Boolean
 
SetAudioModeAux(audio_mode As Integer) As Boolean
 
MapStereoOutputAux(mapping As Integer) As BooleanSetVolumeAux(volume As Integer) As Boolean
 
SetChannelVolumesAux(channel_mask As Integer, volume As Integer) As Boolean
 
SetAudioStreamAux(stream_index As Integer) As Boolean

 


 

If a video file is playing or has played, you need to call roVideoPlayer.Stop() before changing the audio output.

The following script shows how to use the SetPcmAudioOutputs() and SetCompressedAudioOutputs() methods in conjunction with roAudioOutput. The video player is configured to output decoded audio to the analog output or compressed audio to the HDMI and SPDIF outputs.

ao1=CreateObject("roAudioOutput", "Analog")
ao2=CreateObject("roAudioOutput", "HDMI")
ao3=CreateObject("roAudioOutput", "SPDIF")


v1=CreateObject("roVideoPlayer")
v1.SetPcmAudioOutputs(ao1)

--or--

ar = CreateObject("roArray", 2, true)
ar[0] = ao2
ar[1] = ao3
v1.SetCompressedAudioOutputs(ar)

In most cases, rerouting audio outputs during audio/video playback will cause playback to stop. The system software will still be responsive, so you can use commands to exit playback during or following an audio output modification.

audio_output values

0 – Analog audio
1 – USB audio
2 – Digital audio, stereo PCM
3 – Digital audio, raw AC3
4 – Onboard analog audio with HDMI mirroring raw AC3

digital audio values

0 – Onboard HDMI
1 – SPDIF from expansion module

audio_mode values

Options 0 and 1 only apply to video files, while option 2 applies to all audio sources.
0 – AC3 Surround
1 – AC3 mixed down to stereo
2 – No audio
3 – Left
4 – Right

mapping  values

Use mapping values to select which analog output to use if audio_output is set to 0.
0 – Stereo audio is mapped to onboard analog output
1 – Stereo audio is mapped to expansion module leftmost output
2 – Stereo audio is mapped to expansion module middle output
3 – Stereo audio is mapped to expansion module rightmost output

set_volume

Volume functions as a percentage and therefore takes a value between 0-100. The volume value is clipped prior to use (i.e. SetVoume(101) will set the volume to 100 and return True). The volume is the same for all mapped outputs and USB/SPDIF/analog.

Separate volume levels are stored for roAudioPlayer and roVideoPlayer.

 

set_channel_volumes

You can control the volume of individual audio channels. This volume command takes a hex channel mask, which determines the channels to apply the volume to, and a level, which is a percentage of the full scale. The volume control works according to audio channel rather than the output. The channel mask is a bit mask with the following bits for MP3 output:

  • &H01 Left
  • &H02 Right
  • &H03 Both left and right

 

This code sets audio output to the rightmost expansion module audio port.

 

video = CreateObject("roVideoPlayer")
video.SetAudioOutput(0)              
video.MapStereoOutput(3) 

 

This code sets the volume level for individual channels.

audio = CreateObject("roAudioPlayer")
audio.SetChannelVolumes(&H01, 60)      'left channel to 60%
audio.SetChannelVolumes(&H02, 75)      'right channel to 75%
audio.SetChannelVolumes(&H03, 65)      'all channels to 65%

Playing Multiple Audio Files Simultaneously

Multiple MP3 files, as well as the audio track of a video file, can be played to any combination of the following:

  • Analog outputs
  • SPDIF / HDMI
  • USB

Only a single file can be sent to an output at any given time. For example, two roAudioPlayers cannot simultaneously play to the SPDIF output. The second one to attempt a PlayFile will get an error. To free an output, the audio or video stream must be stopped (using the ifMediaTransport Stop or StopClear calls).

Note the following about multiple audio-file functionality:

  • The onboard analog audio output and HDMI output are clocked by the same sample-rate clock. Therefore, if different content is being played out of each, the content must have the same sample rate.
  • Currently, only a single set of USB speakers is supported.
  • Each audio and video stream played consumes some of the finite CPU resources. The amount consumed depends on the bitrates of the streams. Testing is the only way to determine whether a given set of audio files can be played at the same time as a video. The maximum recommended usage is a 16Mbps video file with three simultaneous MP3 160kbps streams.

This code plays a video with audio over HDMI and an MP3 file to the onboard analog port.

video=CreateObject("roVideoPlayer")

video.SetAudioOutput(3)              
video.PlayFile("video.mpg")

audio=CreateObject("roAudioPlayer")

audio.MapStereoOutput(0)
audio.PlayFile("audio.mp3")

 

Â