# tsp_rooms

Room-sensitive soundtrack example using advanced sound player.

### Synopsis

`tsp_rooms`

### Description

Creates a thread to playback a sound track based on a global room variable gRoom.

The parent task, tsp_rooms, gets control port events and updates gRoom as follows:

- A -Enter room A.
- B-Enter room B.
- C - Enter room C.
- X (Stop)-Exit nicely.
- Shift-X-Stop immediately.

The soundtrack thread, Soundtrack, uses the advanced sound player to play a unique sound file for each room. When the main task changes rooms, the soundtrack thread adapts the soundtrack to the change in room at a musically convenient location.

The way this is done is that each room's soundfile is designed so it can play in a loop. In addition to this, the end of each sound file, and additional optional marked locations within the sound file, must be musically sensible locations to transition to the beginning of any of the other room's sound files. When playback reaches the next marked position in, or the end of, the current room's sound, a default decision function is called to check to see if the main task changed room. If the room is still the same, then the current sound continues to play, or loops if at the end.

If the room has changed, the SPPlayer is instructed to begin playing the sound for the new room.

Note that the soundtrack adapts to room changes by the main task instead of making a sharp transition as soon as the room changes. It is possible for the main task to make several room changes before the soundtrack thread discovers that the room has changed at all. This results in smooth soundtrack transitions that occur at seemingly random locations, which is far less likely to become annoying to a game player than a soundtrack that predictably changes the instant the player crosses a given threshold.

### Associated Files

tsp_rooms.c, $samples, words.aiff

### Location

examples/Audio/Advanced_Sound_Player

### See Also

`spCreatePlayer, tsp_switcher, tsp_algorithmic`