Login Register
Frontpage Code library Pastebin

SinWave

Author: MetalRain
Added: 9.4.2011 23:39
Edited: 15.4.2011 22:19
Category: Ääni & musiikki

Description

Valtzun toteuttama siniaallon .wav-tiedostoon rakentava funktio.

Code

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
// --- Äänifunktioita by Valtzu (2007) --- //

// Ääni tietyltä taajuudelta
Function SinWave(taajuus#, pituus#, voimakkuus#=100)
    fq=44100
    length=pituus*fq
    f=OpenToWrite("tmpwav.tmp")
    WriteInt f,$52494646
    WriteInt f,0
    WriteInt f,$57415645
    WriteInt f,$666d7420
    WriteInt f,16
    WriteShort f,1
    WriteShort f,1
    WriteInt f,fq
    WriteInt f,fq*2
    WriteShort f,2
    WriteShort f,16
    WriteInt f,$64617461
    WriteInt f,length*2
    vokke = voimakkuus/100*32767
    For i = 0 To length-1
        WriteShort f,Sin(360.0*taajuus/fq*(i Mod fq))*vokke
    Next i
    fs=FileOffset(f)-8
    SeekFile f,4
    WriteInt f,fs
    CloseFile f
    tmpsnd=LoadSound("tmpwav.tmp")
    DeleteFile "tmpwav.tmp"
    Return tmpsnd
End Function

Comments

No comments. You can be first!

Leave a comment

You must be logged in to comment.