ID:1483545
 
Not a bug
BYOND Version:504
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Chrome 32.0.1700.76
Applies to:Dream Daemon
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
I start playing a song using sound(), caching the sound object on the server. In order to try and fade it, I set its status to SOUND_UPDATE, change variables (in this case, volume), and re-send it to the player. However, this appears to have the unintended side effect of causing the sound to restart playing, instead of merely applying the updates.

Numbered Steps to Reproduce Problem:
1. Store output of sound() to variable
2. Output variable to world
3. Attempt to fade the sound out

Code Snippet (if applicable) to Reproduce Problem:
        if (client.Pressed["Insert"])
PlayingSound = sound('THUNDERDOME.ogg', 0, 0, 4, 100)
PlayingSound.status = SOUND_STREAM
world << PlayingSound

if (client.Pressed["Delete"])
spawn
PlayingSound.status = SOUND_UPDATE
while (PlayingSound.volume)
PlayingSound.volume -= 5
world << PlayingSound
sleep(1)
PlayingSound.status = SOUND_PAUSED | SOUND_UPDATE
world << PlayingSound


Expected Results:
Sound fades out smoothly

Actual Results:
Soudn fades out, but restarts playback on every fade step

Does the problem occur:
Every time? Or how often? Every time
In other games? Not tested
In other user accounts? Not tested
On other computers? Not tested

When does the problem NOT occur?

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)

Workarounds:
I tried to use a null sound as follows, but this only resulted in immediately stopping the track. A global (null sound to channel 0) fade worked, but that works against what I'm planning to do.
        if (client.Pressed["Insert"])
PlayingSound = sound('THUNDERDOME.ogg', 0, 0, 4, 100)
PlayingSound.status = SOUND_STREAM
world << PlayingSound

if (client.Pressed["Delete"])
spawn
var/sound/FadeTrack = sound()
FadeTrack.channel = PlayingSound.channel
DebugText("[FadeTrack.channel]")
FadeTrack.volume = 100
FadeTrack.status = SOUND_UPDATE
while (FadeTrack.volume)
FadeTrack.volume -= 5
world << FadeTrack
sleep(1)
FadeTrack.status = SOUND_PAUSED | SOUND_UPDATE
world << FadeTrack
The code looks correct, as far as I can tell, but I know that this used to work. If you don't set the sound to stream, does it update correctly?
No, it does not work then either.
I have not managed to reproduce this issue. I thought maybe the issue might be with SOUND_STREAM, but that seems to be irrelevant. I'm able to fade out a sound with no trouble. I'll need a simple test case from you to look into this further.
Lummox JR changed status to 'Unverified'
I'll put one together tonight,
Okay, this is odd.

I tried running the fade-out code again today, and it worked fine, despite the code being the exact same as the code that had not worked yesterday - except for two things: SOUND_STREAM, and the file being played.

The two files were "THUNDERDOME.ogg" and "clouds.s3m". Today, THUNDERDOME.ogg worked fine no matter whether SOUND_STREAM was set or not. clouds.s3m also worked, if SOUND_STREAM was set. When I tried running without SOUND_STREAM, it caused the audio bug I initially reported. After this. THUNDERDOME.ogg also exhibited the bug.

Closing and restarting dream seeker didn't fix the problem. Neither did closing and restarting BYOND, and amazingly enough neither did putting the computer to sleep and then restoring it.

I'm not entirely sure why the bug managed to persist through that, seeing as it hadn't persisted overnight / through earlier today. Would it help if I made the two audio files in question available via .zip or such?
Probably worth uploading them, yea.

Also, if you clear your cache, does it start working again?
These are the two test files I used

Also, clearing the cache didn't help.
I did some followup on this with those files, but didn't see anything wrong. I tested both of them with and without SOUND_STREAM.

I did however discover a logic error in my own implementation that might be relevant to yours: I did a more gradual fade by subtracting 0.1 every tick (this being at 40 FPS, it was 4% per second), but rounding errors kept the while loop() from completing unless I added <0 to the volume check, so an old verb would interfere with a newer one. Your sample code here isn't subject to that rounding error, but I thought I'd mention it.

This remains unverified pending a reproducible test.
I can reproduce this consistently on 504, both on my desktop (Win7 x64) and one my laptop (WinVista x86). I've pared out almost everything I can from the project except some of the really basic stuff that's still used.

When you start the DMB, you'll have a little green rectangle-dude in a black screen. Press U/D/L/R to move around, and Insert/Delete to play, and fade out the music respectively.

The code that plays (and fades) the sound is in Project\Code\Mob\Soldier.dm, at the bottom of the file.

Demo Here
Is anyone else able to reproduce this?
@Topkasa: What audio drivers/card do you have?

BYOND's sound implementation depends on Creative EAX, which is only supported on legacy devices now. It was deprecated in 2005, and discontinued in 2010 in favor of OpenAL EFX. Even most DirectX games these days implement OpenAL instead of DirectSound. Microsoft's implementation of DirectSound is antequated and not universally supported, owing to a lack of software emulation for fallback situations.

EAX simply doesn't work on Creative sound cards made after about 2005, and doesn't work at all on non-creative sound cards. Even Creative, who created the specification has recommended OpenAL's EFX instead of their old proprietary EAX implementation.
Tested with a pair of RealTek integrated audio cards (one per computer), a Logitech G930 (with software surround both on and off), and a Logitech G510. I wasn't using EAX in my test case, though - just a little more than a basic world << sound()
I tested out your project. I can now confirm there is no bug involved.

Your code in the project is not the same as what you posted here. Specifically, you set the channel argument to 0, not to channel 4 as you posted. With channel=0, any available channel is used, and that is why the music is constantly restarting as you fade it out. When I changed the channel to 1, instead of 0, the problem went away.
Lummox JR resolved issue (Not a bug)
Okay, I see what happened. I thought setting channel to 0 and simply re-using the object would work; I guess I'll have to explicitly managed channels then.