Login Register
Frontpage Code library Pastebin

Code snippet #8

Added: 11. huhtikuuta 2011 kello 0.22
Owner: Pettis

Select all
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//==================================================================
// SinWave-funktio [ Valtzu ]
// -----------------------------
// Luo siniaaltoa lennosta ja lataa sen muistiin.
// * Funktion parametrit:
// - 1: Siniaallon taajuus hertseinä
// - 2: Äänen kesto sekunteina
// - 3: Äänen voimakkuus desim. lukuna välillä 0-100 (oletus 100)
// * Funktio palauttaa muistiin luodun äänen osoitteen CB:n ääni-
// funktioita ja -komentoja varten.
//==================================================================
 
// -----------------------------
// ESIMERKKI
// -----------------------------
 
Print "Paina näppäintä soittaaksesi siniaallon"
WaitKey
Cls
 
siniaalto = SinWave( 25000, 3.0, 90 ) // 25000Hz, 3.0s, 90 voimakkuus
PlaySound siniaalto
 
Print "Paina mitä tahansa näppäintä sulkeaksesi ohjelman"
 
WaitKey
If sndTMP Then DeleteSound sndTMP // Ääni pois muistista
 
// -----------------------------
// FUNKTIO
// -----------------------------
 
Function SinWave(taajuus#, pituus#, voimakkuus#=100)
length# = pituus * 44100
If FileExists("tmpwav.tmp") Then DeleteFile "tmpwav.tmp"
f=OpenToWrite("tmpwav.tmp")
If f=0 Then Return 0
WriteInt f,1179011410
WriteInt f,(36 + length)
WriteInt f,1163280727
WriteInt f,544501094
WriteInt f,16
WriteShort f,1
WriteShort f,1
WriteInt f,44100
WriteInt f,44100
WriteShort f,1
WriteShort f,8
WriteInt f,1635017060
WriteInt f,length
vokke = voimakkuus/100*127
For i = 1 To length
WriteByte f,128+Sin(taajuus/44100*i*2*3.14159265358979)*vokke
Next i
CloseFile f
tmpsnd=LoadSound("tmpwav.tmp")
DeleteFile "tmpwav.tmp"
Return tmpsnd
EndFunction