# llLoopSoundMaster

*LSL function*

```lsl
void llLoopSoundMaster(string sound, float volume);
```

- `string sound`: Name of a sound in the prim's inventory, or a UUID.
- `float volume`: Volume level to set, between 0.0 (silent) and 1.0 (loud).

- Energy: 10

Plays the attached sound looping indefinitely at the specified volume and declares it a Sync Master, forcing slave sounds to synchronize with it.

Plays attached **sound** looping at **volume**, declares it a sync master.

```lsl title="How to use" frame="terminal"
llLoopSoundMaster("", 0.0);
```

## Caveats

- This function is affected by the [Sound Queueing](/functions/llSetSoundQueueing/) property of the parent prim - this means it's possible to queue a slave sound prior to starting a master, without having to use more than one prim as an emitter. (See below).

## Examples

<details open>
<summary>Example 1</summary>

```lsl
// for an uploaded .wav file called "MasterLoop" in inventory
llLoopSoundMaster("MasterLoop", 1.0);
```

</details>

<details>
<summary>The script below is an example of how using [llSetSoundQueueing](/functions/llSetSoundQueueing/) affects the interaction between master and slave sounds. In the example, it is used to run a car engine.</summary>

```lsl collapse={1-15, 31-39}
integer playState; //see LUT below.

list lut = ["Engine start, idle.","Accelerate, speed loop.","Decelerate, idle.", "Idle, stop"];

default
{
    state_entry()
    {
        llSetSoundQueueing(TRUE); //Set this so the we don't skip the 1st 'slave' sound.
    }

    touch_start(integer total_number)
    {
        llWhisper(0, "Sound: " + llList2String(lut,playState));
        if(!playState) //start engine.
        {
            llPlaySoundSlave("engine start",1); //This sound is skipped if Sound Queueing is not set.
            llLoopSoundMaster("idle",1);
        }
        else if(playState == 1) //accelerate, then play driving loop
        {
            llPlaySoundSlave("accelerate",1);
            llLoopSoundMaster("speed",1);
        }
        else if(playState == 2) //decelerate to idle.
        {
            llPlaySoundSlave("decelerate",1);
            llLoopSoundMaster("idle",1);
        }
        else //stop the engine.
        {
            llPlaySoundSlave("engine stop",1);
            llSleep(2); //Wait until the above sound completes.
            llStopSound(); //Call this to prevent the master loop from restarting randomly (e.g. upon script reset or region change).
            playState = -1; //This actually resets to 0, as it's incremented below.
        }
        ++playState; //increment playState.
    }
}
```

</details>

<details>
<summary>The script below can be added to an object, to toggle a SoundMaster on and off. Note that the script requires a sound in inventory called MasterLoop, or you need to change the argument in the function for it to work.</summary>

```lsl collapse={1-17, 23-28}
//This integer (actually a boolean) will be used to manage the toggle effect.
integer soundState = FALSE;
//Change MasterLoop to the sound clip you want to use.
string soundClip = "MasterLoop";
default {
    state_entry()
    {
        //Displays red "OFF" as floating text above the prim
        llSetText("OFF", <1,0,0>, 1.0);
    }
    touch_start(integer num_detected)
    {
        //When touched, soundState inverts its current boolean value. 1 becomes 0, 0 becomes 1.
        soundState = !soundState;
        if(soundState)
        {
            //Run this code when entering soundState 'on'
            //Displays green "ON" as floating text above the prim
            llSetText("ON", <0,1,0>, 1.0);
            llLoopSoundMaster(soundClip, 1.0);
        }else
        {   //Run this code when entering soundState 'off'
            //When touched, stop sound & display red "OFF" as floating text.
            llSetText("OFF", <1,0,0>, 1.0);
            llStopSound();
        }
    }
}
```

</details>

## See also

### Functions

- [llLoopSound](/functions/llLoopSound/) — 3=Plays a sound `attached` indefinitely.
- [llLoopSoundSlave](/functions/llLoopSoundSlave/) — 3=Plays a sound `attached` indefinitely, and declares it as a sync slave.
- [llPlaySoundSlave](/functions/llPlaySoundSlave/) — 3=Plays a sound `attached` once.
- [llSetSoundQueueing](/functions/llSetSoundQueueing/) — 3=Enables the ability to queue sounds.

---

*Source: [LlLoopSoundMaster](https://wiki.secondlife.com/wiki/LlLoopSoundMaster) on the Second Life Wiki. Content from the Second Life Wiki articles LlLoopSoundMaster (revision 1210676, 2022-04-22) and Template:LSL Function/inventory (revision 1191151, 2014-06-07), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llLoopSoundMaster/
