Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns » Sound/s/sound
Sound/s/sound
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns |
Filename: | Sound/s/sound |
Read OK: | ✔ |
File size: | 0F83 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
XSound_Configure * &60140 ; ; C prototype: ; char *voice_base ; points to new voice generator ; ; char *wave_base ; points to sample to be played ; nb this must be allocated and filled by C code ; ; char *wave_end ; points one byte beyond sample end ; nb this must be set by C code ; EXPORT voice_base EXPORT wave_base EXPORT wave_end voice_base DCD voicebase wave_base DCD 0 wave_end DCD 0 voicebase B fill B fill B gateon B gateoff B instance LDMFD sp!, {pc} LDMFD sp!, {pc} DCD voicename-voicebase voicename DCB "VoiceOfChaos", 0 ALIGN logampptr DCD 0 instance STMFD sp!, {r0-r4} MOV r0, #0 MOV r1, #0 MOV r2, #0 MOV r3, #0 MOV r4, #0 SWI XSound_Configure LDRVC r0, [r3, #12] STRVC r0, logampptr STRVS r0, [sp] LDMFD sp!, {r0-r4, pc} gateon LDR r0, wave_base STR r0, [r9, #16] ;work reg 5 - waveptr STR r0, [r9, #24] ;work reg 7 - wavebase LDR r0, logampptr STR r0, [r9, #20] ;work reg 6 - log amp table ptr LDR r0, wave_end STR r0, [r9, #28] ;work reg 8 - waveend fill LDMIA r9, {r1-r8} AND r1, r1, #&7f LDRB r1, [r6, r1, LSL #1] MOV r1, r1, LSR #1 RSB r1, r1, #127 fillloop LDRB r0, [r5], #1 CMP r5, r8 MOVHS r5, r7 SUBS r0, r0, r1, LSL #1 MOVMI r0, #0 STRB r0, [r12], r11 LDRB r0, [r5], #1 CMP r5, r8 MOVHS r5, r7 SUBS r0, r0, r1, LSL #1 MOVMI r0, #0 STRB r0, [r12], r11 CMP r12, r10 BLT fillloop SUBS r4, r4, #1 STMIB r9, {r2-r5} MOVPL r0, #2_00001000 MOVMI r0, #2_00000010 LDMFD sp!, {pc} gateoff MOV r0, #0 flushloop STRB r0, [r12], r11 STRB r0, [r12], r11 CMP r12, r10 BLT flushloop MOV r0, #2_00000001 LDMFD sp!, {pc} ; pitch16 ; a leaf APCS function ; ; C prototype: ; int pitch16(int a) ; ; returns 16 bit phase accumulator increment (pai) for given pitch a, where a has standard format: ; bits 14-12 giving the octave number ; bits 11-0 giving the fraction of an octave in 1/4096'ths of an octave ; and where a value of 0x4000 corresponds to middle C ; ; note this is on the basis that A above middle C has frequency 440Hz, and we adopt equal temperament ; tuning of the chromatic scale putting middle C 9/12'ths of an octave below 440Hz, ie at 440/(2^0.75) ; ; notes on actual calculation: ; ; set f = frequency of note of pitch a ; set s = sample period (=1/sample frequency) ; then returned pai = 65536*f*s ; assume s = default value of 48e-6 seconds, giving pai = (65536*48e-6)*f ; ; further note given above format of a and frequency of middle C, we also have ; f = (220*2^0.25) * 2^(a/4096 - 4) ; thus pai = 65536*(48e-6)*220*(2^0.25)/16 * 2^(a/4096) ; ie setting q = 4096*(48e-6)*220*(2^0.25) = 51.43767914 (approx) ; pai = q*2^(a/4096) ; ; to evaluate this we split a into octave number i and fraction m, ie a=4096i+m ; thence pai = q*2^(i+m/4096) = ( 2^(m/4096) * q ) << i ; calc of 2^(m/4096) is done by polynomial approximation utilising minimal accuracy needed to give pai ; accurate to nearest integer (more or less!), with mul by constant q coded directly using shifted ADDs,SUBs ; etc ; ; when using pitch16, always remember it assumes the default value for s=48e-6 seconds ; pitch16 is about 10 times faster than Sound_Pitch ; EXPORT pitch16 phnsta DCB "pitch16", 0 ALIGN phnend DCD &ff000000 + phnend - phnsta pitch16 CMP a1, #&8000 MOVHSS pc, lr MOV a4, a1, ASR #12 BIC a1, a1, a4, LSL #12 MOV a1, a1, LSL #5 SUB a1, a1, #&10000 ADD a3, a1, a1, LSL #2 ADD a2, a3, a1, LSL #3 ADD a2, a2, a1, LSL #7 ADD a2, a2, a3, LSL #11 MOV a2, a2, ASR #16 ADD a2, a2, #&010000 ADD a2, a2, #&005F00 ADD a2, a2, #&000062 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&070000 ADD a2, a2, #&00D700 ADD a2, a2, #&000073 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&160000 ADD a2, a2, #&00A000 ADD a2, a2, #&00002E RSB a1, a2, a2, LSL #3 RSB a3, a2, a2, LSL #2 ADD a1, a1, a3, LSL #4 ADD a1, a1, a3, LSL #8 RSB a4, a4, #24 MOVS a1, a1, LSR a4 ADC a1, a1, #0 MOVS pc, lr END
00000000 0a 58 53 6f 75 6e 64 5f 43 6f 6e 66 69 67 75 72 |.XSound_Configur| 00000010 65 09 2a 09 26 36 30 31 34 30 0a 0a 3b 0a 3b 20 |e.*.&60140..;.; | 00000020 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a 3b 20 63 |C prototype:.; c| 00000030 68 61 72 20 2a 76 6f 69 63 65 5f 62 61 73 65 0a |har *voice_base.| 00000040 3b 20 70 6f 69 6e 74 73 20 74 6f 20 6e 65 77 20 |; points to new | 00000050 76 6f 69 63 65 20 67 65 6e 65 72 61 74 6f 72 0a |voice generator.| 00000060 3b 0a 3b 20 63 68 61 72 20 2a 77 61 76 65 5f 62 |;.; char *wave_b| 00000070 61 73 65 0a 3b 20 70 6f 69 6e 74 73 20 74 6f 20 |ase.; points to | 00000080 73 61 6d 70 6c 65 20 74 6f 20 62 65 20 70 6c 61 |sample to be pla| 00000090 79 65 64 0a 3b 20 6e 62 20 74 68 69 73 20 6d 75 |yed.; nb this mu| 000000a0 73 74 20 62 65 20 61 6c 6c 6f 63 61 74 65 64 20 |st be allocated | 000000b0 61 6e 64 20 66 69 6c 6c 65 64 20 62 79 20 43 20 |and filled by C | 000000c0 63 6f 64 65 0a 3b 0a 3b 20 63 68 61 72 20 2a 77 |code.;.; char *w| 000000d0 61 76 65 5f 65 6e 64 0a 3b 20 70 6f 69 6e 74 73 |ave_end.; points| 000000e0 20 6f 6e 65 20 62 79 74 65 20 62 65 79 6f 6e 64 | one byte beyond| 000000f0 20 73 61 6d 70 6c 65 20 65 6e 64 0a 3b 20 6e 62 | sample end.; nb| 00000100 20 74 68 69 73 20 6d 75 73 74 20 62 65 20 73 65 | this must be se| 00000110 74 20 62 79 20 43 20 63 6f 64 65 0a 3b 0a 0a 09 |t by C code.;...| 00000120 45 58 50 4f 52 54 09 76 6f 69 63 65 5f 62 61 73 |EXPORT.voice_bas| 00000130 65 0a 09 45 58 50 4f 52 54 09 77 61 76 65 5f 62 |e..EXPORT.wave_b| 00000140 61 73 65 0a 09 45 58 50 4f 52 54 09 77 61 76 65 |ase..EXPORT.wave| 00000150 5f 65 6e 64 0a 0a 76 6f 69 63 65 5f 62 61 73 65 |_end..voice_base| 00000160 0a 09 44 43 44 09 76 6f 69 63 65 62 61 73 65 0a |..DCD.voicebase.| 00000170 77 61 76 65 5f 62 61 73 65 0a 09 44 43 44 09 30 |wave_base..DCD.0| 00000180 0a 77 61 76 65 5f 65 6e 64 0a 09 44 43 44 09 30 |.wave_end..DCD.0| 00000190 0a 0a 76 6f 69 63 65 62 61 73 65 0a 09 42 09 66 |..voicebase..B.f| 000001a0 69 6c 6c 0a 09 42 09 66 69 6c 6c 0a 09 42 09 67 |ill..B.fill..B.g| 000001b0 61 74 65 6f 6e 0a 09 42 09 67 61 74 65 6f 66 66 |ateon..B.gateoff| 000001c0 0a 09 42 09 69 6e 73 74 61 6e 63 65 0a 09 4c 44 |..B.instance..LD| 000001d0 4d 46 44 09 73 70 21 2c 20 7b 70 63 7d 0a 09 4c |MFD.sp!, {pc}..L| 000001e0 44 4d 46 44 09 73 70 21 2c 20 7b 70 63 7d 0a 09 |DMFD.sp!, {pc}..| 000001f0 44 43 44 09 76 6f 69 63 65 6e 61 6d 65 2d 76 6f |DCD.voicename-vo| 00000200 69 63 65 62 61 73 65 0a 76 6f 69 63 65 6e 61 6d |icebase.voicenam| 00000210 65 0a 09 44 43 42 09 22 56 6f 69 63 65 4f 66 43 |e..DCB."VoiceOfC| 00000220 68 61 6f 73 22 2c 20 30 0a 09 41 4c 49 47 4e 0a |haos", 0..ALIGN.| 00000230 0a 6c 6f 67 61 6d 70 70 74 72 0a 09 44 43 44 09 |.logampptr..DCD.| 00000240 30 0a 0a 69 6e 73 74 61 6e 63 65 0a 09 53 54 4d |0..instance..STM| 00000250 46 44 09 73 70 21 2c 20 7b 72 30 2d 72 34 7d 0a |FD.sp!, {r0-r4}.| 00000260 09 4d 4f 56 09 72 30 2c 20 23 30 0a 09 4d 4f 56 |.MOV.r0, #0..MOV| 00000270 09 72 31 2c 20 23 30 0a 09 4d 4f 56 09 72 32 2c |.r1, #0..MOV.r2,| 00000280 20 23 30 0a 09 4d 4f 56 09 72 33 2c 20 23 30 0a | #0..MOV.r3, #0.| 00000290 09 4d 4f 56 09 72 34 2c 20 23 30 0a 09 53 57 49 |.MOV.r4, #0..SWI| 000002a0 09 58 53 6f 75 6e 64 5f 43 6f 6e 66 69 67 75 72 |.XSound_Configur| 000002b0 65 0a 09 4c 44 52 56 43 09 72 30 2c 20 5b 72 33 |e..LDRVC.r0, [r3| 000002c0 2c 20 23 31 32 5d 0a 09 53 54 52 56 43 09 72 30 |, #12]..STRVC.r0| 000002d0 2c 20 6c 6f 67 61 6d 70 70 74 72 0a 09 53 54 52 |, logampptr..STR| 000002e0 56 53 09 72 30 2c 20 5b 73 70 5d 0a 09 4c 44 4d |VS.r0, [sp]..LDM| 000002f0 46 44 09 73 70 21 2c 20 7b 72 30 2d 72 34 2c 20 |FD.sp!, {r0-r4, | 00000300 70 63 7d 0a 0a 67 61 74 65 6f 6e 0a 09 4c 44 52 |pc}..gateon..LDR| 00000310 09 72 30 2c 20 77 61 76 65 5f 62 61 73 65 0a 09 |.r0, wave_base..| 00000320 53 54 52 09 72 30 2c 20 5b 72 39 2c 20 23 31 36 |STR.r0, [r9, #16| 00000330 5d 09 09 3b 77 6f 72 6b 20 72 65 67 20 35 20 20 |]..;work reg 5 | 00000340 2d 20 20 77 61 76 65 70 74 72 0a 09 53 54 52 09 |- waveptr..STR.| 00000350 72 30 2c 20 5b 72 39 2c 20 23 32 34 5d 09 09 3b |r0, [r9, #24]..;| 00000360 77 6f 72 6b 20 72 65 67 20 37 20 20 2d 20 20 77 |work reg 7 - w| 00000370 61 76 65 62 61 73 65 0a 09 4c 44 52 09 72 30 2c |avebase..LDR.r0,| 00000380 20 6c 6f 67 61 6d 70 70 74 72 0a 09 53 54 52 09 | logampptr..STR.| 00000390 72 30 2c 20 5b 72 39 2c 20 23 32 30 5d 09 09 3b |r0, [r9, #20]..;| 000003a0 77 6f 72 6b 20 72 65 67 20 36 20 20 2d 20 20 6c |work reg 6 - l| 000003b0 6f 67 20 61 6d 70 20 74 61 62 6c 65 20 70 74 72 |og amp table ptr| 000003c0 0a 09 4c 44 52 09 72 30 2c 20 77 61 76 65 5f 65 |..LDR.r0, wave_e| 000003d0 6e 64 0a 09 53 54 52 09 72 30 2c 20 5b 72 39 2c |nd..STR.r0, [r9,| 000003e0 20 23 32 38 5d 09 09 3b 77 6f 72 6b 20 72 65 67 | #28]..;work reg| 000003f0 20 38 20 20 2d 20 20 77 61 76 65 65 6e 64 0a 0a | 8 - waveend..| 00000400 66 69 6c 6c 0a 09 4c 44 4d 49 41 09 72 39 2c 20 |fill..LDMIA.r9, | 00000410 7b 72 31 2d 72 38 7d 0a 09 41 4e 44 09 72 31 2c |{r1-r8}..AND.r1,| 00000420 20 72 31 2c 20 23 26 37 66 0a 09 4c 44 52 42 09 | r1, #&7f..LDRB.| 00000430 72 31 2c 20 5b 72 36 2c 20 72 31 2c 20 4c 53 4c |r1, [r6, r1, LSL| 00000440 20 23 31 5d 0a 09 4d 4f 56 09 72 31 2c 20 72 31 | #1]..MOV.r1, r1| 00000450 2c 20 4c 53 52 20 23 31 0a 09 52 53 42 09 72 31 |, LSR #1..RSB.r1| 00000460 2c 20 72 31 2c 20 23 31 32 37 0a 66 69 6c 6c 6c |, r1, #127.filll| 00000470 6f 6f 70 0a 09 4c 44 52 42 09 72 30 2c 20 5b 72 |oop..LDRB.r0, [r| 00000480 35 5d 2c 20 23 31 0a 09 43 4d 50 09 72 35 2c 20 |5], #1..CMP.r5, | 00000490 72 38 0a 09 4d 4f 56 48 53 09 72 35 2c 20 72 37 |r8..MOVHS.r5, r7| 000004a0 0a 09 53 55 42 53 09 72 30 2c 20 72 30 2c 20 72 |..SUBS.r0, r0, r| 000004b0 31 2c 20 4c 53 4c 20 23 31 0a 09 4d 4f 56 4d 49 |1, LSL #1..MOVMI| 000004c0 09 72 30 2c 20 23 30 0a 09 53 54 52 42 09 72 30 |.r0, #0..STRB.r0| 000004d0 2c 20 5b 72 31 32 5d 2c 20 72 31 31 0a 09 4c 44 |, [r12], r11..LD| 000004e0 52 42 09 72 30 2c 20 5b 72 35 5d 2c 20 23 31 0a |RB.r0, [r5], #1.| 000004f0 09 43 4d 50 09 72 35 2c 20 72 38 0a 09 4d 4f 56 |.CMP.r5, r8..MOV| 00000500 48 53 09 72 35 2c 20 72 37 0a 09 53 55 42 53 09 |HS.r5, r7..SUBS.| 00000510 72 30 2c 20 72 30 2c 20 72 31 2c 20 4c 53 4c 20 |r0, r0, r1, LSL | 00000520 23 31 0a 09 4d 4f 56 4d 49 09 72 30 2c 20 23 30 |#1..MOVMI.r0, #0| 00000530 0a 09 53 54 52 42 09 72 30 2c 20 5b 72 31 32 5d |..STRB.r0, [r12]| 00000540 2c 20 72 31 31 0a 09 43 4d 50 09 72 31 32 2c 20 |, r11..CMP.r12, | 00000550 72 31 30 0a 09 42 4c 54 09 66 69 6c 6c 6c 6f 6f |r10..BLT.fillloo| 00000560 70 0a 0a 09 53 55 42 53 09 72 34 2c 20 72 34 2c |p...SUBS.r4, r4,| 00000570 20 23 31 0a 09 53 54 4d 49 42 09 72 39 2c 20 7b | #1..STMIB.r9, {| 00000580 72 32 2d 72 35 7d 0a 09 4d 4f 56 50 4c 09 72 30 |r2-r5}..MOVPL.r0| 00000590 2c 20 23 32 5f 30 30 30 30 31 30 30 30 0a 09 4d |, #2_00001000..M| 000005a0 4f 56 4d 49 09 72 30 2c 20 23 32 5f 30 30 30 30 |OVMI.r0, #2_0000| 000005b0 30 30 31 30 0a 09 4c 44 4d 46 44 09 73 70 21 2c |0010..LDMFD.sp!,| 000005c0 20 7b 70 63 7d 0a 0a 67 61 74 65 6f 66 66 0a 09 | {pc}..gateoff..| 000005d0 4d 4f 56 09 72 30 2c 20 23 30 0a 66 6c 75 73 68 |MOV.r0, #0.flush| 000005e0 6c 6f 6f 70 0a 09 53 54 52 42 09 72 30 2c 20 5b |loop..STRB.r0, [| 000005f0 72 31 32 5d 2c 20 72 31 31 0a 09 53 54 52 42 09 |r12], r11..STRB.| 00000600 72 30 2c 20 5b 72 31 32 5d 2c 20 72 31 31 0a 09 |r0, [r12], r11..| 00000610 43 4d 50 09 72 31 32 2c 20 72 31 30 0a 09 42 4c |CMP.r12, r10..BL| 00000620 54 09 66 6c 75 73 68 6c 6f 6f 70 0a 09 4d 4f 56 |T.flushloop..MOV| 00000630 09 72 30 2c 20 23 32 5f 30 30 30 30 30 30 30 31 |.r0, #2_00000001| 00000640 0a 09 4c 44 4d 46 44 09 73 70 21 2c 20 7b 70 63 |..LDMFD.sp!, {pc| 00000650 7d 0a 0a 0a 0a 3b 20 70 69 74 63 68 31 36 0a 3b |}....; pitch16.;| 00000660 20 61 20 6c 65 61 66 20 41 50 43 53 20 66 75 6e | a leaf APCS fun| 00000670 63 74 69 6f 6e 0a 3b 0a 3b 20 43 20 70 72 6f 74 |ction.;.; C prot| 00000680 6f 74 79 70 65 3a 0a 3b 20 69 6e 74 20 70 69 74 |otype:.; int pit| 00000690 63 68 31 36 28 69 6e 74 20 61 29 0a 3b 0a 3b 20 |ch16(int a).;.; | 000006a0 72 65 74 75 72 6e 73 20 31 36 20 62 69 74 20 70 |returns 16 bit p| 000006b0 68 61 73 65 20 61 63 63 75 6d 75 6c 61 74 6f 72 |hase accumulator| 000006c0 20 69 6e 63 72 65 6d 65 6e 74 20 28 70 61 69 29 | increment (pai)| 000006d0 20 66 6f 72 20 67 69 76 65 6e 20 70 69 74 63 68 | for given pitch| 000006e0 20 61 2c 20 77 68 65 72 65 20 61 20 68 61 73 20 | a, where a has | 000006f0 73 74 61 6e 64 61 72 64 20 66 6f 72 6d 61 74 3a |standard format:| 00000700 0a 3b 20 62 69 74 73 20 31 34 2d 31 32 20 67 69 |.; bits 14-12 gi| 00000710 76 69 6e 67 20 74 68 65 20 6f 63 74 61 76 65 20 |ving the octave | 00000720 6e 75 6d 62 65 72 0a 3b 20 62 69 74 73 20 31 31 |number.; bits 11| 00000730 2d 30 20 67 69 76 69 6e 67 20 74 68 65 20 66 72 |-0 giving the fr| 00000740 61 63 74 69 6f 6e 20 6f 66 20 61 6e 20 6f 63 74 |action of an oct| 00000750 61 76 65 20 69 6e 20 31 2f 34 30 39 36 27 74 68 |ave in 1/4096'th| 00000760 73 20 6f 66 20 61 6e 20 6f 63 74 61 76 65 0a 3b |s of an octave.;| 00000770 20 61 6e 64 20 77 68 65 72 65 20 61 20 76 61 6c | and where a val| 00000780 75 65 20 6f 66 20 30 78 34 30 30 30 20 63 6f 72 |ue of 0x4000 cor| 00000790 72 65 73 70 6f 6e 64 73 20 74 6f 20 6d 69 64 64 |responds to midd| 000007a0 6c 65 20 43 0a 3b 0a 3b 20 6e 6f 74 65 20 74 68 |le C.;.; note th| 000007b0 69 73 20 69 73 20 6f 6e 20 74 68 65 20 62 61 73 |is is on the bas| 000007c0 69 73 20 74 68 61 74 20 41 20 61 62 6f 76 65 20 |is that A above | 000007d0 6d 69 64 64 6c 65 20 43 20 68 61 73 20 66 72 65 |middle C has fre| 000007e0 71 75 65 6e 63 79 20 34 34 30 48 7a 2c 20 61 6e |quency 440Hz, an| 000007f0 64 20 77 65 20 61 64 6f 70 74 20 65 71 75 61 6c |d we adopt equal| 00000800 20 74 65 6d 70 65 72 61 6d 65 6e 74 0a 3b 20 74 | temperament.; t| 00000810 75 6e 69 6e 67 20 6f 66 20 74 68 65 20 63 68 72 |uning of the chr| 00000820 6f 6d 61 74 69 63 20 73 63 61 6c 65 20 70 75 74 |omatic scale put| 00000830 74 69 6e 67 20 6d 69 64 64 6c 65 20 43 20 39 2f |ting middle C 9/| 00000840 31 32 27 74 68 73 20 6f 66 20 61 6e 20 6f 63 74 |12'ths of an oct| 00000850 61 76 65 20 62 65 6c 6f 77 20 34 34 30 48 7a 2c |ave below 440Hz,| 00000860 20 69 65 20 61 74 20 34 34 30 2f 28 32 5e 30 2e | ie at 440/(2^0.| 00000870 37 35 29 0a 3b 0a 3b 20 6e 6f 74 65 73 20 6f 6e |75).;.; notes on| 00000880 20 61 63 74 75 61 6c 20 63 61 6c 63 75 6c 61 74 | actual calculat| 00000890 69 6f 6e 3a 0a 3b 0a 3b 20 73 65 74 20 66 20 3d |ion:.;.; set f =| 000008a0 20 66 72 65 71 75 65 6e 63 79 20 6f 66 20 6e 6f | frequency of no| 000008b0 74 65 20 6f 66 20 70 69 74 63 68 20 61 0a 3b 20 |te of pitch a.; | 000008c0 73 65 74 20 73 20 3d 20 73 61 6d 70 6c 65 20 70 |set s = sample p| 000008d0 65 72 69 6f 64 20 28 3d 31 2f 73 61 6d 70 6c 65 |eriod (=1/sample| 000008e0 20 66 72 65 71 75 65 6e 63 79 29 0a 3b 20 74 68 | frequency).; th| 000008f0 65 6e 20 72 65 74 75 72 6e 65 64 20 70 61 69 20 |en returned pai | 00000900 3d 20 36 35 35 33 36 2a 66 2a 73 0a 3b 20 61 73 |= 65536*f*s.; as| 00000910 73 75 6d 65 20 73 20 3d 20 64 65 66 61 75 6c 74 |sume s = default| 00000920 20 76 61 6c 75 65 20 6f 66 20 34 38 65 2d 36 20 | value of 48e-6 | 00000930 73 65 63 6f 6e 64 73 2c 20 67 69 76 69 6e 67 20 |seconds, giving | 00000940 70 61 69 20 3d 20 28 36 35 35 33 36 2a 34 38 65 |pai = (65536*48e| 00000950 2d 36 29 2a 66 0a 3b 0a 3b 20 66 75 72 74 68 65 |-6)*f.;.; furthe| 00000960 72 20 6e 6f 74 65 20 67 69 76 65 6e 20 61 62 6f |r note given abo| 00000970 76 65 20 66 6f 72 6d 61 74 20 6f 66 20 61 20 61 |ve format of a a| 00000980 6e 64 20 66 72 65 71 75 65 6e 63 79 20 6f 66 20 |nd frequency of | 00000990 6d 69 64 64 6c 65 20 43 2c 20 77 65 20 61 6c 73 |middle C, we als| 000009a0 6f 20 68 61 76 65 0a 3b 20 66 20 3d 20 28 32 32 |o have.; f = (22| 000009b0 30 2a 32 5e 30 2e 32 35 29 20 2a 20 32 5e 28 61 |0*2^0.25) * 2^(a| 000009c0 2f 34 30 39 36 20 2d 20 34 29 0a 3b 20 74 68 75 |/4096 - 4).; thu| 000009d0 73 20 70 61 69 20 3d 20 36 35 35 33 36 2a 28 34 |s pai = 65536*(4| 000009e0 38 65 2d 36 29 2a 32 32 30 2a 28 32 5e 30 2e 32 |8e-6)*220*(2^0.2| 000009f0 35 29 2f 31 36 20 2a 20 32 5e 28 61 2f 34 30 39 |5)/16 * 2^(a/409| 00000a00 36 29 0a 3b 20 69 65 20 73 65 74 74 69 6e 67 20 |6).; ie setting | 00000a10 71 20 3d 20 34 30 39 36 2a 28 34 38 65 2d 36 29 |q = 4096*(48e-6)| 00000a20 2a 32 32 30 2a 28 32 5e 30 2e 32 35 29 20 3d 20 |*220*(2^0.25) = | 00000a30 35 31 2e 34 33 37 36 37 39 31 34 20 28 61 70 70 |51.43767914 (app| 00000a40 72 6f 78 29 0a 3b 20 70 61 69 20 3d 20 71 2a 32 |rox).; pai = q*2| 00000a50 5e 28 61 2f 34 30 39 36 29 0a 3b 0a 3b 20 74 6f |^(a/4096).;.; to| 00000a60 20 65 76 61 6c 75 61 74 65 20 74 68 69 73 20 77 | evaluate this w| 00000a70 65 20 73 70 6c 69 74 20 61 20 69 6e 74 6f 20 6f |e split a into o| 00000a80 63 74 61 76 65 20 6e 75 6d 62 65 72 20 69 20 61 |ctave number i a| 00000a90 6e 64 20 66 72 61 63 74 69 6f 6e 20 6d 2c 20 69 |nd fraction m, i| 00000aa0 65 20 61 3d 34 30 39 36 69 2b 6d 0a 3b 20 74 68 |e a=4096i+m.; th| 00000ab0 65 6e 63 65 20 70 61 69 20 3d 20 71 2a 32 5e 28 |ence pai = q*2^(| 00000ac0 69 2b 6d 2f 34 30 39 36 29 20 3d 20 28 20 32 5e |i+m/4096) = ( 2^| 00000ad0 28 6d 2f 34 30 39 36 29 20 2a 20 71 20 29 20 3c |(m/4096) * q ) <| 00000ae0 3c 20 69 0a 3b 20 63 61 6c 63 20 6f 66 20 32 5e |< i.; calc of 2^| 00000af0 28 6d 2f 34 30 39 36 29 20 69 73 20 64 6f 6e 65 |(m/4096) is done| 00000b00 20 62 79 20 70 6f 6c 79 6e 6f 6d 69 61 6c 20 61 | by polynomial a| 00000b10 70 70 72 6f 78 69 6d 61 74 69 6f 6e 20 75 74 69 |pproximation uti| 00000b20 6c 69 73 69 6e 67 20 6d 69 6e 69 6d 61 6c 20 61 |lising minimal a| 00000b30 63 63 75 72 61 63 79 20 6e 65 65 64 65 64 20 74 |ccuracy needed t| 00000b40 6f 20 67 69 76 65 20 70 61 69 0a 3b 20 61 63 63 |o give pai.; acc| 00000b50 75 72 61 74 65 20 74 6f 20 6e 65 61 72 65 73 74 |urate to nearest| 00000b60 20 69 6e 74 65 67 65 72 20 28 6d 6f 72 65 20 6f | integer (more o| 00000b70 72 20 6c 65 73 73 21 29 2c 20 77 69 74 68 20 6d |r less!), with m| 00000b80 75 6c 20 62 79 20 63 6f 6e 73 74 61 6e 74 20 71 |ul by constant q| 00000b90 20 63 6f 64 65 64 20 64 69 72 65 63 74 6c 79 20 | coded directly | 00000ba0 75 73 69 6e 67 20 73 68 69 66 74 65 64 20 41 44 |using shifted AD| 00000bb0 44 73 2c 53 55 42 73 0a 3b 20 65 74 63 0a 3b 0a |Ds,SUBs.; etc.;.| 00000bc0 3b 20 77 68 65 6e 20 75 73 69 6e 67 20 70 69 74 |; when using pit| 00000bd0 63 68 31 36 2c 20 61 6c 77 61 79 73 20 72 65 6d |ch16, always rem| 00000be0 65 6d 62 65 72 20 69 74 20 61 73 73 75 6d 65 73 |ember it assumes| 00000bf0 20 74 68 65 20 64 65 66 61 75 6c 74 20 76 61 6c | the default val| 00000c00 75 65 20 66 6f 72 20 73 3d 34 38 65 2d 36 20 73 |ue for s=48e-6 s| 00000c10 65 63 6f 6e 64 73 0a 3b 20 70 69 74 63 68 31 36 |econds.; pitch16| 00000c20 20 69 73 20 61 62 6f 75 74 20 31 30 20 74 69 6d | is about 10 tim| 00000c30 65 73 20 66 61 73 74 65 72 20 74 68 61 6e 20 53 |es faster than S| 00000c40 6f 75 6e 64 5f 50 69 74 63 68 0a 3b 0a 0a 20 20 |ound_Pitch.;.. | 00000c50 20 20 20 20 20 20 45 58 50 4f 52 54 20 20 70 69 | EXPORT pi| 00000c60 74 63 68 31 36 0a 0a 70 68 6e 73 74 61 20 20 44 |tch16..phnsta D| 00000c70 43 42 20 20 20 20 20 22 70 69 74 63 68 31 36 22 |CB "pitch16"| 00000c80 2c 20 30 0a 20 20 20 20 20 20 20 20 41 4c 49 47 |, 0. ALIG| 00000c90 4e 0a 70 68 6e 65 6e 64 20 20 44 43 44 20 20 20 |N.phnend DCD | 00000ca0 20 20 26 66 66 30 30 30 30 30 30 20 2b 20 70 68 | &ff000000 + ph| 00000cb0 6e 65 6e 64 20 2d 20 70 68 6e 73 74 61 0a 0a 70 |nend - phnsta..p| 00000cc0 69 74 63 68 31 36 0a 0a 09 43 4d 50 09 61 31 2c |itch16...CMP.a1,| 00000cd0 20 23 26 38 30 30 30 0a 09 4d 4f 56 48 53 53 09 | #&8000..MOVHSS.| 00000ce0 70 63 2c 20 6c 72 0a 09 4d 4f 56 09 61 34 2c 20 |pc, lr..MOV.a4, | 00000cf0 61 31 2c 20 41 53 52 20 23 31 32 0a 09 42 49 43 |a1, ASR #12..BIC| 00000d00 09 61 31 2c 20 61 31 2c 20 61 34 2c 20 4c 53 4c |.a1, a1, a4, LSL| 00000d10 20 23 31 32 0a 09 4d 4f 56 09 61 31 2c 20 61 31 | #12..MOV.a1, a1| 00000d20 2c 20 4c 53 4c 20 23 35 0a 09 53 55 42 09 61 31 |, LSL #5..SUB.a1| 00000d30 2c 20 61 31 2c 20 23 26 31 30 30 30 30 0a 09 41 |, a1, #&10000..A| 00000d40 44 44 09 61 33 2c 20 61 31 2c 20 61 31 2c 20 4c |DD.a3, a1, a1, L| 00000d50 53 4c 20 23 32 0a 09 41 44 44 09 61 32 2c 20 61 |SL #2..ADD.a2, a| 00000d60 33 2c 20 61 31 2c 20 4c 53 4c 20 23 33 0a 09 41 |3, a1, LSL #3..A| 00000d70 44 44 09 61 32 2c 20 61 32 2c 20 61 31 2c 20 4c |DD.a2, a2, a1, L| 00000d80 53 4c 20 23 37 0a 09 41 44 44 09 61 32 2c 20 61 |SL #7..ADD.a2, a| 00000d90 32 2c 20 61 33 2c 20 4c 53 4c 20 23 31 31 0a 09 |2, a3, LSL #11..| 00000da0 4d 4f 56 09 61 32 2c 20 61 32 2c 20 41 53 52 20 |MOV.a2, a2, ASR | 00000db0 23 31 36 0a 09 41 44 44 09 61 32 2c 20 61 32 2c |#16..ADD.a2, a2,| 00000dc0 20 23 26 30 31 30 30 30 30 0a 09 41 44 44 09 61 | #&010000..ADD.a| 00000dd0 32 2c 20 61 32 2c 20 23 26 30 30 35 46 30 30 0a |2, a2, #&005F00.| 00000de0 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00000df0 30 30 30 36 32 0a 20 20 20 20 20 20 20 20 4d 4f |00062. MO| 00000e00 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 |V.ip, a1..mul16c| 00000e10 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a |.a2, ip, a2, a3.| 00000e20 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00000e30 37 30 30 30 30 0a 09 41 44 44 09 61 32 2c 20 61 |70000..ADD.a2, a| 00000e40 32 2c 20 23 26 30 30 44 37 30 30 0a 09 41 44 44 |2, #&00D700..ADD| 00000e50 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 37 |.a2, a2, #&00007| 00000e60 33 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 |3. MOV.ip| 00000e70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c |, a1..mul16c.a2,| 00000e80 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 44 | ip, a2, a3..ADD| 00000e90 09 61 32 2c 20 61 32 2c 20 23 26 31 36 30 30 30 |.a2, a2, #&16000| 00000ea0 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |0..ADD.a2, a2, #| 00000eb0 26 30 30 41 30 30 30 0a 09 41 44 44 09 61 32 2c |&00A000..ADD.a2,| 00000ec0 20 61 32 2c 20 23 26 30 30 30 30 32 45 0a 09 52 | a2, #&00002E..R| 00000ed0 53 42 09 61 31 2c 20 61 32 2c 20 61 32 2c 20 4c |SB.a1, a2, a2, L| 00000ee0 53 4c 20 23 33 0a 09 52 53 42 09 61 33 2c 20 61 |SL #3..RSB.a3, a| 00000ef0 32 2c 20 61 32 2c 20 4c 53 4c 20 23 32 0a 09 41 |2, a2, LSL #2..A| 00000f00 44 44 09 61 31 2c 20 61 31 2c 20 61 33 2c 20 4c |DD.a1, a1, a3, L| 00000f10 53 4c 20 23 34 0a 09 41 44 44 09 61 31 2c 20 61 |SL #4..ADD.a1, a| 00000f20 31 2c 20 61 33 2c 20 4c 53 4c 20 23 38 0a 09 52 |1, a3, LSL #8..R| 00000f30 53 42 09 61 34 2c 20 61 34 2c 20 23 32 34 0a 09 |SB.a4, a4, #24..| 00000f40 4d 4f 56 53 09 61 31 2c 20 61 31 2c 20 4c 53 52 |MOVS.a1, a1, LSR| 00000f50 20 61 34 0a 09 41 44 43 09 61 31 2c 20 61 31 2c | a4..ADC.a1, a1,| 00000f60 20 23 30 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 | #0. MOVS| 00000f70 20 20 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 09 45 | pc, lr.....E| 00000f80 4e 44 0a |ND.| 00000f83