Qt 5.13 | Qt Multimedia | QML Types | Sound QML Type

Qt 5.13.2 Reference Documentation

# Sound QML Type

Define a variety of samples and parameters to be used for SoundInstance. More...

Import Statement: | import QtAudioEngine 1.13
Since: | Qt 5.0

- List of all members, including inherited members

## Properties

- attenuationModel : string
- category : string
- cone.innerAngle : real
- cone.outerAngle : real
- cone.outerGain : real
- name : string
- playType : enumeration

## Methods

- addPlayVariation(playVariation)
- QtAudioEngine::SoundInstance newInstance()
- play(position, velocity, direction, gain, pitch)
- play(position, velocity, gain, pitch)
- play(position, gain, pitch)
- play(position, velocity, direction, gain)
- play(position, velocity, gain)
- play(position, gain)
- play(position, velocity, direction)
- play(position, velocity)
- play(position)
- play(gain, pitch)
- play(gain)
- play()

## Detailed Description

Sound can be accessed through QtAudioEngine::AudioEngine::sounds with its unique name and must be defined inside AudioEngine or be added to it using AudioEngine.addSound() if Sound is created dynamically.

      Rectangle {
          color:"white"
          width: 300
          height: 500

          AudioEngine {
              id:audioengine

              AudioSample {
                  name:"explosion01"
                  source: "explosion-01.wav"
              }

              AudioSample {
                  name:"explosion02"
                  source: "explosion-02.wav"
              }

              Sound {
                  name:"explosion"
                  playType: Sound.Random
                  PlayVariation {
                      sample:"explosion01"
                      minPitch: 0.8
                      maxPitch: 1.1
                  }
                  PlayVariation {
                      sample:"explosion02"
                      minGain: 1.1
                      maxGain: 1.5
                  }
              }
          }
          MouseArea {
              anchors.fill: parent
              onPressed: {
                  audioengine.sounds["explosion"].play();
              }
          }
      }

## Property Documentation

attenuationModel : string

This property specifies which attenuation model this sound will apply.

category : string

This property specifies which AudioCategory this sound belongs to.

cone.innerAngle : real

This property holds the innerAngle for Sound definition. The range is [0, 360] degree. There is no directional attenuation within innerAngle.

cone.outerAngle : real

This property holds the outerAngle for Sound definition. The range is [0, 360] degree. All audio output from this sound will be attenuated by outerGain outside outerAngle.

cone.outerGain : real

This property holds attenuation value for directional attenuation of this sound. The range is [0, 1]. All audio output from this sound will be attenuated by outerGain outside outerAngle.

name : string

This property holds the name of Sound, must be unique among all sounds and only defined once.

playType : enumeration

This property holds the playType. It can be one of:

- Random - randomly picks up a play variation when playback is triggered
- Sequential - plays each variation in sequence when playback is triggered

The default value is Random.

## Method Documentation

addPlayVariation(playVariation)

Adds the given playVariation to sound. This can be used when the PlayVariation is created dynamically:

      import QtAudioEngine 1.1

      AudioEngine {
          id: engine

          Component.onCompleted: {
              var playVariation = Qt.createQmlObject('import QtAudioEngine 1.1; PlayVariation {}', engine);
              playVariation.sample = "sample";
              playVariation.minPitch = 0.8
              playVariation.maxPitch = 1.1

              var sound = Qt.createQmlObject('import QtAudioEngine 1.1; Sound {}', engine);
              sound.name = "example";
              sound.addPlayVariation(playVariation);
              engine.addSound(sound);
          }
      }

QtAudioEngine::SoundInstance newInstance()

Returns a new SoundInstance.

play(position, velocity, direction, gain, pitch)

Creates a new SoundInstance and starts playing with specified position, velocity, direction, adjusted gain and pitch.

play(position, velocity, gain, pitch)

Creates a new SoundInstance and starts playing with specified position, velocity, adjusted gain and pitch. Direction is set to `"0,0,0"`.

play(position, gain, pitch)

Creates a new SoundInstance and starts playing with specified position, adjusted gain and pitch. Direction and velocity are all set to `"0,0,0"`.

play(position, velocity, direction, gain)

Creates a new SoundInstance and starts playing with specified position, velocity, direction and adjusted gain.

play(position, velocity, gain)

Creates a new SoundInstance and starts playing with specified position, velocity and adjusted gain. Direction is set to `"0,0,0"`.

play(position, gain)

Creates a new SoundInstance and starts playing with specified position and adjusted gain. Direction and velocity are all set to `"0,0,0"`.

play(position, velocity, direction)

Creates a new SoundInstance and starts playing with specified position, velocity and direction.

play(position, velocity)

Creates a new SoundInstance and starts playing with specified position and velocity. Direction is set to `"0,0,0"`.

play(position)

Creates a new SoundInstance and starts playing with specified position. Direction and velocity are all set to `"0,0,0"`.

play(gain, pitch)

Creates a new SoundInstance and starts playing with the adjusted gain and pitch. Position, direction and velocity are all set to `"0,0,0"`.

play(gain)

Creates a new SoundInstance and starts playing with the adjusted gain. Position, direction and velocity are all set to `"0,0,0"`.

play()

Creates a new SoundInstance and starts playing. Position, direction and velocity are all set to `"0,0,0"`.