# Emotion-Driven Music and IoT Devices for Collaborative Exer-Games
## 4 Integrating Music into Exer-Games
### Example of Emotion-Based Musical Stimulation  
In this section, the interaction between the components shown in Figure 2 is illustrated through an specific example of stimulation scenario. This interaction consists of a flow of messages, some of which contain information about the players' emotions and the songs to be played as part of the affective regulation actions. So that, before explaining the flow, the affective model to represent emotions and the way of identifying songs are briefly introduced. Various models to represent emotions have been proposed in the field of affective computing. The most popular model is [PERSON]'s circumplex model [46]. It represents affective states over a two-dimensional space defined by the valence (X-axis) and arousal (Y-axis) dimensions. The combination of these two dimensions (valence/arousal) determines four distinct quadrants: the aggressive (negative/positive), the happy (positive/positive), the sad (negative/negative), and the relaxed (positive/negative) quadrants. Each emotion is then mapped to a point within this two-dimensional space and is thus located in one of these quadrants. Considering the [PERSON]'s model, we decided to represent an emotion by means of two vectors of four values: the first vector determines the probability that the emotion is mapped to each of the four quadrants, and the second which of these probabilities are significant (a relevance threshold was experimentally calculated). Two examples of emotions are as follows:  
* The annotation ([0.174, 0.865, 0.155, 0.006], [false, true, false, false]) represents that the affective state is happy with a 0.865 probability. The aggressive, sad, and relaxed probabilities (0.174, 0.155 and 0.006, respectively) are lower than the threshold and therefore the state is also defined as not sad, not aggressive and not relaxed. This annotation could correspond with a positive emotion with a high arousal value, for example, with the emotion \"excited\". * The annotation ([0.087, 0.695, 0.213, 0.578], [false, true, false, true]) represents that the affective state is happy and relaxed (and not aggressive and not sad). It could correspond with a positive emotion closer to the X-axis than the one of the previous example, for example, with the emotion \"delighted\". Regarding the identification of songs, the _Spotify IDs_ of tracks are reused. This decision facilitates the use of the _Spotify_ player, which is integrated into the smart glasses, and the interaction with the _Spotify_ online services to provide the music-based functionality. After presenting the representation models, the stimulation scenario is introduced. We suppose that a player is particularly motivated and is successfully completing the physical tasks (player's predominant emotion would be \"excited\" at that moment). The other players are performing their activities more slowly and are lagging behind the motivated player (their would feel \"relaxed\"). The emotion-based music system wants to regulate the players' affective states to balance their task outcomes. Figure 3 synthesizes the flow of messages that would happen in this scenario. The motivated player wears an Empatica E4 device which monitors their physiological signals. The Empatica PDA system, integrated into the player's glasses, periodically accesses these raw signals and filters the information related to the electrodermal activity (EDA). Then, EDA data are packaged in an event message to be published in the bus. Each package contains the information extracted from a five-minutes signal fragment. The Emotion Recognition Service is subscribed to be notified when new physiological events are available. It applies a series of machine learning models capable of translating the received EDA data to an emotion. This emotion represents the predominant affective state that the player is most likely to have felt during those five minutes.