un exemple de création de son par modulation de frequence.
(sans debugger) .
Code : Tout sélectionner
InitSprite()
InitKeyboard()
InitSound()
;------ création bruit ---------------------
!MOV dword[add_dat],0
e.f=1
For br=0 To 15000;- bruit de 15000 double echantillons
a.f+0.25 ;creation onde sinus 1
b.f+0.05;creation onde sinus 2
c.f+0.77;creation onde sinus 3
d.f+0.09;creation onde sinus 4
e-0.00029;son regressif
brh0.f=((Sin(a)+Sin(b)+Sin(c)+Sin(d))*32000/4)*e ;mixe le tout.
brsong.w=brh0
!PUSH eax
!PUSH ebx
!PUSH edi
!MOV ax,word[v_brsong]
!LEA edi,[donne] ;on place les echantillon a l adresse "donne"
!ADD edi,[add_dat]
!ADD dword[add_dat],4
!MOV word[edi],ax
!MOV word[edi+2],ax
!POP edi
!POP ebx
!POP eax
Next br
CatchSound(0,?music);on pointe le debut du fi
SoundVolume(0, 100);volume de 0 a 100
SoundFrequency(0, 5000);frequence du son de 1000 a 100000
If OpenScreen(0, 0, 8, "8")
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space) ;joue le son si la touche espace pressée
If ver_bruit=0
ver_bruit=1
PlaySound(0,0)
EndIf
Else
ver_bruit=0
EndIf
;---------
Until KeyboardPushed(#PB_Key_Escape)
EndIf
End
!section '.data' align 16
!add_dat:
!dd 0
music: ;ici 'l entete du fichier wave juste avant les echantillons
!db 052h,049h,046h,046h; (4 octets) : Constante "RIFF" (0x52,0x49,0x46,0x46)
!tail8:
!dd 15000-8 ; (4 octets) : Taille du fichier moins 8 octets
!db 057h,041h,056h,045h ; (4 octets) : Format = "WAVE" (0x57,0x41,0x56,0x45)
!db 066h,06dh,074h,020h ; (4 octets) : Identifiant "fmt " (0x66,0x6D,0x74,0x20)
!dd 16 ; (4 octets) : Nombre d'octets utilisés pour définir en détail le contenu
!dw 1 ; (2 octets) : Format de fichier (1: PCM, ...)
!dw 2 ; (2 octets) : Nombre de canaux (1 pour mono ou 2 pour stéréo)
!dd 22050 ; (4 octets) : Fréquence d'échantillonnage (en Hertz)
!dd 88200 ; (4 octets) : Nombre d'octets par seconde de musique
!dw 4 ; (2 octets) : Nombre d'octets par échantillon
!dw 16; (2 octets) : Nombre de bits par donnée
!db 064h,061h,074h,061h; (4 octets) : Constante "data" (0x64,0x61,0x74,0x61)
!tail44:
!dd 15000-44; (4 octets) : Taille du fichier moins 44 octets
!donne: ;ici les echantillons
!rb 500000