Home » Archimedes archive » Acorn User » AU 1998-02 A.adf » PDScheme » ArtToSpr/WavePlayer/Help/TextHelp/4b-Sound
ArtToSpr/WavePlayer/Help/TextHelp/4b-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 » Acorn User » AU 1998-02 A.adf » PDScheme |
Filename: | ArtToSpr/WavePlayer/Help/TextHelp/4b-Sound |
Read OK: | ✔ |
File size: | 08D7 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
+---------------------------------------------------------------------------+ | WAVE PLAYER | | � 1997, Matthew Wilson | +---------------------------------------------------------------------------+ | SOUND SYSTEM | +---------------------------------------------------------------------------+ This assumes you understand the basics of samples - see 'Samples'. Inside your computer, there is a digital to analogue converter (DAC). This turns the computer's numbers into voltages to give sound. To give a sound, the number has to be constantly changed. If the sample were obtained at 20kHz, then the number has to be changed every 50�s (0�000050secs). One way would be to interrupt the processor every 50�s, to find the next number to provide. However, this would be very time consuming, and may not always work - for instance, if the processor is loading a file off the disc, the delay between may be a few milliseconds before the sound interrupt could be dealt with. Therefore, a double-buffer system is used. Basically, what happens is that roughly every 1cs (0�01secs) the processor is interrupt to obtain the next 200 or so numbers. The DAC then takes each number at 50�s intervals, without the need to interrupt the processor. However, what happens when this buffer is exhausted? This is why /two/ buffers are used - one is already filled, and is being played; the other can be prepared whilst this is happening. In sequence, this is what happens: +------+----------------------------------------------------+ | Time | Event | +------+----------------------------------------------------+ | 0�00 | Buffer 1 is filled | | 0�01 | Buffer 1 begins playing, whilst buffer 2 is filled | | 0�02 | Buffer 2 begins playing, whilst buffer 1 is filled | | 0�03 | Buffer 1 begins playing, whilst buffer 2 is filled | | 0�04 | Buffer 2 begins playing, whilst buffer 1 is filled | +------+----------------------------------------------------+ This gives much more efficient way of working.
00000000 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |+---------------| 00000010 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 00000040 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2b 0a 7c 20 |------------+.| | 00000050 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000060 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 57 | W| 00000070 41 56 45 20 50 4c 41 59 45 52 20 20 20 20 20 20 |AVE PLAYER | 00000080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000090 20 20 20 20 20 20 20 20 20 20 7c 0a 7c 20 20 20 | |.| | 000000a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000000b0 20 20 20 20 20 20 20 a9 20 31 39 39 37 2c 20 4d | . 1997, M| 000000c0 61 74 74 68 65 77 20 57 69 6c 73 6f 6e 20 20 20 |atthew Wilson | 000000d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000000e0 20 20 20 20 20 20 20 20 7c 0a 2b 2d 2d 2d 2d 2d | |.+-----| 000000f0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 00000130 2d 2d 2d 2d 2d 2d 2b 0a 7c 20 20 20 20 20 20 20 |------+.| | 00000140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000150 20 20 20 20 20 20 20 20 53 4f 55 4e 44 20 20 53 | SOUND S| 00000160 59 53 54 45 4d 20 20 20 20 20 20 20 20 20 20 20 |YSTEM | 00000170 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000180 20 20 20 20 7c 0a 2b 2d 2d 2d 2d 2d 2d 2d 2d 2d | |.+---------| 00000190 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 000001d0 2d 2d 2b 0a 0a 20 20 54 68 69 73 20 61 73 73 75 |--+.. This assu| 000001e0 6d 65 73 20 79 6f 75 20 75 6e 64 65 72 73 74 61 |mes you understa| 000001f0 6e 64 20 74 68 65 20 62 61 73 69 63 73 20 6f 66 |nd the basics of| 00000200 20 73 61 6d 70 6c 65 73 20 2d 20 73 65 65 20 27 | samples - see '| 00000210 53 61 6d 70 6c 65 73 27 2e 0a 0a 20 20 49 6e 73 |Samples'... Ins| 00000220 69 64 65 20 79 6f 75 72 20 63 6f 6d 70 75 74 65 |ide your compute| 00000230 72 2c 20 74 68 65 72 65 20 69 73 20 61 20 64 69 |r, there is a di| 00000240 67 69 74 61 6c 20 74 6f 20 61 6e 61 6c 6f 67 75 |gital to analogu| 00000250 65 20 63 6f 6e 76 65 72 74 65 72 20 28 44 41 43 |e converter (DAC| 00000260 29 2e 20 54 68 69 73 0a 74 75 72 6e 73 20 74 68 |). This.turns th| 00000270 65 20 63 6f 6d 70 75 74 65 72 27 73 20 6e 75 6d |e computer's num| 00000280 62 65 72 73 20 69 6e 74 6f 20 76 6f 6c 74 61 67 |bers into voltag| 00000290 65 73 20 74 6f 20 67 69 76 65 20 73 6f 75 6e 64 |es to give sound| 000002a0 2e 20 54 6f 20 67 69 76 65 20 61 20 73 6f 75 6e |. To give a soun| 000002b0 64 2c 0a 74 68 65 20 6e 75 6d 62 65 72 20 68 61 |d,.the number ha| 000002c0 73 20 74 6f 20 62 65 20 63 6f 6e 73 74 61 6e 74 |s to be constant| 000002d0 6c 79 20 63 68 61 6e 67 65 64 2e 20 49 66 20 74 |ly changed. If t| 000002e0 68 65 20 73 61 6d 70 6c 65 20 77 65 72 65 20 6f |he sample were o| 000002f0 62 74 61 69 6e 65 64 20 61 74 0a 32 30 6b 48 7a |btained at.20kHz| 00000300 2c 20 74 68 65 6e 20 74 68 65 20 6e 75 6d 62 65 |, then the numbe| 00000310 72 20 68 61 73 20 74 6f 20 62 65 20 63 68 61 6e |r has to be chan| 00000320 67 65 64 20 65 76 65 72 79 20 35 30 b5 73 20 28 |ged every 50.s (| 00000330 30 b7 30 30 30 30 35 30 73 65 63 73 29 2e 20 4f |0.000050secs). O| 00000340 6e 65 20 77 61 79 0a 77 6f 75 6c 64 20 62 65 20 |ne way.would be | 00000350 74 6f 20 69 6e 74 65 72 72 75 70 74 20 74 68 65 |to interrupt the| 00000360 20 70 72 6f 63 65 73 73 6f 72 20 65 76 65 72 79 | processor every| 00000370 20 35 30 b5 73 2c 20 74 6f 20 66 69 6e 64 20 74 | 50.s, to find t| 00000380 68 65 20 6e 65 78 74 20 6e 75 6d 62 65 72 20 74 |he next number t| 00000390 6f 0a 70 72 6f 76 69 64 65 2e 20 48 6f 77 65 76 |o.provide. Howev| 000003a0 65 72 2c 20 74 68 69 73 20 77 6f 75 6c 64 20 62 |er, this would b| 000003b0 65 20 76 65 72 79 20 74 69 6d 65 20 63 6f 6e 73 |e very time cons| 000003c0 75 6d 69 6e 67 2c 20 61 6e 64 20 6d 61 79 20 6e |uming, and may n| 000003d0 6f 74 20 61 6c 77 61 79 73 20 77 6f 72 6b 0a 2d |ot always work.-| 000003e0 20 66 6f 72 20 69 6e 73 74 61 6e 63 65 2c 20 69 | for instance, i| 000003f0 66 20 74 68 65 20 70 72 6f 63 65 73 73 6f 72 20 |f the processor | 00000400 69 73 20 6c 6f 61 64 69 6e 67 20 61 20 66 69 6c |is loading a fil| 00000410 65 20 6f 66 66 20 74 68 65 20 64 69 73 63 2c 20 |e off the disc, | 00000420 74 68 65 20 64 65 6c 61 79 0a 62 65 74 77 65 65 |the delay.betwee| 00000430 6e 20 6d 61 79 20 62 65 20 61 20 66 65 77 20 6d |n may be a few m| 00000440 69 6c 6c 69 73 65 63 6f 6e 64 73 20 62 65 66 6f |illiseconds befo| 00000450 72 65 20 74 68 65 20 73 6f 75 6e 64 20 69 6e 74 |re the sound int| 00000460 65 72 72 75 70 74 20 63 6f 75 6c 64 20 62 65 20 |errupt could be | 00000470 64 65 61 6c 74 0a 77 69 74 68 2e 20 54 68 65 72 |dealt.with. Ther| 00000480 65 66 6f 72 65 2c 20 61 20 64 6f 75 62 6c 65 2d |efore, a double-| 00000490 62 75 66 66 65 72 20 73 79 73 74 65 6d 20 69 73 |buffer system is| 000004a0 20 75 73 65 64 2e 0a 0a 20 20 42 61 73 69 63 61 | used... Basica| 000004b0 6c 6c 79 2c 20 77 68 61 74 20 68 61 70 70 65 6e |lly, what happen| 000004c0 73 20 69 73 20 74 68 61 74 20 72 6f 75 67 68 6c |s is that roughl| 000004d0 79 20 65 76 65 72 79 20 31 63 73 20 28 30 b7 30 |y every 1cs (0.0| 000004e0 31 73 65 63 73 29 20 74 68 65 20 70 72 6f 63 65 |1secs) the proce| 000004f0 73 73 6f 72 0a 69 73 20 69 6e 74 65 72 72 75 70 |ssor.is interrup| 00000500 74 20 74 6f 20 6f 62 74 61 69 6e 20 74 68 65 20 |t to obtain the | 00000510 6e 65 78 74 20 32 30 30 20 6f 72 20 73 6f 20 6e |next 200 or so n| 00000520 75 6d 62 65 72 73 2e 20 54 68 65 20 44 41 43 20 |umbers. The DAC | 00000530 74 68 65 6e 20 74 61 6b 65 73 20 65 61 63 68 0a |then takes each.| 00000540 6e 75 6d 62 65 72 20 61 74 20 35 30 b5 73 20 69 |number at 50.s i| 00000550 6e 74 65 72 76 61 6c 73 2c 20 77 69 74 68 6f 75 |ntervals, withou| 00000560 74 20 74 68 65 20 6e 65 65 64 20 74 6f 20 69 6e |t the need to in| 00000570 74 65 72 72 75 70 74 20 74 68 65 20 70 72 6f 63 |terrupt the proc| 00000580 65 73 73 6f 72 2e 0a 48 6f 77 65 76 65 72 2c 20 |essor..However, | 00000590 77 68 61 74 20 68 61 70 70 65 6e 73 20 77 68 65 |what happens whe| 000005a0 6e 20 74 68 69 73 20 62 75 66 66 65 72 20 69 73 |n this buffer is| 000005b0 20 65 78 68 61 75 73 74 65 64 3f 20 54 68 69 73 | exhausted? This| 000005c0 20 69 73 20 77 68 79 20 2f 74 77 6f 2f 0a 62 75 | is why /two/.bu| 000005d0 66 66 65 72 73 20 61 72 65 20 75 73 65 64 20 2d |ffers are used -| 000005e0 20 6f 6e 65 20 69 73 20 61 6c 72 65 61 64 79 20 | one is already | 000005f0 66 69 6c 6c 65 64 2c 20 61 6e 64 20 69 73 20 62 |filled, and is b| 00000600 65 69 6e 67 20 70 6c 61 79 65 64 3b 20 74 68 65 |eing played; the| 00000610 20 6f 74 68 65 72 20 63 61 6e 0a 62 65 20 70 72 | other can.be pr| 00000620 65 70 61 72 65 64 20 77 68 69 6c 73 74 20 74 68 |epared whilst th| 00000630 69 73 20 69 73 20 68 61 70 70 65 6e 69 6e 67 2e |is is happening.| 00000640 20 49 6e 20 73 65 71 75 65 6e 63 65 2c 20 74 68 | In sequence, th| 00000650 69 73 20 69 73 20 77 68 61 74 20 68 61 70 70 65 |is is what happe| 00000660 6e 73 3a 0a 0a 20 20 2b 2d 2d 2d 2d 2d 2d 2b 2d |ns:.. +------+-| 00000670 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 000006a0 2d 2d 2d 2b 0a 20 20 7c 20 54 69 6d 65 20 7c 20 |---+. | Time | | 000006b0 45 76 65 6e 74 20 20 20 20 20 20 20 20 20 20 20 |Event | 000006c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 000006e0 20 20 20 7c 0a 20 20 2b 2d 2d 2d 2d 2d 2d 2b 2d | |. +------+-| 000006f0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 00000720 2d 2d 2d 2b 0a 20 20 7c 20 30 b7 30 30 20 7c 20 |---+. | 0.00 | | 00000730 42 75 66 66 65 72 20 31 20 69 73 20 66 69 6c 6c |Buffer 1 is fill| 00000740 65 64 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |ed | 00000750 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000760 20 20 20 7c 0a 20 20 7c 20 30 b7 30 31 20 7c 20 | |. | 0.01 | | 00000770 42 75 66 66 65 72 20 31 20 62 65 67 69 6e 73 20 |Buffer 1 begins | 00000780 70 6c 61 79 69 6e 67 2c 20 77 68 69 6c 73 74 20 |playing, whilst | 00000790 62 75 66 66 65 72 20 32 20 69 73 20 66 69 6c 6c |buffer 2 is fill| 000007a0 65 64 20 7c 0a 20 20 7c 20 30 b7 30 32 20 7c 20 |ed |. | 0.02 | | 000007b0 42 75 66 66 65 72 20 32 20 62 65 67 69 6e 73 20 |Buffer 2 begins | 000007c0 70 6c 61 79 69 6e 67 2c 20 77 68 69 6c 73 74 20 |playing, whilst | 000007d0 62 75 66 66 65 72 20 31 20 69 73 20 66 69 6c 6c |buffer 1 is fill| 000007e0 65 64 20 7c 0a 20 20 7c 20 30 b7 30 33 20 7c 20 |ed |. | 0.03 | | 000007f0 42 75 66 66 65 72 20 31 20 62 65 67 69 6e 73 20 |Buffer 1 begins | 00000800 70 6c 61 79 69 6e 67 2c 20 77 68 69 6c 73 74 20 |playing, whilst | 00000810 62 75 66 66 65 72 20 32 20 69 73 20 66 69 6c 6c |buffer 2 is fill| 00000820 65 64 20 7c 0a 20 20 7c 20 30 b7 30 34 20 7c 20 |ed |. | 0.04 | | 00000830 42 75 66 66 65 72 20 32 20 62 65 67 69 6e 73 20 |Buffer 2 begins | 00000840 70 6c 61 79 69 6e 67 2c 20 77 68 69 6c 73 74 20 |playing, whilst | 00000850 62 75 66 66 65 72 20 31 20 69 73 20 66 69 6c 6c |buffer 1 is fill| 00000860 65 64 20 7c 0a 20 20 2b 2d 2d 2d 2d 2d 2d 2b 2d |ed |. +------+-| 00000870 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |----------------| * 000008a0 2d 2d 2d 2b 0a 0a 20 20 54 68 69 73 20 67 69 76 |---+.. This giv| 000008b0 65 73 20 6d 75 63 68 20 6d 6f 72 65 20 65 66 66 |es much more eff| 000008c0 69 63 69 65 6e 74 20 77 61 79 20 6f 66 20 77 6f |icient way of wo| 000008d0 72 6b 69 6e 67 2e 0a |rking..| 000008d7