Hello,
c'est encore moi et mes "essais".
Cette fois-ci je m'attaque à la production de son sur le contrôleur "musique et jeu" au moyen du port B.
J'ai réussi à produire un belle onde sinusoïdale avec le code suivant :
Code:
(main)sound.asm * Marquage du programme principal
CRB2 EQU $E7CF
DDRB2 EQU $E7CD
PORTB2 EQU $E7CD
ORG $A000
DEBUT
PSHS U,Y,X,DP,D,CC
JSR INIT
JSR PLAY_START
FIN
PULS CC,D,DP,X,Y,U,PC ; PC == RTS
* -------------------
* SELECTION DU PORT B
* -------------------
INIT
PSHS D
CLRB
STB CRB2 ; CRB2 = 00
LDD #$3F04 ; D(A+B) = 0011 1111 0000 0100
STA DDRB2 ; DDRB2 = A = 3F = 0011 1111
STB CRB2 ; CRB2 = B = 04 = 0000 0100
PULS D,PC ; PC == RTS
* -------------------
* Routine sonore
* -------------------
PLAY_START
PSHS Y,X,D,CC
ORCC #$10 ; no interrupt
SIN_START
CLRB ; B == increment de 0 -> 255
LDX #SIN
SEND_VALUE
LDA ,X+
STA PORTB2 ; produire le son sur 6 bits ($00 to $3F)
LDY #$0070 ; init valeur d'attente
INCB
BEQ SIN_START ; on recommence la SIN quand B == 0
JMP SEND_VALUE ; POUR L'INSTANT, BOUCLE INFINIE /!\
PLAY_END
PULS CC,D,X,Y,PC ; PC == RTS
* ---------------------------------------------------------------------------------------
* table de SINUS. l'amplitude est de 62 valeurs. (sur 64 possibles) de $01 (1) à $3E (62)
* ---------------------------------------------------------------------------------------
SIN
FCB $20,$21,$22,$23,$23,$24,$25,$26,$26,$27,$28,$28,$29,$2A,$2B,$2B
FCB $2C,$2D,$2D,$2E,$2F,$2F,$30,$31,$31,$32,$33,$33,$34,$34,$35,$35
FCB $36,$36,$37,$37,$38,$38,$39,$39,$3A,$3A,$3A,$3B,$3B,$3C,$3C,$3C
FCB $3C,$3D,$3D,$3D,$3D,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E
FCB $3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3E,$3D,$3D,$3D,$3D,$3C,$3C
FCB $3C,$3C,$3B,$3B,$3A,$3A,$3A,$39,$39,$38,$38,$37,$37,$36,$36,$35
FCB $35,$34,$34,$33,$33,$32,$31,$31,$30,$2F,$2F,$2E,$2D,$2D,$2C,$2B
FCB $2B,$2A,$29,$28,$28,$27,$26,$26,$25,$24,$23,$23,$22,$21,$20,$20
FCB $1F,$1E,$1D,$1C,$1C,$1B,$1A,$19,$19,$18,$17,$17,$16,$15,$14,$14
FCB $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0C,$0C,$0B,$0B,$0A,$0A
FCB $09,$09,$08,$08,$07,$07,$06,$06,$05,$05,$05,$04,$04,$03,$03,$03
FCB $03,$02,$02,$02,$02,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
FCB $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$02,$02,$02,$02,$03,$03
FCB $03,$03,$04,$04,$05,$05,$05,$06,$06,$07,$07,$08,$08,$09,$09,$0A
FCB $0A,$0B,$0B,$0C,$0C,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12,$13,$14
FCB $14,$15,$16,$17,$17,$18,$19,$19,$1A,$1B,$1C,$1C,$1D,$1E,$1F,$20
END DEBUT
Ca fonctionne bien, je suis content, ça donne ça :
J'ai voulu augmenter artificiellement la période de la sinusoïde, pour produire un son plus grave
J'ai donc rajouté une boucle de temporisation entre 2 changements de valeur :
Code:
* -------------------
* Routine sonore
* -------------------
PLAY_START
PSHS Y,X,D,CC
ORCC #$10 ; no interrupt
SIN_START
CLRB ; B == increment de 0 -> 255
LDX #SIN
SEND_VALUE
LDA ,X+
STA PORTB2 ; produire le son sur 6 bits ($00 to $3F)
LDY #$0070 ; init valeur d'attente
* > Boucle de temporisation
TEMPO
LEAY -1,Y ;
BNE TEMPO ; on boucle tant que Y != 0
* > Fin de boucle de temporisation
INCB
BEQ SIN_START ; on recommence la SIN quand B == 0
JMP SEND_VALUE ; POUR L'INSTANT, BOUCLE INFINIE /!\
PLAY_END
PULS CC,D,X,Y,PC ; PC == RTS
Mais je ne comprends pas le résultat obtenu.
J'aurais dû obtenir un son plus grave et à la place, il est plus aigu et, surtout, il ne semble pas correct.
Quand j'ouvre avec Audacity l'onde sonore :
Sans temporisation (son correct) :
Fichier(s) joint(s):
no-tempo.png [ 7.75 Kio | Vu 8665 fois ]
Avec temporisation (son incorrect) :
Fichier(s) joint(s):
tempo.png [ 7.51 Kio | Vu 8665 fois ]
Quelque chose m'échappe. Qu'est-ce que je ne fais (ou comprends) pas bien ?
PS : je pense que c'est Sam qui va me répondre :-)