Author Topic: Alpha + Volume Fade  (Read 4081 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Alpha + Volume Fade
« on: July 29, 2011 »
Hi guys,
I was wondering if anyone can help with this problem I have?
I am trying to fade my screen with opengl Alpha and fade the volume of my music
at the same time but I would like them both to finish at the same time.
Here is my code from my main loop.

If KeyDown(KEY_ESCAPE) Or exitprog Then
            
       exitprog = True
   If alpha > 0.7 And vlevel > 0 Then vlevel:-1; BASS_SetVolume(vlevel)
   fadescreen()
               
End If

This is BlitzMax code, Thanks for any help.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Alpha + Volume Fade
« Reply #1 on: July 29, 2011 »
You haven't posted enough code for anyone to give an exact answer, but let's say you want the fade to last 2 seconds.  Let's also say alpha goes from 1->0 and volume goes from 255->0 during the fade.
Code: [Select]
const fadetime = 2000
fader#=fadetime
...
;main loop
repeat

alpha#=fader/fadetime
volume#=255*fader/fadetime

setvolume(volume)
setalpha(alpha)

fader = fader - elapsedtime
flip
until fader<=0

Jim
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Alpha + Volume Fade
« Reply #2 on: July 30, 2011 »
Hi Jim,
My main loop keeps running even after the Esc key has been pressed.
So it keeps drawing the screen, The alpha channel is set at #0.1 and has to fade to #1.0
The volume of the music on my system is set at int:67 this must dec to 0
On other system this volume may be less or higher depending on the mixer wave setting.

I would like a smooth not to fast fade of music and screen
The alpha controls a black rectangle that fills the screen and fades from transparent to not transparent.
Thanks Jim
 

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Alpha + Volume Fade
« Reply #3 on: July 30, 2011 »
you just have to interpolate from one value to another
Code: [Select]
interpolate = firstvalue + curstep*(finalvalue-firstvalue)/numsteps;

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Alpha + Volume Fade
« Reply #4 on: July 30, 2011 »
Thanks rain_storm but you are dealing with an idiot here, Can you elaborate on that please.

What would the first value be?
I guess the finalvalue would be 0 for the volume and 1.0 for the alpha  ;D

Thanks for any help on this.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Alpha + Volume Fade
« Reply #5 on: July 31, 2011 »
interpolation is the process of taking a few sample points and trying to fill in the missing points in between, so that the new points transition smoothly from one extreme to the other. The most simple form is linear interpolation (the pseudocode I gave above), in which the points inbetweens fall apon a straight line with both ends being the sample points.

you can use that equation to transition from a given initial colour to a desired colour doesn't have to be black it could just as easily be red or white. It doesn't even have to be colours, anything can be interpolated.

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Alpha + Volume Fade
« Reply #6 on: July 31, 2011 »
Thanks Rain_Storm, I had read that info on the web but I can not get my head around it but I will play with it and see
Cheers for your help.