On peut toutefois jouer sur 1 bit des sons complexes, grâce à la technique PWM (Pulse Width Modulation). Le principe est très simple :
- Une porteuse rectangulaire de fréquence inaudible (supérieure à 19000 Hz)
- Modification du rapport cyclique (rapport entre la période des créneaux positifs et des créneaux négatifs) proportionnelle à l'échantillon à jouer.
J'ai voulu tester ce concept, voici un premier jet du programme pour MO5 : http://dcmoto.free.fr/sons/son1bit.zip
Le code n'est peut-être pas très clair car optimisé pour être rapide et court, mais si vous l'étudiez attentivement vous verrez que c'est très simple à programmer. Avec ces optimisations, on arrive à jouer des échantillons 3 bits à 22050 Hz. Il doit être difficile de faire beaucoup mieux. Peut-être 24000 Hz en rusant un peu...
Pour lancer l'application, chargez la cassette dans le MO5 et tapez RUN"
Ce n'est pas un produit fini, juste un test pour montrer la faisabilité. On ne peut même pas arrêter le programme quand il a commencé à jouer.
Code : Tout sélectionner
/**************************************************\
* S O N 1 B I T *
* (c) 2013 - Daniel Coulom *
* http://dcmoto.free.fr/ *
* http://forum.system-cfg.com/ *
*--------------------------------------------------*
* Ce code est distribue gratuitement dans l'espoir *
* qu'il sera utile, mais sans aucune garantie et *
* sans engager la responsabilité de l'auteur. *
* Vous pouvez l' utiliser, le modifier et le *
* diffuser librement, en conservant cette licence *
* et les références de l'auteur dans toutes les *
* copies. L'exploitation commerciale est interdite.*
\**************************************************/
* Ce programme joue des echantillons 3 bits 22050 Hz
* en les convertissant en signal tout ou rien 1 bit
* par modulation de largeur d'impulsion (PWM).
* Le fichier audio contient un echantillon par octet
* L'echantillon est place dans les bits b3, b2 et b1
/**************************************************\
* Version 2013.03.20 *
\**************************************************/
* Historique
* 2013.03.20 premiere version operationnelle
ORG $9F00
*------------------------------------------------------
* INITIALISATIONS
*------------------------------------------------------
INIT
9F00 347E PSHS U,Y,X,DP,B,A empile les registres utilises
9F02 1AD0 ORCC #$D0 desactive les interruptions
9F04 86A7 LDA #$A7 valeur pour DP
9F06 1F8B TFR A,DP initialisation DP
9F08 D6C1 LDB <$C1 valeur port B du PIA systeme
9F0A CA01 ORB #$01 set buzzer bit
9F0C 108E9F90 LDY #PLAYX adresse des generateurs PWM
*------------------------------------------------------
* BOUCLE DE LECTURE DU SON
*------------------------------------------------------
PLAYA
9F10 8E6000 LDX #$6000 adresse du buffer son
9F13 7E9FA0 JMP PLAYZ acquisition d'un echantillon
PLAY0
9F16 D7C1 STB <$C1 set buzzer bit
9F18 0AC1 DEC <$C1 clear buzzer bit
9F1A 8D72 BSR PLAY8 temporisation 14 cycles
9F1C 8C9000 CMPX #$9000 test de fin
9F1F 267F BNE PLAYZ echantillon suivant
9F21 20ED BRA PLAYA recommencer
PLAY1
9F23 D7C1 STB <$C1 set buzzer bit
9F25 12 NOP temporisation 2 cycles
9F26 0AC1 DEC <$C1 clear buzzer bit
9F28 8D65 BSR PLAY9 temporisation 12 cycles
9F2A 8C9000 CMPX #$9000 test de fin
9F2D 2671 BNE PLAYZ echantillon suivant
9F2F 20DF BRA PLAYA recommencer
PLAY2
9F31 D7C1 STB <$C1 set buzzer bit
9F33 D100 CMPB <$00 temporisation 4 cycles
9F35 0AC1 DEC <$C1 clear buzzer bit
9F37 9C00 CMPX <$00 temporisation 6 cycles
9F39 D100 CMPB <$00 temporisation 4 cycles
9F3B 8C9000 CMPX #$9000 test de fin
9F3E 2660 BNE PLAYZ echantillon suivant
9F40 20CE BRA PLAYA recommencer
PLAY3
9F42 D7C1 STB <$C1 set buzzer bit
9F44 9C00 CMPX <$00 temporisation 6 cycles
9F46 0AC1 DEC <$C1 clear buzzer bit
9F48 9C00 CMPX <$00 temporisation 6 cycles
9F4A 12 NOP temporisation 2 cycles
9F4B 8C9000 CMPX #$9000 test de fin
9F4E 2650 BNE PLAYZ echantillon suivant
9F50 20BE BRA PLAYA recommencer
PLAY4
9F52 D7C1 STB <$C1 set buzzer bit
9F54 9C00 CMPX <$00 temporisation 6 cycles
9F56 12 NOP temporisation 2 cycles
9F57 0AC1 DEC <$C1 clear buzzer bit
9F59 9C00 CMPX <$00 temporisation 6 cycles
9F5B 8C9000 CMPX #$9000 test de fin
9F5E 2640 BNE PLAYZ echantillon suivant
9F60 20AE BRA PLAYA recommencer
PLAY5
9F62 D7C1 STB <$C1 set buzzer bit
9F64 9C00 CMPX <$00 temporisation 6 cycles
9F66 D100 CMPB <$00 temporisation 4 cycles
9F68 0AC1 DEC <$C1 clear buzzer bit
9F6A D100 CMPB <$00 temporisation 4 cycles
9F6C 8C9000 CMPX #$9000 test de fin
9F6F 262F BNE PLAYZ echantillon suivant
9F71 209D BRA PLAYA recommencer
PLAY6
9F73 D7C1 STB <$C1 set buzzer bit
9F75 8D18 BSR PLAY9 temporisation 12 cycles
9F77 0AC1 DEC <$C1 clear buzzer bit
9F79 12 NOP temporisation 2 cycles
9F7A 8C9000 CMPX #$9000 test de fin
9F7D 2621 BNE PLAYZ echantillon suivant
9F7F 208F BRA PLAYA recommencer
PLAY7
9F81 D7C1 STB <$C1 set buzzer bit
9F83 8D09 BSR PLAY8 temporisation 14 cycles
9F85 0AC1 DEC <$C1 clear buzzer bit
9F87 8C9000 CMPX #$9000 test de fin
9F8A 2614 BNE PLAYZ echantillon suivant
9F8C 2082 BRA PLAYA recommencer
PLAY8
9F8E 12 NOP temporisation 2 cycles
PLAY9
9F8F 39 RTS temporisation 5 cycles
PLAYX
9F90 2084 BRA PLAY0 jouer echantillon 0
9F92 208F BRA PLAY1 jouer echantillon 1
9F94 209B BRA PLAY2 jouer echantillon 2
9F96 20AA BRA PLAY3 jouer echantillon 3
9F98 20B8 BRA PLAY4 jouer echantillon 4
9F9A 20C6 BRA PLAY5 jouer echantillon 5
9F9C 20D5 BRA PLAY6 jouer echantillon 6
9F9E 20E1 BRA PLAY7 jouer echantillon 7
PLAYZ
9FA0 A680 LDA ,X+ nouvel echantillon
9FA2 840E ANDA #$0E raz bit 0 non significatif
9FA4 6EA6 JMP A,Y jouer l'echantillon
*------------------------------------------------------
* RETOUR AU BASIC
*------------------------------------------------------
RETOUR
9FA6 35FE PULS A,B,DP,X,Y,U,PC retour au Basic
END
SYMBOL TABLE
INIT 02 9F00 PLAY0 02 9F16 PLAY1 02 9F23 PLAY2 02 9F31
PLAY3 02 9F42 PLAY4 02 9F52 PLAY5 02 9F62 PLAY6 02 9F73
PLAY7 02 9F81 PLAY8 02 9F8E PLAY9 02 9F8F PLAYA 02 9F10
PLAYX 02 9F90 PLAYZ 02 9FA0 RETOUR 02 9FA6
15 SYMBOLS
0 error(s), 0 warning(s)