hedgewars/uSound.pas
changeset 351 29bc9c36ad5f
parent 287 b0eef98928f8
child 355 40c68869899e
equal deleted inserted replaced
350:c3ccec3834e8 351:29bc9c36ad5f
    22 {$INCLUDE options.inc}
    22 {$INCLUDE options.inc}
    23 
    23 
    24 procedure InitSound;
    24 procedure InitSound;
    25 procedure ReleaseSound;
    25 procedure ReleaseSound;
    26 procedure SoundLoad;
    26 procedure SoundLoad;
    27 procedure PlaySound(snd: TSound; const infinite: boolean = false);
    27 procedure PlaySound(snd: TSound; infinite: boolean);
    28 procedure PlayMusic;
    28 procedure PlayMusic;
    29 procedure StopSound(snd: TSound);
    29 procedure StopSound(snd: TSound);
    30 function  ChangeVolume(voldelta: integer): integer;
    30 function  ChangeVolume(voldelta: integer): integer;
    31 
    31 
    32 implementation
    32 implementation
    61 Mix_CloseAudio
    61 Mix_CloseAudio
    62 end;
    62 end;
    63 
    63 
    64 procedure SoundLoad;
    64 procedure SoundLoad;
    65 var i: TSound;
    65 var i: TSound;
    66     s: string;
    66     s: array[byte] of char;
    67 begin
    67 begin
    68 if not isSoundEnabled then exit;
    68 if not isSoundEnabled then exit;
    69 for i:= Low(TSound) to High(TSound) do
    69 for i:= Low(TSound) to High(TSound) do
    70     begin
    70     begin
    71     s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
    71     s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
    72     WriteToConsole(msgLoading + s + ' ');
    72     WriteToConsole(msgLoading + string(s) + ' ');
    73     Soundz[i].id:= Mix_LoadWAV_RW(SDL_RWFromFile(PChar(s), 'rb'), 1);
    73     Soundz[i].id:= Mix_LoadWAV_RW(SDL_RWFromFile(@s, 'rb'), 1);
    74     TryDo(Soundz[i].id <> nil, msgFailed, true);
    74     TryDo(Soundz[i].id <> nil, msgFailed, true);
    75     WriteLnToConsole(msgOK);
    75     WriteLnToConsole(msgOK);
    76     end;
    76     end;
    77 
    77 
    78 s:= PathPrefix + '/Music/kahvi140a_alexander_chereshnev-illusion.ogg';
    78 s:= PathPrefix + '/Music/kahvi140a_alexander_chereshnev-illusion.ogg';
    79 WriteToConsole(msgLoading + s + ' ');
    79 WriteToConsole(msgLoading + string(s) + ' ');
    80 Mus:= Mix_LoadMUS(PChar(s));
    80 Mus:= Mix_LoadMUS(@s);
    81 TryDo(Mus <> nil, msgFailed, false);
    81 TryDo(Mus <> nil, msgFailed, false);
    82 WriteLnToConsole(msgOK)
    82 WriteLnToConsole(msgOK)
    83 end;
    83 end;
    84 
    84 
    85 procedure PlaySound(snd: TSound; const infinite: boolean = false);
    85 procedure PlaySound(snd: TSound; infinite: boolean);
    86 var loops: integer;
    86 var loops: integer;
    87 begin
    87 begin
    88 if not isSoundEnabled then exit;
    88 if not isSoundEnabled then exit;
    89 if infinite then loops:= -1 else loops:= 0;
    89 if infinite then loops:= -1 else loops:= 0;
    90 Soundz[snd].lastChan:= Mix_PlayChannelTimed(-1, Soundz[snd].id, loops, -1)
    90 Soundz[snd].lastChan:= Mix_PlayChannelTimed(-1, Soundz[snd].id, loops, -1)
   105 end;
   105 end;
   106 
   106 
   107 function ChangeVolume(voldelta: integer): integer;
   107 function ChangeVolume(voldelta: integer): integer;
   108 begin
   108 begin
   109 if not isSoundEnabled then
   109 if not isSoundEnabled then
   110    begin
   110    exit(0);
   111    Result:= 0;
   111 
   112    exit
       
   113    end;
       
   114 inc(Volume, voldelta);
   112 inc(Volume, voldelta);
   115 if Volume < 0 then Volume:= 0;
   113 if Volume < 0 then Volume:= 0;
   116 Mix_Volume(-1, Volume);
   114 Mix_Volume(-1, Volume);
   117 Volume:= Mix_Volume(-1, -1);
   115 Volume:= Mix_Volume(-1, -1);
   118 Mix_VolumeMusic(Volume * 3 div 8);
   116 Mix_VolumeMusic(Volume * 3 div 8);
   119 Result:= Volume * 100 div MIX_MAX_VOLUME
   117 ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
   120 end;
   118 end;
   121 
   119 
   122 end.
   120 end.