Editor hudby pre programy v pascale
Delphi & Pascal (česká wiki)
Kategórie: KMP (Programy mladých programátorů)
Autor: Martin Koleček
Program: Editsnd.pas, Speaker.pas
Potřebné: Manual_snd.txt
Autor: Martin Koleček
Program: Editsnd.pas, Speaker.pas
Potřebné: Manual_snd.txt
S programem EditSnd.exe je mozne generovat soubory s priponou SND. Tyto soubory maji slouzit k ozvuceni programu na profesionalni urovni pomoci PC Speakeru. Vyuziva se k tomu preruseni od casovace nastavene na 100Hz tzn. vzorkovaci frekvence prehravanych zvuku je 100Hz. Nedochazi ke zhrouceni hodin vse je osetreno tak aby sly prehravat zvuky, aby spravne sly hodiny a zaroven aby program mohl vykonavat jine ulohy. Vse bezi na pozadi pres int8 viz. unit speaker.pas.
{ SPEAKER.PAS Copyright (c) Martin Kolecek } { Tato unita nastavuje novou obsluhu preruseni 8 (timer) a nastavuje} { frekvenci timeru na 100Hz. Pak na pozadi hraje hudbu pres speaker.} { } { Author: Martin Kolecek } { Datum: 18.05.2009 http://www.trsek.com } Unit Speaker; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} Interface Procedure InitSound; Procedure ShutdownSound; Procedure LoadSNDFile(Filename:String); Procedure PlaySound(Sample:Byte); Function FPS2s: Boolean; {pomoc pri vypoctu fps pomoci timeru} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} Implementation Uses Crt,Dos; {$F+} Var BIOSTimerHandler: procedure; clock_ticks,counter: longint; F: File; SoundData: array[0..1999] of Word; ZvukTab: array[0..99] of Word; PrehravatZvuk: Boolean; CisloZvuku:Byte; Posuv: Word; fps_helper: Byte; Procedure TimerHandler; Interrupt; Begin {prehravani} If PrehravatZvuk=True then Begin If SoundData[ZvukTab[CisloZvuku*2]+Posuv]>0 then Sound(SoundData[ZvukTab[CisloZvuku*2]+Posuv]) else NoSound; Inc(Posuv); If Posuv>ZvukTab[CisloZvuku*2+1] then {prehrali jsme celou delku zvuku} Begin PrehravatZvuk:=False; Posuv:=0; NoSound; End End; {helper pro vypocet fps kazde 2 sekundy} If fps_helper<200 then Inc(fps_helper) else fps_helper:=0; clock_ticks:=clock_ticks+counter; {volat BIOS obsluhu preruseni ?} If clock_ticks>=$10000 then Begin clock_ticks:=clock_ticks-$10000; asm pushf end; BIOSTimerHandler; End else Port[$20]:=$20; {konec preruseni} End; Procedure InitSound; Begin fps_helper:=0; clock_ticks:=0; counter:=$1234DD div 100; GetIntVec(8,@BIOSTimerHandler); SetIntVec(8,Addr(TimerHandler)); Port[$43]:=$34; Port[$40]:=counter mod 256; Port[$40]:=counter div 256; PrehravatZvuk:=False; End; Procedure ShutdownSound; Begin Port[$43]:=$34; Port[$40]:=0; Port[$40]:=0; SetIntVec(8, @BIOSTimerHandler); PrehravatZvuk:=False; End; Procedure LoadSNDFile(Filename:String); Begin Assign(F,Filename); Reset(F,1); BlockRead(F,SoundData,4000); BlockRead(F,ZvukTab,200); Close(F); End; Procedure PlaySound(Sample:Byte); Begin PrehravatZvuk:=True; {sdelime handleru int8 ze chceme prehravat} CisloZvuku:=Sample; {predame ktery zvuk se ma hrat} Posuv:=0; {nastavime na zacatek zvuku} End; Function FPS2s: Boolean; Begin If fps_helper<100 then FPS2s:=False {false v prvni vterine} else FPS2s:=True; {true ve druhe vterine} End; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} Begin End.