This wiki is out of date, use the continuation of this wiki instead

Set song volume

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 11:50, 30 July 2007 (edit)
G105b (Talk | contribs)
(New page: Category:functions Category:music ==Definition== '''INT''' set_song_volume ( <'''INT''' volume> ) Change the reproduction volume of the music track. With this function, it is po...)
← Previous diff
Current revision (13:25, 19 September 2007) (edit) (undo)
Sandman (Talk | contribs)
m
 
(5 intermediate revisions not shown.)
Line 1: Line 1:
[[Category:functions]] [[Category:functions]]
-[[Category:music]]+[[Category:sound]]
==Definition== ==Definition==
Line 11: Line 11:
== Parameters == == Parameters ==
{| {|
-| '''INT''' volume || - New volume. (0 to 128).+| '''INT''' volume || - New volume. (0..128).
 +|}
 + 
 +== Returns ==
 +'''INT''' : Error.
 +{|
 +| -1 || - Error: sound inactive.
 +|-
 +| 0 || - No error.
|} |}
== Notes == == Notes ==
-This function changes the reproduction volume of the music track. The volume level can be set between 0 (silence) and 128 (original 100% volume of the track.+This function changes the reproduction volume of the music track. The volume level can be set between 0 (silence) and 128 (original 100% volume of the track. The default volume is 128.
 + 
 +== Example ==
 +<pre>
 +program music_example;
 +global
 + my_song;
 + playing;
 + paused;
 + faded_in;
 + v;
 +begin
 + set_mode(640,480,16);
 +
 + my_song=load_song("beat.ogg");
 +
 +
 + write(0,320,30,4,"Use the keyboard to control the music playback.");
 + write(0,320,50,4,"Key [ENTER] starts / stops the song.");
 + write(0,320,60,4,"Key [SPACE] pauses / resumes the song.");
 + write(0,320,70,4,"Key [0] through key [9] changes the song volume.");
 + write(0,320,80,4,"Key [F] fades the song in or out.");
 +
 + write(0,320,120,5,"Playing: ");
 + write_int(0,320,120,3,&playing);
 +
 + write(0,320,140,5,"Paused: ");
 + write_int(0,320,140,3,&paused);
 +
 + write(0,320,160,5,"Faded in: ");
 + write_int(0,320,160,3,&faded_in);
 +
 + write(0,320,180,5,"Volume: ");
 + write_int(0,320,180,3,&v);
 +
 + v=128;
 + faded_in=true;
 + 
 + 
 + repeat
 + if(key(_enter))
 + if(is_playing_song())
 + stop_song();
 + playing=false;
 + else
 + play_song(my_song,1);
 + playing=true;
 + end
 + while(key(_enter))frame;end
 + end
 +
 + if(key(_space))
 + if(paused)
 + paused=false;
 + resume_song();
 + else
 + paused=true;
 + pause_song();
 + end
 + while(key(_space))frame;end
 + end
 +
 + if(key(_f))
 + if(faded_in)
 + faded_in=false;
 + fade_music_off(100);
 + else
 + faded_in=true;
 + fade_music_in(my_song,1,100);
 + end
 + while(key(_f))frame;end
 + end
 +
 + if(key(_0))v=0;end
 + if(key(_1))v=14;end
 + if(key(_2))v=28;end
 + if(key(_3))v=43;end
 + if(key(_4))v=57;end
 + if(key(_5))v=71;end
 + if(key(_6))v=85;end
 + if(key(_7))v=100;end
 + if(key(_8))v=114;end
 + if(key(_9))v=128;end
 +
 + set_song_volume(v);
 + 
 + frame;
 + until(key(_esc))
 +
 + exit();
 +end
 +</pre>
 +Used in example: [[key]](), [[set_mode]](), [[load_song]](), [[write]](), [[write_int]](), [[pause_song]](), [[play_song]](), [[stop_song]](), [[resume_song]](), [[fade_music_in]](), [[fade_music_off]](), [[set_song_volume]]().
 + 
 +{{Funcbox
 + | category=Sound
 +}}

Current revision


Contents

[edit] Definition

INT set_song_volume ( <INT volume> )

Change the reproduction volume of the music track.

With this function, it is possible to set the background music to a different volume than the sound effects, etc.

[edit] Parameters

INT volume - New volume. (0..128).

[edit] Returns

INT : Error.

-1 - Error: sound inactive.
0 - No error.

[edit] Notes

This function changes the reproduction volume of the music track. The volume level can be set between 0 (silence) and 128 (original 100% volume of the track. The default volume is 128.

[edit] Example

program music_example;
global
    my_song;
    playing;
    paused;
    faded_in;
    v;
begin
    set_mode(640,480,16);
    
    my_song=load_song("beat.ogg");
    
    
    write(0,320,30,4,"Use the keyboard to control the music playback.");
    write(0,320,50,4,"Key [ENTER] starts / stops the song.");
    write(0,320,60,4,"Key [SPACE] pauses / resumes the song.");
    write(0,320,70,4,"Key [0] through key [9] changes the song volume.");
    write(0,320,80,4,"Key [F] fades the song in or out.");
    
    write(0,320,120,5,"Playing: ");
    write_int(0,320,120,3,&playing);
    
    write(0,320,140,5,"Paused: ");
    write_int(0,320,140,3,&paused);
    
    write(0,320,160,5,"Faded in: ");
    write_int(0,320,160,3,&faded_in);
    
    write(0,320,180,5,"Volume: ");
    write_int(0,320,180,3,&v);
    
    v=128;
    faded_in=true;


    repeat
        if(key(_enter))
            if(is_playing_song())
                stop_song();
                playing=false;
            else
                play_song(my_song,1);
                playing=true;
            end
            while(key(_enter))frame;end
        end
        
        if(key(_space))
            if(paused)
                paused=false;
                resume_song();
            else
                paused=true;
                pause_song();
            end
            while(key(_space))frame;end
        end
        
        if(key(_f))
            if(faded_in)
                faded_in=false;
                fade_music_off(100);
            else
                faded_in=true;
                fade_music_in(my_song,1,100);
            end
            while(key(_f))frame;end
        end
        
        if(key(_0))v=0;end
        if(key(_1))v=14;end
        if(key(_2))v=28;end
        if(key(_3))v=43;end
        if(key(_4))v=57;end
        if(key(_5))v=71;end
        if(key(_6))v=85;end
        if(key(_7))v=100;end
        if(key(_8))v=114;end
        if(key(_9))v=128;end
        
        set_song_volume(v);

    frame;
    until(key(_esc))
    
    exit();
end

Used in example: key(), set_mode(), load_song(), write(), write_int(), pause_song(), play_song(), stop_song(), resume_song(), fade_music_in(), fade_music_off(), set_song_volume().


Sound Functions
Is_playing_song() • Load_song() • Load_wav() • Pause_song() • Play_song() • Play_wav() • Resume_song() • Set_song_volume() • Unload_song() •
Personal tools