ID:264779
 
Code:


Problem description:

I apologize for all the space I've been taking up on the forums recently, but there are several code issues I have confined to myself for some time and I realize how proficient some of you are in the DM language. =)

So I have been worked up lately by an audio issue. It seems that a song not yet loaded in the world cache (the .dyn file for the game) has slightly different attributes than a song that has been played already and loaded into the cache. I am experiencing a couple audio errors, but I will only describe the more simple of the two, as I think these errors are linked to the same root. When I play a song that has been played previously (and is still in the cache), everything works fine. It is only when a new song is played that this happens: I have a speed setting which allows the user to play a song at a range of different speeds (using sound.frequency), the problem is that a new song will always play at default (1.0) frequency, regardless of the user's speed setting. I feel this could have something to do with status = SOUND_UPDATE, which I hope some of you are familiar with. I used this line of code to update the frequency for the song, and such, and in reading the description for status --> SOUND_UPDATE in the DM Reference, I noticed that it states "If this flag is not set or no channel is specified, the sound will start again from the beginning". And that's what I believe to be happening, the song is probably starting from the beginning and at default frequency. So that leads me to believe the solution would come by setting the SOUND_UPDATE flag, or specifying a channel, but how would I do either of these two things?
When you have a problem with a code snippet, it often proves helpful to show the code in question for those trying to help you. Or, in other words, how are you trying to invoke the customised sound?
In response to Schnitzelnagler
Very well... I just hope this doesn't confuse the matter at all. The code is posted below, just remember the problem here applies ONLY when a new song is played (not stored in the cache). So when looking over the code, try to think about why only new songs cause issues. I did, and I'm stumped.

mob/Player/proc/Play_Song_To_World()
set category = "Music"
if( worldplaymusicpermitted == 1 )
var/s = input( "Which song would you like to play?" ) in songs
if( ( s != "--Cancel--" ) && ( worldplaymusicpermitted == 1 ) )
if( muted == 1 )
usr << "You are currently muted!"
else
for( var/mob/Player/p ) p.StopSong()
sleep( 1 )
S = sound( "Music/[s].mid", repeat, 0, 100, 100 )
for( var/mob/Player/p )
p.S = S
p.S.frequency = freq
p.S.status = SOUND_UPDATE
world << S
if( repeat == 0 ) world << "<font color =#505050><b>[usr]</b> has played <b>[s]</b> to the world!"
else world << "<font color =#505050><b>[usr]</b> has played <b>[s]</b>, on repeat, to the world!"

mob/Player/proc/StopSong()
src << sound( "" )
soundaction = 1
In response to Lethal Dragon
well just throwing this out there but your changing S's frequency and status as many times as there are players. i suggest you move the 2 out of there and put

S.frequency=freq
S.status=SOUND_UPDATE


before the for() proc.
In response to Masschaos100
If that doesn't help, then load the song into the cache before playing it, by playing it with a volume of 0 so that no one hears it but it does get loaded into cache prior to being heard.