ID:264776
 
Code:
SomeVerbThatPlaysSongs()
world << sound( "" ) // Stops any music currently playing
var/sound/S = sound( "SomeSong.mid", repeat, 0, 100, 100 ) // Sets up some song on channel 100 via var S
S.frequency = 1.2 // Sets S to play at 1.2 default speed
//S.y = 50 // Commented out; changes 3D effect
usr << S // Play the song at 1.2 times normal speed
//S.y = 0 // Commented out; restores default 3D effect, but only when the sound is updated successfully
sleep( 10 ) // Wait for just a second
S.status = SOUND_UPDATE // SHOULD update S even while it's playing; FAILS to do so. Why?
usr << S // My second attempt to update S, by playing it after setting the status to update; when this line is executed, S continues to play but the frequency seems to have multiplied by itself, becoming 1.2 * 1.2 = 1.44
usr << S.frequency // Curiously, this value is STILL equal to 1.2 although I can hear a change in the frequency. WTF?


Problem description:

In short, I want this verb to change the song's attributes WHILE the song is playing. The code is a bit messy because I've been playing around with it, attempting to get things to work. From experimenting, I noted another issue which struck my curiosity. The frequency (originally set to 1.2) seems to be shifted to 1.44 (or around there) after the sound update (this takes place one second after the first time the music is played), which itself seems to fail entirely. I don't understand how the frequency can so clearly sound altered, and yet the frequency output still reads 1.2 after the modifications to the sound are all said and done. To sample my problem further, please note the comments associated with the above lines of code.
Unlike with, say, /images, with the /sound object, what the client experiences doesn't directly tie in with the /sound object. Instead, when a /sound object is outputted to the client, it's just sent the data it needs to know and handles the sound on its end (so it doesn't "care" about the object). This data can also be sent without using a sound object, when applicable (e.g. player << 'sound.ogg').
So the /sound object's vars don't necessarily correlate with the client's playing sound. It's similar to outputting an icon file to a label, then modifying that icon (in effect creating a new, altered icon) and expecting the label display to update to reflect the changes.

To update an existing sound, you need to output a sound object with the SOUND_UPDATE status flag, the changes you want and the same channel and file as the sound you're updating had. Here's a post with an example: [link]

I'm not sure how much of the rather messy-looking code you've tried or not and how exactly. var/sound/S = sound( "SomeSong.mid", repeat, 0, 100, 100 ) doesn't look like it'd compile, or it would compile erroneously, unless you have a repeat var declared within the scope. Additionally, 100 shouldn't be a valid channel.
The second usr << S line updates the song. The only thing you've done to update it is to set the frequency to 1.2 times the current frequency. As you describe the frequency increasing by 20%, this is working properly.
In response to Garthor (#2)
Well I have resolved the main issue I was having =). But the point I brought up about the frequency... There was an initial change in the frequency. So I would hear it playing at 1.2x normal speed. But after the sleep( 10 ), I heard yet another increase in the frequency. The part that doesn't make sense is that when I outputted the frequency, it read 1.2, and what I was hearing was certainly higher than 1.2. Bizarre?
In response to Lethal Dragon (#3)
Maybe frequency works based on the current status of the sound being played. So the first time it's updated, it gets +20% to its frequency. And the second time, since it's updated again, it gets +20% again.
In response to Lethal Dragon (#3)
No, not bizarre. A sound is output to a player. The sound itself does not matter. You then output an update command. Part of this update command is to set the frequency to 1.2 times the previous frequency, so that happens.

Now, the original sound output to the player was at a frequency that was 1.2 times higher than that of the original sound file. After its frequency is increased, it is now 1.44 times higher.

The sound object does not show a frequency of 1.44 because that would not make sense. What if you used the same sound datum to up one person's frequency to 1.2 and another's to 1.44. What should it read then?