[0..1] of tmemorystream;: integer;: integer ;, soundfilename: string;: TStringList;: boolean;: boolean;: boolean;: array of byte ; MakeComplexSound (n: integer; freqlist: TStrings; {mSec}: Integer; Volume: TVolumeLevel); MsPlaySound; savesound; LoadSound (name: string); checkplaying ;;: TForm1 ;: Integer=11025;// 8000, 11025, 22050, or 44100
{$ R * .DFM} math, U_SetFreq;makesoundname(name:string):string;n:integer;:string;:=extractfilename(name);:=pos(laquo;.raquo;,s);ngt;0 then delete (s, n, length (s) -n + 1);:=s ;; shapenames: array [0..3] of string=(laquo;Sineraquo;,laquo;Squareraquo;,laquo;Sawtoothraquo;,laquo;Triangleraquo;);:string=laquo;DEFAULT.SNDraquo;;TFreqObj.Create;create;:=newf;:=f;:=newp;:=newA;:=newSHAPE;;;TFreqObj.makestringrep;:=format(laquo;%5d (F:% 4d, P:% 4d, A:% 4d% S) , [ftemp, f, p, a, SHAPENAMES [SHAPE]]) ;;: Word=$ +0001 ;: string= RIFF ;: string= WAVE raquo ;;: string= fmt raquo ;;: string= data raquo ;; TForm1.MakeComplexSound (N: integer {stream # to use} ;: TStrings; {mSec}: Integer ;: TVolumeLevel) ;: TWaveFormatEx;, j, TempInt, RiffCount: integer ;: integer;: byte ;, maxval: integer;, ph, amp: double;: boolean;: integer;: string;, x: extended; WaveFormatEx do: =WAVE_FORMAT_PCM;:=Mono;:=SampleRate;:=$ +0008;:=(nChannels * wBitsPerSample) div 8;:=nSamplesPerSec * nBlockAlign;:=0 ;; [n]:=TMemoryStream.Create; MS [n] do :=(Duration * SampleRate) div +1000;:=Length (WaveId) + Length (FmtId) + SizeOf (DWORD) + (TWaveFormatEx) + Length (DataId) + SizeOf (DWORD) + DataCount; (RiffId [1], 4 );// Laquo; RIFF (RiffCount, SizeOf (DWORD));// File data size (WaveId [1], Length (WaveId));// Laquo; WAVE (FmtId [1], Length (FmtId));// Laquo; fmt :=SizeOf (TWaveFormatEx); (TempInt, SizeOf (DWORD));// TWaveFormat data size (WaveFormatEx, SizeOf (TWaveFormatEx));// WaveFormatEx record (DataId [1], Length (DataId));// Laquo; data (DataCount, SizeOf (DWORD));// Sound data size:=TFreqObj (freqlist.objects [0]). Ftemp;:=0;:=false;:=samplerate div 2; i:=0 to trunc (2/minfreq * samplerate) do:=0 ; j:=0 to freqlist.count - 1 doTFreqObj (freqlist.objects [j]) lt; gt; nil thenTFreqObj (freqlist.objects [j]) doftemp gt; sampdiv2 then freqerror:=true;:=2 * Pi * Ftemp ;:=p/pi;:=soundvalue + trunc (Volume * a/1000 * sin (ph + i * w/SampleRate)) ;; soundvalue gt; maxvalmaxval:=soundvalue ;; i:=0 to DataCount - 1 do:= 127; j:=0 to freqlist.count - 1 doTFreqObj (freqlist.objects [j]) lt; gt; nil thenTFreqObj (freqlist.objects [j]) doftemp lt; sampdiv2 then:=samplerate/Ftemp; j=0 then setlength (imagedata, min (datacount, trunc (5 * ptspercycle)));:=frac (i/ptspercycle + p/360);:=a/1000;:= 2 * Pi * Ftemp;:=p/pi;:=soundvalue + trunc (Volume * amp * sin (ph + i * w/SampleRate)) ;;; maxval gt; 127 then byteval:=soundvalue * 127 div maxvalbyteval:=soundvalue ; (Byteval, SizeOf (Byte)); i lt;=high (imagedata) then imagedata [i]:=byteval ;;;; TForm1.msPlaySound; options: integer;:=SND_MEMORY or SND_ASYNC; duration.position=0 then options :=options or SND_LOOP; (MS [streaminuse] .Memory, 0, options) ;; TForm1.PlayBtnClick (Sender: TObject) ;: integer;: TStringlist;: integer;: integer;:=TStringlist.create; listbox1 doitems. count gt; 0 theni:=0 to items.count - 1 do if checked [i] freqlist.addobject (items [i], items.objects [i]);:=(streaminuse + 1) mod 2; freqlist.count gt; 0 then:=duration.position; unitsgrp.itemindex=1 then dur:=dur * 1000; dur=0 then dur:=5000; (nextstream, freqlist, dur, Volbar.position);(sender);:=true;:=nextstream;;stopbtnclick(sender);.free;;;TForm1.StopBtnClick(Sender: TObject); (nil, 0, SND_Purge); assigned (ms [streaminuse]) then freeandnil (Ms [streaminuse]);:=false ;; TForm1.FormCreate (Sender: TObject);:=1; .activepage:=SoundSheet ; ( -Default.snd ) ;; TForm1.CheckPlaying; playing then playbtnclick(self)(self);(self);;;TForm1.savesound;:textfile;:integer;(ff,soundfilename);(ff);(ff,laquo;Draquo;,laquo; , duration.position, , unitsgrp.itemindex); i:=0 to listbox1.items.count - 1 dolistbox1, TFreqObj (items.objects [i]) do writeln (ff, (checked [i]), raquo ;, f, , p, , a, , shape, raquo;,stringrep);(ff);:=false;;TForm1.Loadsound(name:string);:textfile;:TFreqobj;:integer;:char;,units:integer;:=name;(ff,soundfilename);(ff);(ff,d);d=laquo;Draquo; then (ff, dur, units) ;. position:=dur; .itemindex:=units; reset (ff);:=makesoundname (soundfilename) ;. clear; not eof (ff) dolistbox1 do:=tfreqobj.create (0 , 0,0,0); t do readln (ff, chk, f, p, a, shape, stringrep) ;. ftemp:=tf; .AddObject (t.stringrep, t); [items.count - 1]:=chklt;gt;0;(ff);:=false;.position:=TFreqobj(listbox1.items.objects[0]).f;.position:=64;(self);;TForm1.FreqbarChange(Sender: TObject) ;: extended;: integer; freqbar.position gt; 0 thenlistbox1, items docount gt;=1 then:=freqbar.position/TFreqobj (objects [0]). F; .text:=inttostr (freqbar.position); i :=0 to count - 1 doobjects [i] lt; gt; nil thenTFreqObj (objects [i]) do:=round (f * scale) ;; [i]:=stringrep ;;;;;;...