1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
34 TBasicSound = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
36 FChanNum: Integer; // <0: no channel allocated
44 function RawPlay(Pan: Single; Volume: Single; aPos: DWORD): Boolean;
45 function GetChan (): Integer;
47 property Channel: Integer read GetChan;
51 destructor Destroy(); override;
52 procedure SetID(ID: DWORD);
53 procedure FreeSound();
54 function IsPlaying(): Boolean;
56 function IsPaused(): Boolean;
57 procedure Pause(Enable: Boolean);
58 function GetVolume(): Single;
59 procedure SetVolume(Volume: Single);
60 function GetPan(): Single;
61 procedure SetPan(Pan: Single);
62 function IsMuted(): Boolean;
63 procedure Mute(Enable: Boolean);
64 function GetPosition(): DWORD;
65 procedure SetPosition(aPos: DWORD);
66 procedure SetPriority(priority: Integer);
70 NO_SOUND_ID = DWORD(-1);
72 function e_InitSoundSystem(NoOutput: Boolean = False): Boolean;
74 function e_LoadSound(FileName: string; var ID: DWORD; isMusic: Boolean): Boolean;
75 function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean;
77 // returns channel number or -1
78 function e_PlaySound(ID: DWORD): Integer;
79 function e_PlaySoundPan(ID: DWORD; Pan: Single): Integer;
80 function e_PlaySoundVolume(ID: DWORD; Volume: Single): Integer;
81 function e_PlaySoundPanVolume(ID: DWORD; Pan, Volume: Single): Integer;
83 procedure e_ModifyChannelsVolumes(SoundMod: Single; setMode: Boolean);
84 procedure e_MuteChannels(Enable: Boolean);
85 procedure e_StopChannels();
87 procedure e_DeleteSound(ID: DWORD);
88 procedure e_RemoveAllSounds();
89 procedure e_ReleaseSoundSystem();
90 procedure e_SoundUpdate();
93 e_SoundsArray: array of TSoundRec = nil;
102 N_MUSCHAN = N_CHANNELS+42;
106 id: DWORD; // sound id
108 oldvol: Integer; // for muted
113 SoundMuted: Boolean = False;
114 SoundInitialized: Boolean = False;
115 ChanSIds: array[0..N_CHANNELS] of TChanInfo;
116 MusVolume: Integer = MIX_MAX_VOLUME;
119 procedure chanFinished (chan: Integer); cdecl;
121 //e_WriteLog(Format('chanFinished: %d', [chan]), TMsgType.Notify);
122 if (chan >= 0) and (chan < N_CHANNELS) then
124 if ChanSIds[chan].id <> NO_SOUND_ID then
126 if (ChanSIds[chan].id <= High(e_SoundsArray)) and (e_SoundsArray[ChanSIds[chan].id].nRefs > 0) then
128 Dec(e_SoundsArray[ChanSIds[chan].id].nRefs);
130 ChanSIds[chan].id := NO_SOUND_ID;
136 procedure dumpMusicType (ms: PMix_Music);
140 e_WriteLog('MUSIC FORMAT: NONE', TMsgType.Notify);
144 case Mix_GetMusicType(ms^) of
145 TMix_MusicType.MUS_NONE:
146 e_WriteLog('MUSIC FORMAT: NONE', TMsgType.Notify);
147 TMix_MusicType.MUS_CMD:
148 e_WriteLog('MUSIC FORMAT: CMD', TMsgType.Notify);
149 TMix_MusicType.MUS_WAV:
150 e_WriteLog('MUSIC FORMAT: WAV', TMsgType.Notify);
151 TMix_MusicType.MUS_MOD:
152 e_WriteLog('MUSIC FORMAT: MOD', TMsgType.Notify);
153 TMix_MusicType.MUS_MID:
154 e_WriteLog('MUSIC FORMAT: MID', TMsgType.Notify);
155 TMix_MusicType.MUS_OGG:
156 e_WriteLog('MUSIC FORMAT: OGG', TMsgType.Notify);
157 TMix_MusicType.MUS_MP3:
158 e_WriteLog('MUSIC FORMAT: MP3', TMsgType.Notify);
159 TMix_MusicType.MUS_MP3_MAD:
160 e_WriteLog('MUSIC FORMAT: MP3_MAD', TMsgType.Notify);
161 TMix_MusicType.MUS_FLAC:
162 e_WriteLog('MUSIC FORMAT: FLAC', TMsgType.Notify);
163 TMix_MusicType.MUS_MODPLUG:
164 e_WriteLog('MUSIC FORMAT: MODPLUG', TMsgType.Notify);
166 e_WriteLog('MUSIC FORMAT: UNKNOWN', TMsgType.Notify);
171 function e_InitSoundSystem(NoOutput: Boolean = False): Boolean;
178 if SoundInitialized then begin Result := true; Exit end;
181 SoundInitialized := False;
183 if NoOutput then begin Result := true; Exit end;
185 // wow, this is actually MIDI player!
186 // we need module player
187 res := Mix_Init(MIX_INIT_FLAC or MIX_INIT_MOD or MIX_INIT_MODPLUG or MIX_INIT_MP3 or MIX_INIT_OGG or MIX_INIT_FLUIDSYNTH);
188 e_WriteLog(Format('SDL: res=0x%x', [res]), TMsgType.Notify);
189 if (res and MIX_INIT_FLAC) <> 0 then e_WriteLog('SDL: FLAC playback is active', TMsgType.Notify);
190 if (res and MIX_INIT_MOD) <> 0 then e_WriteLog('SDL: MOD playback is active', TMsgType.Notify);
191 if (res and MIX_INIT_MODPLUG) <> 0 then e_WriteLog('SDL: MODPLUG playback is active', TMsgType.Notify);
192 if (res and MIX_INIT_MP3) <> 0 then e_WriteLog('SDL: MP3 playback is active', TMsgType.Notify);
193 if (res and MIX_INIT_OGG) <> 0 then e_WriteLog('SDL: OGG playback is active', TMsgType.Notify);
194 if (res and MIX_INIT_FLUIDSYNTH) <> 0 then e_WriteLog('SDL: FLUIDSYNTH playback is active', TMsgType.Notify);
196 e_WriteLog(Format('SDL: initializing mixer at %d with buffer %d', [gsSDLSampleRate, gsSDLBufferSize]), TMsgType.Notify);
197 res := Mix_OpenAudio(gsSDLSampleRate, AUDIO_S16LSB, 2, gsSDLBufferSize);
200 e_WriteLog('Error initializing SDL mixer:', TMsgType.Fatal);
201 e_WriteLog(Mix_GetError(), TMsgType.Fatal);
205 if Mix_QuerySpec(@rfreq, @rformat, @rchans) > 0 then
207 e_WriteLog(Format('SDL: frequency=%d; format=%u; channels=%d', [rfreq, rformat, rchans]), TMsgType.Notify);
210 for i := 0 to Mix_GetNumChunkDecoders()-1 do
212 e_WriteLog(Format('SDL: chunk decoder %s is avalable', [Mix_GetChunkDecoder(i)]), TMsgType.Notify);
214 for i := 0 to Mix_GetNumMusicDecoders()-1 do
216 e_WriteLog(Format('SDL: music decoder %s is avalable', [Mix_GetMusicDecoder(i)]), TMsgType.Notify);
219 Mix_AllocateChannels(N_CHANNELS);
220 Mix_ChannelFinished(chanFinished);
222 for i := 0 to N_CHANNELS-1 do
224 ChanSIds[i].id := NO_SOUND_ID;
225 ChanSIds[i].muted := SoundMuted;
226 ChanSIds[i].oldvol := MIX_MAX_VOLUME;
227 ChanSIds[i].pan := 1.0;
229 MusVolume := MIX_MAX_VOLUME;
231 SoundInitialized := True;
235 function e_isMusic (id: DWORD): Boolean;
238 if (e_SoundsArray <> nil) and (id <= High(e_SoundsArray)) then
240 Result := (e_SoundsArray[id].Music <> nil);
244 function e_isSound (id: DWORD): Boolean;
247 if (e_SoundsArray <> nil) and (id <= High(e_SoundsArray)) then
249 Result := (e_SoundsArray[id].Sound <> nil);
253 function FindESound(): DWORD;
257 if e_SoundsArray <> nil then
259 for i := 0 to High(e_SoundsArray) do
260 if (e_SoundsArray[i].Sound = nil) and (e_SoundsArray[i].Music = nil) then
266 if e_SoundsArray = nil then
268 SetLength(e_SoundsArray, 16);
273 Result := High(e_SoundsArray) + 1;
274 SetLength(e_SoundsArray, Length(e_SoundsArray) + 16);
276 for i := Result to High(e_SoundsArray) do
278 e_SoundsArray[i].Sound := nil;
279 e_SoundsArray[i].Music := nil;
280 e_SoundsArray[i].Data := nil;
281 e_SoundsArray[i].isMusic := False;
282 e_SoundsArray[i].nRefs := 0;
286 function e_LoadSound(FileName: String; var ID: DWORD; isMusic: Boolean): Boolean;
292 if not SoundInitialized then Exit;
294 if isMusic then e_WriteLog('Loading music '+FileName+'...', TMsgType.Notify)
295 else e_WriteLog('Loading sound '+FileName+'...', TMsgType.Notify);
300 e_WriteLog('IGNORING MUSIC FROM FILE', TMsgType.Warning);
305 find_id := FindESound();
307 e_SoundsArray[find_id].Data := nil;
308 e_SoundsArray[find_id].isMusic := isMusic;
309 e_SoundsArray[find_id].nRefs := 0;
313 e_WriteLog(Format(' MUSIC SLOT: %u', [find_id]), TMsgType.Notify);
314 e_SoundsArray[find_id].Music := Mix_LoadMUS(PAnsiChar(FileName));
315 if e_SoundsArray[find_id].Music = nil then
317 e_WriteLog(Format('ERROR LOADING MUSIC:', [find_id]), TMsgType.Warning);
318 e_WriteLog(Mix_GetError(), TMsgType.Warning);
321 dumpMusicType(e_SoundsArray[find_id].Music);
325 e_SoundsArray[find_id].Sound := Mix_LoadWAV(PAnsiChar(FileName));
326 if e_SoundsArray[find_id].Sound = nil then Exit;
334 function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean;
343 if not SoundInitialized then Exit;
349 e_WriteLog('IGNORING MUSIC FROM MEMORY', TMsgType.Warning);
354 //FIXME: correctly skip ID3
357 if (Length > $400) and (pc[0] = 'I') and (pc[1] = 'D') and (pc[2] = '3') then
361 pData := Pointer(pc);
363 e_WriteLog('MUSIC: MP3 ID3 WORKAROUND APPLIED!', TMsgType.Warning);
367 rw := SDL_RWFromConstMem(pData, Length);
368 if rw = nil then Exit;
370 find_id := FindESound();
372 e_SoundsArray[find_id].Data := pData;
373 if isid3 then e_SoundsArray[find_id].Data := nil;
374 e_SoundsArray[find_id].isMusic := isMusic;
375 e_SoundsArray[find_id].nRefs := 0;
379 e_WriteLog(Format(' MUSIC SLOT: %u', [find_id]), TMsgType.Notify);
380 e_SoundsArray[find_id].Music := Mix_LoadMUS_RW(rw, 0);
381 if e_SoundsArray[find_id].Music = nil then
383 e_WriteLog(Format('ERROR LOADING MUSIC:', [find_id]), TMsgType.Warning);
384 e_WriteLog(Mix_GetError(), TMsgType.Warning);
388 dumpMusicType(e_SoundsArray[find_id].Music);
392 if e_SoundsArray[find_id].Music <> nil then
394 Mix_FreeMusic(e_SoundsArray[find_id].Music);
396 e_SoundsArray[find_id].Music := nil;
402 e_SoundsArray[find_id].Sound := Mix_LoadWAV_RW(rw, 0);
404 //SDL_FreeRW(rw); // somehow it segfaults...
405 if (e_SoundsArray[find_id].Sound = nil) and (e_SoundsArray[find_id].Music = nil) then
407 e_SoundsArray[find_id].Data := nil;
416 function e_PlaySound (ID: DWORD): Integer;
421 if not SoundInitialized then Exit;
423 if e_isSound(ID) then
425 if e_SoundsArray[ID].nRefs >= gMaxSimSounds then Exit;
426 Inc(e_SoundsArray[ID].nRefs);
427 res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, 0);
430 ChanSIds[res].id := ID;
431 ChanSIds[res].muted := SoundMuted;
432 if SoundMuted then Mix_Volume(res, 0) else Mix_Volume(res, ChanSIds[res].oldvol);
434 if e_SoundsArray[ID].isMusic then
435 res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, -1)
437 res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, 0);
443 if not e_isMusic(ID) then Exit;
445 res := Mix_PlayMusic(e_SoundsArray[ID].Music, -1);
446 if res >= 0 then res := N_MUSCHAN;
447 if SoundMuted then Mix_VolumeMusic(0) else Mix_VolumeMusic(MusVolume);
454 function e_chanSetPan (chan: Integer; Pan: Single): Boolean;
459 if chan = N_MUSCHAN then
461 // no panning for music
463 else if chan >= 0 then
465 if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
466 Pan := Pan+1.0; // 0..2
467 l := trunc(127.0*(2.0-Pan));
468 r := trunc(127.0*Pan);
469 Mix_SetPanning(chan, l, r);
470 ChanSIds[chan].pan := Pan;
478 function e_chanSetVol (chan: Integer; Volume: Single): Boolean;
483 if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
484 vol := trunc(Volume*MIX_MAX_VOLUME);
485 if chan = N_MUSCHAN then
488 if SoundMuted then Mix_VolumeMusic(0) else Mix_VolumeMusic(vol);
490 else if chan >= 0 then
492 ChanSIds[chan].oldvol := vol;
493 if ChanSIds[chan].muted then Mix_Volume(chan, 0) else Mix_Volume(chan, vol);
501 function e_PlaySoundPan(ID: DWORD; Pan: Single): Integer;
506 chan := e_PlaySound(ID);
507 e_chanSetPan(chan, Pan);
511 function e_PlaySoundVolume(ID: DWORD; Volume: Single): Integer;
516 chan := e_PlaySound(ID);
517 e_chanSetVol(chan, Volume);
521 function e_PlaySoundPanVolume(ID: DWORD; Pan, Volume: Single): Integer;
526 chan := e_PlaySound(ID);
527 e_chanSetPan(chan, Pan);
528 e_chanSetVol(chan, Volume);
532 procedure e_DeleteSound(ID: DWORD);
536 if ID > High(e_SoundsArray) then Exit;
537 if (e_SoundsArray[ID].Sound = nil) and (e_SoundsArray[ID].Music = nil) then Exit;
539 for i := 0 to N_CHANNELS-1 do
541 if ChanSIds[i].id = ID then
543 ChanSIds[i].id := NO_SOUND_ID;
548 if e_SoundsArray[ID].Sound <> nil then Mix_FreeChunk(e_SoundsArray[ID].Sound);
549 if e_SoundsArray[ID].Music <> nil then Mix_FreeMusic(e_SoundsArray[ID].Music);
550 if e_SoundsArray[ID].Data <> nil then FreeMem(e_SoundsArray[ID].Data);
552 e_SoundsArray[ID].Sound := nil;
553 e_SoundsArray[ID].Music := nil;
554 e_SoundsArray[ID].Data := nil;
555 e_SoundsArray[ID].nRefs := 0;
558 procedure e_ModifyChannelsVolumes(SoundMod: Single; setMode: Boolean);
564 for i := 0 to N_CHANNELS-1 do
566 ovol := ChanSIds[i].oldvol;
573 vol := (MIX_MAX_VOLUME+0.0)/ovol;
576 if vol < 0 then vol := 0 else if vol > 1 then vol := 1;
577 ChanSIds[i].oldvol := trunc(vol*MIX_MAX_VOLUME);
578 //if i = 0 then e_WriteLog(Format('modifying volumes: vol=%f; newvol=%d', [vol, ChanSIds[i].oldvol]), TMsgType.Warning);
579 if ChanSIds[i].muted then Mix_Volume(i, 0) else Mix_Volume(i, ChanSIds[i].oldvol);
581 ovol := Mix_VolumeMusic(-1);
590 vol := (MIX_MAX_VOLUME+0.0)/ovol;
591 vol := vol * SoundMod;
593 if vol < 0 then vol := 0 else if vol > 1 then vol := 1;
594 MusVolume := trunc(vol*MIX_MAX_VOLUME);
595 if SoundMuted then Mix_VolumeMusic(0) else Mix_VolumeMusic(MusVolume);
599 procedure e_MuteChannels(Enable: Boolean);
603 //if Enable = SoundMuted then Exit;
604 SoundMuted := Enable;
605 for i := 0 to N_CHANNELS-1 do
607 if ChanSIds[i].muted <> SoundMuted then
609 ChanSIds[i].muted := SoundMuted;
610 //e_WriteLog(Format('gmuting sound for channel %d', [i]), TMsgType.Warning);
611 if ChanSIds[i].muted then Mix_Volume(i, 0) else Mix_Volume(i, ChanSIds[i].oldvol);
614 //if SoundMuted then e_WriteLog('muting music', TMsgType.Notify) else e_WriteLog(Format('unmuting music (%d)', [MusVolume]), TMsgType.Notify);
615 if SoundMuted then Mix_VolumeMusic(0) else Mix_VolumeMusic(MusVolume);
618 procedure e_StopChannels();
624 for i := 0 to High(e_SoundsArray) do e_SoundsArray[i].nRefs := 0;
625 for i := 0 to N_CHANNELS-1 do ChanSIds[i].id := NO_SOUND_ID;
628 procedure e_RemoveAllSounds();
632 if SoundInitialized then e_StopChannels();
633 for i := 0 to High(e_SoundsArray) do e_DeleteSound(i);
634 SetLength(e_SoundsArray, 0);
635 e_SoundsArray := nil;
638 procedure e_ReleaseSoundSystem();
641 if SoundInitialized then
644 SoundInitialized := False;
648 procedure e_SoundUpdate();
650 //FMOD_System_Update(F_System);
656 constructor TBasicSound.Create();
665 destructor TBasicSound.Destroy();
671 function TBasicSound.GetChan (): Integer;
673 if (FID <> NO_SOUND_ID) and (FChanNum >= 0) and (FChanNum < N_CHANNELS) then
675 if ChanSIds[FChanNum].id <> FID then FChanNum := -1;
677 else if e_isMusic(FID) then
679 FChanNum := N_MUSCHAN;
684 procedure TBasicSound.FreeSound();
686 if FID = NO_SOUND_ID then Exit;
695 function TBasicSound.RawPlay(Pan: Single; Volume: Single; aPos: DWORD): Boolean;
698 if (FID = NO_SOUND_ID) or not SoundInitialized then Exit;
699 FChanNum := e_PlaySoundPanVolume(FID, Pan, Volume);
700 Result := (FChanNum >= 0);
701 //if e_isMusic(FID) then e_WriteLog(Format('playing music (%u)', [FID]), TMsgType.Notify);
705 procedure TBasicSound.SetID(ID: DWORD);
709 if ID <> NO_SOUND_ID then
711 FMusic := e_SoundsArray[ID].isMusic;
716 function TBasicSound.IsPlaying(): Boolean;
721 if e_isSound(FID) then
723 //e_WriteLog(Format('IsPlaying: FID=%u; FChanNum=%d', [FID, FChanNum]), TMsgType.Warning);
727 //e_WriteLog(Format('IsPlaying: FID=%u; ONA', [FID]), TMsgType.Warning);
730 //Result := (Mix_Playing(chan) > 0)
731 //e_WriteLog(Format('IsPlaying: FID=%u; TAN', [FID]), TMsgType.Warning);
734 else if e_isMusic(FID) then
736 Result := (Mix_PlayingMusic() > 0);
740 procedure TBasicSound.Stop();
744 if e_isSound(FID) then
750 Mix_HaltChannel(chan);
753 else if e_isMusic(FID) then
760 function TBasicSound.IsPaused(): Boolean;
765 if e_isSound(FID) then
768 if chan < 0 then Exit;
769 Result := (Mix_Paused(chan) > 0);
771 else if e_isMusic(FID) then
773 Result := (Mix_PausedMusic() > 0);
777 procedure TBasicSound.Pause(Enable: Boolean);
782 Enable := not Enable; // fuckin' double negation
783 if e_isSound(FID) then
786 if chan < 0 then Exit;
787 pl := not (Mix_Paused(chan) > 0);
790 if Enable then Mix_Resume(chan) else Mix_Pause(chan);
793 else if e_isMusic(FID) then
795 pl := not (Mix_PausedMusic() > 0);
798 if Enable then Mix_ResumeMusic() else Mix_PauseMusic();
804 res := FMOD_Channel_GetPosition(FChanNum, FPosition, FMOD_TIMEUNIT_MS);
805 if res <> FMOD_OK then
812 function TBasicSound.GetVolume(): Single;
817 if e_isSound(FID) then
820 if chan < 0 then Exit;
821 Result := (ChanSIds[chan].oldvol+0.0)/(MIX_MAX_VOLUME+0.0);
823 else if e_isMusic(FID) then
825 Result := (MusVolume+0.0)/(MIX_MAX_VOLUME+0.0);
829 procedure TBasicSound.SetVolume(Volume: Single);
833 if e_isSound(FID) then
836 if chan < 0 then Exit;
837 //e_WriteLog(Format('SetVolume: chan=%d; Volume=%f', [chan, Volume]), TMsgType.Warning);
838 e_chanSetVol(chan, Volume);
840 else if e_isMusic(FID) then
842 //e_WriteLog(Format('SetVolume: chan=MUSIC; Volume=%f', [Volume]), TMsgType.Warning);
843 e_chanSetVol(N_MUSCHAN, Volume);
847 function TBasicSound.GetPan(): Single;
852 if e_isSound(FID) then
855 if chan < 0 then Exit;
856 Result := ChanSIds[chan].pan;
860 procedure TBasicSound.SetPan(Pan: Single);
864 if e_isSound(FID) then
867 if chan < 0 then Exit;
868 e_chanSetPan(chan, Pan);
872 function TBasicSound.IsMuted(): Boolean;
877 if e_isSound(FID) then
880 if chan < 0 then Exit;
881 Result := ChanSIds[chan].muted;
883 else if e_isMusic(FID) then
885 Result := SoundMuted;
889 procedure TBasicSound.Mute(Enable: Boolean);
893 if e_isSound(FID) then
896 if chan < 0 then Exit;
897 if ChanSIds[chan].muted <> Enable then
899 //e_WriteLog(Format('muting sound for channel %d', [cnan]), TMsgType.Warning);
900 ChanSIds[chan].muted := Enable;
901 if ChanSIds[chan].muted then Mix_Volume(chan, 0) else Mix_Volume(chan, ChanSIds[chan].oldvol);
904 else if e_isMusic(FID) then
906 if Enable then Mix_VolumeMusic(0) else Mix_VolumeMusic(MusVolume);
911 function TBasicSound.GetPosition(): DWORD;
915 if FChanNum < 0 then Exit;
916 res := FMOD_Channel_GetPosition(FChanNum, FPosition, FMOD_TIMEUNIT_MS);
917 if res <> FMOD_OK then
926 procedure TBasicSound.SetPosition(aPos: DWORD);
930 if FChanNum < 0 then Exit;
931 res := FMOD_Channel_SetPosition(FChanNum, FPosition, FMOD_TIMEUNIT_MS);
932 if res <> FMOD_OK then
939 procedure TBasicSound.SetPriority(priority: Integer);
942 if (FChanNum <> nil) and (FPriority <> priority) and
943 (priority >= 0) and (priority <= 256) then
945 FPriority := priority;
946 res := FMOD_Channel_SetPriority(FChanNum, priority);
947 if res <> FMOD_OK then