Jump to content
Eternal Lands Official Forums
CodeWarrior

Music Fadein/Fadeout

Recommended Posts

I've been pouring over sound.c and sound.h to sus out exactly how it all goes together, (my previous experiments have been entirely with DirectX, but after looking at the ogg vorbis/OpenAL APIs I'm pretty sure I see how this works)

 

If nobody else is taking a stab at doing fadein/fadeout, I'd like to try my hand at it.

 

The other thing that I wanted to ask about was with song looping. Reading around and doing preliminary tests, it seems that it should be possible to make a song loop to an exact location in the song.

 

It is my believe that looping is a good thing because I, personally, feel that the gaming experience is interupted when the music stops or fades out and you're left with nothing but sound effects.

 

This is purely a suggestion, but otherwise I'd be quite happy to do reasearch into and implement just the fade-in and fade-out.

 

--Loop implementation:details--

 

For the unitiated for audio (appologies if any of this is wrong), an uncompressed piece of music as data is reperesented as samples, which is basically the amplitude of the sound at any one point in time. Vorbis files are not stored in samples though, they're stored in blocks of compressed sound.

 

The ogg/vorbis API provides a function ov_pcm_seek() which is usable on seekable streams, (which from my research, does include vorbis songs).

 

When a song reaches the last sample (or a pre-defined loop point), instead of ending the song playback, we rewind the current play time to the start of the loop.

 

There are a few issues with this. Because Ogg Vorbis files are stored in blocks, not samples, doing this rewind will require Vorbis to go back to the block which contains the sample and decode the block up to that point. I'm unsure at this point as to whether this would cause any latency. I'll need to experiment.

 

Secondly, .pll files would need to be modified to take into account the loop points. I'd probably recommend having a value (like -1) that would disable looping as it might be handy in some circumstances.

 

Lastly, The biggest problem with looping songs is that the loop points have to match up exactly, that includes any effects like reverb and such. (they don't have to be 100% accurate, but it needs to be very close.) The people who have written the songs would need to know how to use editors such as Audacity, Nero Wave Editor or such a program to figure out exactly what points the song loops. I am available however to figure out loop points for songs.

 

--end of explanation--

 

I'd appreciate comments/suggestions or in a worstcase scenario, a polite rejection ^_^

 

-Steven

Share this post


Link to post
Share on other sites

Ok, that was a lot trickier than I thought it would be ^_^

 

Well, I have a working fade-out that seems to work rather well. I'm curious though as to the point of a fade-in? Most of the songs have rather defined beginnings that may already include a fade-in. I don't mind implementing it, but I just want to make 100% sure that it's neccessary. (or are we talking about crossfading two songs?)

 

Also, I'm embarrased to admit that I've never done any work on a project like this and so I don't know anything about patch or diff (other than what they're for) I'd appreciate it if someone could give me a quick rundown on how to create a diff file.

 

-Steven

Share this post


Link to post
Share on other sites

it's easiest to use your cvs client to make a diff. `cvs diff file1 file2 file3` I beleive. if using tortoiseCVS, then select the files you want to include, rightclick, and make patch (if you do a lot of editing, remember to prune your patch files to only include the changes for the curent job)

it's also best to update cvs just before making the patch, and do a `patch --dry-run` with your new patch on a clean cvs tree, to make sure it applies cleanly. if you're on windows, you probably won't have patch yet, you

ll have to download it. if you have cvs, you don't need another diff

Share this post


Link to post
Share on other sites

Thanks for that :)

 

Here is the patch then for the music fadeout, I'm rather new to C, but I'm pretty sure that I haven't done anything that would normally be discouraged.

 

Music Fadeout Diff

 

I'd like to ask again though for your opinions on the music looping...

 

edit: whoops, wrong URL.

Edited by CodeWarrior

Share this post


Link to post
Share on other sites
Here is the patch then for the music fadeout, I'm rather new to C, but I'm pretty sure that I haven't done anything that would normally be discouraged.

200646[/snapback]

You're positive you're new to C? The patch looks great. :angry:

Share this post


Link to post
Share on other sites

*phew*

 

I've got about 12 years with programming Visual Basic and 5 with PHP and 2 for Java, so I'm not new to programming, but this is the first thing I've ever done in a community project, so things like coding standards, comments and changelogs are new to me.

Share this post


Link to post
Share on other sites

Indeed somebody (presumably you) did ^_^

 

Most of what I did was mostly making it more publically accessible so that the map change functions were able to enable the fadeout (It was previously set so that only a fadeout between playlist entries were possible)

 

The other changes that I made were to make the fadout smoother as 6 volume levels seemed a little too small, and the rest of the changes were in making sure that it continued to buffer the song while fading out. (That had me stumped for a while)

 

Ideally it was not my favourite way of doing a fadeout simply because when there were too many fadeout levels, CPU usage jumps through the roof.

 

Ideally I would have liked to fade the song sample by sample as it might have paved the way for cross fading songs, but you did save a lot of work which I'm grateful for :(

Share this post


Link to post
Share on other sites

Codewarrior, I was wondering if you'd be interested in working on an idea of mine, if it is at all possible, concerning music.

 

I would love to have Wandering Bards in the game. Basically, a NPC that walks around, sits down, and of course, plays music on his instrument :mace:

 

It would randomly choose one of the songs that it is defined to play. This sound would have a small area range around the npc..just like a viewable character range. If there is another music song in the map, the NPC's song would over ride it, so you would fadeout of the map song, fade into the npc's song.

And of course when he starts playing the song, an animation would start with him visible playing the instrument(i will do the models/animations).

 

Is it possible?

Share this post


Link to post
Share on other sites
Codewarrior, I was wondering if you'd be interested in working on an idea of mine, if it is at all possible, concerning music.

 

I would love to have Wandering Bards in the game. Basically, a NPC that walks around, sits down, and of course, plays music on his instrument :cry:

 

It would randomly choose one of the songs that it is defined to play. This sound would have a small area range around the npc..just like a viewable character range. If there is another music song in the map, the NPC's song would over ride it, so you would fadeout of the map song, fade into the npc's song.

And of course when he starts playing the song, an animation would start with him visible playing the instrument(i will do the models/animations).

 

Is it possible?

202710[/snapback]

If the server sends a play music command with the area, yes. No idea how much the protocol would have to be modified, but this is almost entirely server work, if I remember the PLAY_MUSIC (or something) command correctly.

Edited by crusadingknight

Share this post


Link to post
Share on other sites

Well, I thought I'd look it over anyway, The PLAY_MUSIC is defined and used in multiplayer.c which looks just fine, with the exception of the play_music() function...

 

From what I can gather, in order to have a bard play a song, you'd need to send a numerical parameter back to the client, this number is used to get the PLL filename which would be limited to '1.pll', '2.pll', etc.

 

The current system also has the problem that once the server sends a play music message, it would remove the map playlist and replace it with the "bard" playlist...

 

Other things need to be taken into account such as people not having the music file in question. We can't assume that a bard will be playing a song stored on someone's hard drive (or even someone's edited .pll!)

 

To make matters worse, unless the bard plays music specific to someone's computer, rather than everyone (as I assumed from Roja's original post on the idea) The server will need to keep track of how long the song is so that it knows when the bard is available to play the next song.

 

Fading a song out with the character should not be a difficult thing to do. It would be better if you could assure me that there will be NO plans to have two bards on the same map, or at least within viewable distance of each other.

 

Anyway, that's my discussion on the issues with regard to it. I see it as enturely possible within the following guidelines:

  • The NPC Bard must have a set list on the server, complete with song lengths. It would have to have a flag as to whether it's playing or not, and it would have to be retrievable what the current song actually is and where in the song it's currently up to...
     
  • The music engine needs to be updated to be able to start a song midway through. This is a trivial change which can be implemented using ov_seek_pcm(); easily enough.
     
  • play_music() needs to be updated then to not remove the current playlist, and to support fading in and out instead of starting a new song abruptly.
     
  • There may be another way around this, but I'd assume that a new Actor type would need to be defined so that when updating informatin about a bard, the music volume can be adjusted accordingly.

Hmn.... That's all I can think of on the subject now. It doesn't sound impossible to me at all, nor even hard... just a little tedious.

 

edit: tried to make it easier to read

Edited by CodeWarrior

Share this post


Link to post
Share on other sites

We can of course make it so the NPC are not on the same maps/do not cross paths. I was planning them having a predefined path that they can walk, and places to sit.

Share this post


Link to post
Share on other sites

Sorry Roja, I haven't disappeared or given up yet, just settling back into uni. I'll get started on the bards this weekend.

 

Edit: Just out of curiosity... is there still a test server? I've been trying to connect on port 2001 and 2002, but I'm not finding anything... I don't want to experiment on the live server if I'm not supposed to... :glare:

Edited by CodeWarrior

Share this post


Link to post
Share on other sites

I've been working really hard on coding the fading a bit better.

 

Specifically speaking, I've been trying to implement cross-fading. I've made two implementations, one that reads from a fadein ogg file at the same time as stream_music(), and one where it creates a seperate thread to create a 5 second buffer.

 

Unfortunately, when I use either of these methods, the soung that is being faded out tends to get corrupted when I start reading from a second OGG file. I'm not sure what's causing this. perhaps I'm not handling the memory correctly, but I can't seem to get valgrind to work with EL (something about openGL not being loadable or something...) which I had hoped would tell me about any memory leaks I might be creating...

 

Occasionally, after the first or second fade, the sound will start jumping all over the place, half a second from here, half a second from there...

 

I dunno... I'm starting to get a little stumped.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×