Changes
/* Writing */
'''Translation note :'''Cassette == Recording a sound ==Tape.
[[Image:wave1.gif]]
[[Image:wave4.gif]]
''Fig 4. An amplitude/time graph showing the sampled waveform. This waveform was generated at a high sample rate, and therefore the resulting waveform has a shape which is similar to the original. This waveform is the type you can see in a audio recording program like Goldwave. '''Note''', however, that this distinctively square signal is not what would be output by any barely decent sound-card! Audio hardware has built-in filters to smooth waveforms as they are converted from digital to analogue.''
[[Image:wave5.gif]]
[[Image:wave7.gif]]
''Fig 7. An amplitude/time graph showing the sampled waveform. As explained in the note for Figure 4, this is only a visual representation of the digitally stored audio, '''not''' of the signal that would be output by any competent audio card. However, it does illustrate how low sampling rates reduce the bandwidth of frequencies: This waveform was generated at a low sample rate, and therefore the resulting waveform is much more coarse compared to Fig 4. Notice that although the general shape is similar to the original waveform, and much of the smoothness is is lost between the time of each measurement. The loss of smoothness also means loss of information since this waveform is not the same as the original. If you compare this graph against Fig 4 then you will see that : the lower the sample sampling rate, the more information is lost. The higher ; in other words, the sample ratemaximal frequency that the signal can represent is lower. Similarly, lower bit-depths mean that the less information signal is lostless accurate, and in extreme cases can generate audible noise. Therefore, to record a sound, it is best to use a relatively high sample sampling rateand bit-depth; CD audio's 44.1 kHz and 16-bit should be more than adequate for most uses. Due to the way the CPC hardware process the sound signal, 16-bit has zero advantage over 8-bit for CPC cassettes. To sum it up, 44.1kHz and 8-bit is recommended for storage of CPC cassettes.''
Notes:
1. The "Nyquist theory" states that in order to accuratly record a sound of a known frequency, you must use a recording frequency which is more than twice that frequency(note "more than", not equal to). i.e. Example: to record a sound of 3000Hz3000 Hz, you must record using 6000Hz>6000 Hz. If you use a lower frequency sampling rate (e.g. 5000Hz5000 Hz), then frequencies less than or equal to half of the sound is not recorded accuratlysampling rate cannot be properly represented and will be altered into lower-sounding frequencies. Most Amstrad loaders are between 300 to 2500Hz2500 Hz, therefore you should use a recording sample rate of at least 5000Hz>5000 Hz. It is recommended to use one of the "common" sample rates. e.g. 22050Hz 22050 Hz (22Khz22.05 Khz) or 44100Hz 44100 Hz (44.1Khz1 Khz).
2. There are two different representations to store the amplitude of the sample in a PCM audio file: unsigned or signed.
* A 8-bit unsigned sample has values between 0 and 255. In this range, 0 represents a low amplitudes, 255 a high amplitude, and the amplitudes increase linearly from 0 to 255.
* A 8-bit signed sample has values between -128 and 127. In this range, -128 represents a low amplitude, and 127 high amplitude, and the amplitudes increase linearly from -128 to 127.
Both methods can represent the same data, just in different ways (techies will be able to compare this to their knowledge of Z80 assembly), so there is no advantage to using either. The original reason for the two methods is due to the original method to playback the sound. Modern sound cards can play audio stored in both methods ways.On a side note, the WAV sound container only allows 8-bit unsigned samples, so there is no ambiguity as to how to interpret 8-bit samples.Note that both (albeit more obvious in the latter) share a feature typical of data storagebinary-encoded numbers: there is no exact 'centre' value, because the total number of possible values is even. In the context of audio, this means that, if the signal spanned the entire range, its centre (average) would be slightly off-zero (in this case, below), which is known as a DC offset. However, even if this did occur, it would be negligible and certainly not audible by humans!The fact there is no 'centre' value is actually a good thing, as the CPC has to convert the sound signal that comes in to a single bit, determining whether the signal is low or high.
== Duplication of cassettes ==
A loader on the computer must therefore be able to identify the actual sound of the data from other sounds that are on the cassette. If it can't do this, then there will be loading errors.
If you are transfering a cassette using samp2cdtCSW2CDT, then you are advised to use an original (i.e. a cassette created directly from a master cassette), or a first generation copy (i.e. a cassette copied from an original).
== Loader ==
The Amstrad's cassette electronics converts the amplitude of the sound (a analogue signal) into a "0" or "1" measurement (a digital signal). This measurement can then be read from bit 7 of port B of the PPI 8255 IC.
[Picture showing the conversion process[Image:conv.gif]]
The resulting measurements can be read using the following Z80 instructions:
1. The CPC464 and CPC464+ have a cassette player built in. To connect a cassette player to the CPC664, CPC6128 or KC Compact then you must use a lead.
2. It is not known exactly how the amplitude of the sound from the cassette corresponds to the final "0" or "1" measurement.
=== Writing ===
If the state of bit 5 is changed at a fixed frequency, then the graph of the state of bit 5 over time will be a square wave. However, the resulting audio written on the cassette will not be a perfect square wave because nature will attempt to convert the waveform into a sine wave.
The exact definition of the loading systems's audio waveform is defined by the loader program.
== Example of a typical loading system ==
The data on cassette actually consists of changing 0 and 1 levels. (a "level" is a magnitude of a value). The loader measures the time between each "level transition" where a "level transition" is the change from a "0" to a "1" level or the change from a "1" to a "0" level. The level can be timed using the following Z80 instructions: <pre>;; - keep testing the state of bit 7 of PPI 8255 port B ;; - update the counter to record the number of tests done ;; - when bit 7 of PPI 8255 port B changes state, stop testing. ;; counter will hold the total number of tests made. ;; ;; B = &F5 (I/O address of PPI 8255 input port B) ;; C = previous data read from PPI port B ld d,0 ;; initialise count to 0 .loop inc d ;; increment count in a,(c) ;; read input to PPI 8255 port B xor c ;; exclusive-or with previous data read from PPI 8255 port B and %10000000 ;; isolate bit 7 ;; if result is 0, then the state of bit 7 that has ;; been read is the same as the previous state. i.e. bit 7 has not changed state. ;; if result is not 0, then the state of bit 7 has changed. ;; e.g. if bit 7 was previously 1, it is now 0. if bit 7 was previously 0, it is now 1. jr z,loop ;; when execution reaches here we know that bit 7 has changed state and D ;; contains the number of tests.</pre>
== Loader operation==
The loader generally operates in this way:
1. time Time a wave. Is the duration of the wave within the minimum and maximum duration required for the pilot. If yes, go to 2, else go to 1.
2. We might have seen a wave from the pilot signal. time a wave. Is the duration of this wave within the minimum and maximum duration required for the pilot. If yes, increment number of waves seen, go to 2, else go to 1.
In this case, the only way to test that the data is correct is to make multiple transfers of the program and test each thoroughly (e.g. if the program is a game, you would play the game to the end), checking for graphic corruption and bugs. If all of the transfers operate the same, then you can assume that the data is correct.
== Various Audio file formats == There are numerous Audio file formats, each of which can store audio, but each has it's its own structures and representation for the data.
The "format" of a file describes the internal structure, order and encoding of the data within the file.
[[Category:Hardware]][[Category:DATA Storage|* Windows Wave file (a file which has the ".wav" file extension) is the common file format used for audio sounds on computers running "Windows".* A Voice Wave file (a file which has the ".voc" file extension) was created by Creative for the original Soundblaster ISA ]][[Category:Music and sound card. This file format is used by the original voc2tzx utility which samp2cdt was developed from.* A Audio Interchange file (a file which has the ".aiff" or ".aif" file extension) is the common file format used for audio sounds on the Mac computer.* A file which has the ".iff" file extension is the common file format used for audio sounds by the Amiga computer.]][[Category:CPC Internal Components]]