What's with the "Media_" functions?

Posted By: Irish_Farmer

What's with the "Media_" functions? - 04/14/09 03:05

edit: As luck would have it, I figured out the solution to the problem. The manual notes that .mid can't be altered, but it lead to me finding the master_vol variable which will affect midi volume.....nvmnd. frown [/edit]


So, I've had this problem ever since A6, and I've just downloaded lite-c (with A7 - free cuz I'm poor) and the problem is still there. I'm pretty sure this is user error, because this would be a rather noticeable bug, so maybe someone can show me where I'm going wrong.

The aim of my code is simple: play a midi file, and then fade that midi file out until it is completely quiet. The problem is, media_tune() or even the midi_vol variable aren't doing anything for me. I've also tried just using the generica "media_handle" handle to see if I can manipulate that and I can't. The song plays at full volume unphased, unless I use media_stop() to abruptly end it. In fact, I can't even start the song at a lower volume. What's the deal?! If I didn't know any better, I would say the functions are broken.

I've been trying to get back into programmiing, but there's nothing more frustrating then when I'm testing out the early features of my project and the simplest things aren't working...despite that I'm following the documentation word-for-word.

Thanks in advance for any help.

Code:

[code]
var volume = 100;

function main()
{
video_mode = 8;
video_screen = 1;
var hMedia = 0;
hMedia = media_loop("Dungeon01.mid", NULL, 100);
while (volume > 0)
{
volume -= 1;
media_tune(hMedia, volume, 0, 0);
wait (1);
}

}
Posted By: delinkx

Re: What's with the "Media_" functions? - 04/14/09 03:26

There is no problem with the code. Its only one line which is wrong: wait(1).

The engine frame rate is too fast that you cant notice the fade off. Its actually happening. Suppose ur engine running at 512fps. That means for the fade off (which happens over 100 frames) is being done in 100/512 seconds. Thats way to fast to notice it.

Instead i would suggest u use "seconds" to define your wait between the transition. here is something:

Code:
var volume = 100;

function main()
{
video_mode = 2;
video_screen = 2;
var hMedia = 0;
hMedia = media_loop("battle.mid", NULL, 100);

while (volume > 0)
{
	volume -= 1;
	media_tune(hMedia, volume, 0, 0);
	wait (-0.02);
}


u can play around with "0.02" to any value u want. here 0.02 is the seconds to wait between each 1 volume down.
Posted By: delinkx

Re: What's with the "Media_" functions? - 04/14/09 04:53

What the manual says is not wat u want to do. Its the midi_vol that do not allow the volume adjustment. And midi_vol variable affects the mixer(system) volume control. If u using master_vol that also affects the mixer and put off all sounds if set to 0. So this wont be appropriate for a game unless u want to mute off all sounds.

Note: The code above is tested and it works. In this way it affects only tat sound referred to by the media handle.
Posted By: Irish_Farmer

Re: What's with the "Media_" functions? - 04/14/09 18:41

The problem I was having wasn't that the midi file was fading out too fast; instead the file wasn't fading out at all. As a point of fact, it doesn't matter what volume parameter I pass to media_loop() to begin with, because the midi file will always play at the same volume.

This may not be a universal problem, perhaps only certain midi files (or certain computers). The manual says that if the audio mixer has no synthesizer channel, then it won't effect volume - well my computer doesn't have a synthesizer channel so there you go. I don't want people without this channel in their mixer to have a different sound experience, than those that do.

The master_vol variable will have to work, because its the only thing that effects the volume of these midi files, without any caveats. Because of the simplistic audio needs of my game, there won't be any noticeable problems caused by the use of the master_vol variable.

Another alternative solution would be to convert all of my .mid files into .mp3, because media_tune WILL change the volume of these files under all circumstances. But that would significantly increase the size of the finished game's folder with no payoff in improved sound or anything like that.

Thanks for the input.
© 2024 lite-C Forums