|  From: TLC (all posts) 
Date: 2000-09-07 
Subject: TED sound experiments 
 |  
Hi all! 
 
Some of you (emulator writers at the first place) will probably be interested of this thing. Past few days, I made some experiments with the Plus/4 and here are the results. 
 
I experimented with the DC offsets one gets when setting various values to the $ff11 (volume + control) register. I also wanted to know the reason of the effect some of you know: by setting very high values to the frequency registers, some more DC levels can be generated that one can use for improving digi playback quality (as most of my music converter routines do anyway - those days, I obtained the idea from Doky, but until now I had just suspects how and why it works). 
 
First, I wrote a routine for the Plus/4 that plays an about 2khz squarewave signal using a digi routine. It first sets osc1 frequency = 
$03fd, osc2 = $03fe. After a delay, the digi routine starts and alternates $ff11 between $00 and a given value. This value increases one by every 4000 samples. I digitized the resulting wave with my PC/ GUS PnP @ 16bit 48khz. 
 
Then, wrote a small routine in Pascal that picks out a piece from the big Wav file and measures its average AC power (with the assumption that it must be proportional to the TED's actual DC offsets). In the measuring process, each first 3/4 part of a same-level-wave section is skipped, as well as the last 1/10 part, avoiding transient problems. 
 
Here are the results (in descending order of the measured power). 
 
$ff11    Power      Power in % 
FB       15681      100 
FF       15681      100 
FA       15680      99 
FE       15680      99 
F9       15679      99 
FC       15677      99 
FD       15677      99 
F8       15676      99 
BB       15675      99 
B8       15674      99 
BC       15673      99 
BF       15673      99 
BA       15671      99 
BE       15670      99 
B9       15668      99 
BD       15668      99 
F7       13621      86 
B7       13614      86 
F6       11341      72 
B6       11333      72 
7B       11317      72 
7F       11316      72 
7C       11315      72 
7E       11315      72 
78       11313      72 
7A       11313      72 
7D       11313      72 
79       11312      72 
3E       11309      72 
3A       11307      72 
3B       11307      72 
3F       11307      72 
3D       11306      72 
38       11305      72 
39       11305      72 
3C       11303      72 
77       9912      63 
37       9905      63 
F5       9176      58 
B5       9170      58 
76       8309      52 
36       8306      52 
D8       7339      46 
DD       7339      46 
D9       7338      46 
DC       7338      46 
DE       7338      46 
9B       7337      46 
DA       7337      46 
DB       7337      46 
9A       7336      46 
9C       7336      46 
9E       7336      46 
9F       7336      46 
DF       7336      46 
99       7335      46 
98       7334      46 
9D       7334      46 
E9       7319      46 
ED       7319      46 
EC       7318      46 
EE       7318      46 
EF       7318      46 
E8       7317      46 
EA       7317      46 
EB       7316      46 
AB       7315      46 
AE       7315      46 
AF       7315      46 
A8       7314      46 
AC       7314      46 
68       7313      46 
6C       7313      46 
6F       7313      46 
AA       7313      46 
AD       7313      46 
6B       7312      46 
A9       7312      46 
6E       7311      46 
69       7310      46 
6A       7310      46 
6D       7310      46 
28       7309      46 
2F       7308      46 
2B       7308      46 
2A       7307      46 
2C       7307      46 
29       7307      46 
2D       7306      46 
2E       7306      46 
F4       7076      45 
B4       7075      45 
75       6757      43 
35       6753      43 
D7       6467      41 
97       6464      41 
E7       6444      41 
A7       6443      41 
67       6436      41 
27       6430      41 
D6       5451      34 
96       5450      34 
E6       5432      34 
A6       5429      34 
66       5422      34 
26       5418      34 
74       5229      33 
34       5226      33 
F3       5025      32 
B3       5023      32 
D5       4457      28 
95       4454      28 
E5       4438      28 
A5       4434      28 
65       4428      28 
25       4425      28 
73       3732      23 
33       3729      23 
5B       3598      22 
58       3598      22 
5F       3597      22 
5C       3597      22 
5D       3597      22 
5E       3597      22 
59       3597      22 
1A       3596      22 
18       3596      22 
1D       3596      22 
5A       3596      22 
1B       3595      22 
19       3595      22 
1F       3595      22 
1E       3595      22 
1C       3595      22 
D4       3465      22 
94       3462      22 
E4       3445      21 
A4       3443      21 
64       3435      21 
24       3433      21 
57       3179      20 
17       3176      20 
F2       3061      19 
B2       3058      19 
56       2689      17 
16       2687      17 
93       2485      15 
D3       2485      15 
A3       2465      15 
E3       2465      15 
63       2463      15 
23       2461      15 
72       2278      14 
32       2276      14 
55       2205      14 
15       2204      14 
54       1719      10 
14       1717      10 
D2       1528      9 
92       1528      9 
A2       1508      9 
E2       1508      9 
62       1506      9 
22       1505      9 
53       1237      7 
13       1236      7 
F1       1103      7 
B1       1102      7 
71       821      5 
31       820      5 
52       762      4 
12       761      4 
D1       562      3 
91       562      3 
61       542      3 
E1       542      3 
A1       542      3 
21       541      3 
51       281      1 
11       280      1 
4A       31      0 
45       31      0 
09       31      0 
08       31      0 
0A       31      0 
0B       31      0 
C1       31      0 
C2       31      0 
C3       31      0 
C4       31      0 
C5       31      0 
C6       31      0 
C7       31      0 
C8       31      0 
C9       31      0 
CD       31      0 
CE       31      0 
CF       31      0 
D0       31      0 
46       31      0 
4C       31      0 
82       31      0 
86       31      0 
90       31      0 
30       31      0 
81       31      0 
4B       31      0 
E0       31      0 
B0       31      0 
49       31      0 
60       31      0 
40       31      0 
41       31      0 
20       31      0 
A0       31      0 
48       31      0 
80       31      0 
10       31      0 
07       31      0 
04       31      0 
05       31      0 
06       31      0 
0F       30      0 
8C       30      0 
0D       30      0 
44       30      0 
0E       30      0 
C0       30      0 
88       30      0 
70       30      0 
47       30      0 
0C       30      0 
83       30      0 
89       30      0 
8F       30      0 
CA       30      0 
8D       30      0 
84       30      0 
4E       30      0 
85       30      0 
F0       30      0 
8A       30      0 
8E       30      0 
87       30      0 
50       30      0 
4F       30      0 
42       30      0 
CB       30      0 
CC       30      0 
4D       30      0 
02       30      0 
00       30      0 
8B       30      0 
43       30      0 
03       30      0 
01       30      0 
 
Some thoughts that I can derive, after checking this (and after seeing the wave in Sound Forge) 
 
- The output is asymmetric (in DC). I'd say it's positive. Well, not a surprise after all... 
 
- The TED's sound output is quite noisy. The noise seems to be more noticeable if higher levels are generated (this is really strange: I only noticed it if the level was changing dynamically (for example, 
alternating between $00 and $b8); a constant high level ($b8), when measured, did not show more noise than a constant 0). The 50Hz component is clearly noticeable - would suspect that it comes from the video part of the TED, since there are plenty of other possibly video-originate noise in the signal too. 
 
- Setting 0 volume ($x0) or turning no oscillator on ($0x) all generates the same silence (no noticeable difference). 
 
- Volume values above 8 give the same DC offset as volume 8 (the power values of the higher $ff11 settings tend to have higher power in the list, but there is very small difference (not even consequent) and I'd rather consider it a side-effect of my measuring method (AC analysis, on a wave that is clearly asymmetric and one should wait 'enough' until all transients go down before measuring) or the noise that I didn't want to filter out. 
 
- This is probably more interesting: writing $03fe to the frequency register locks up the oscillator completely. The oscillator then gives the same DC offsets as you get in constant DC level mode (bit7 of $ff11 = 
1), e.g. if frq(osc2) = $03fe, writing $24 or $94 or $a4 into $ff11 all give the same DC offset. 
 
- Setting $03fe as frequency in osc2 also locks up the noise generator. 
Depending on something that I can't derive, setting $4x values to $ff11 
either gives the same constant DC offset as above ($9x or $Ax) or constant zero. Should depend on the minute the oscillator value is written, as I suspect. 
 
- Frequency of $03fd and the like work the following way: try it, 
$03fb - $03fd give the same DC offset if the oscillator is on. This is because these don't stop the oscillator, they're just very high frequencies that one doesn't hear. On a PAL machine, $03fb lets the oscillator generate an about 22khz signal, that anyway my GUS PnP just filtered out completely. $03fd is about 55khz - I don't know if it can even reach the audio output. Since this is a 50-50% pulse wave, its average power should be half of the same volume constant DC level. (As one could have suspected that without this explanation). 
 
The levels, if going through the volume settings as 0,1,2...8 seem to be slightly non-linear. The first step (0-1) is about half the second step 
(1-2), whichever oscillators are active. Check the power difference through the steps of $b0...$b8. The steps slightly rise, then the last step is again smaller. ...I don't know the reason. 
 
Then, what to use all this for? 
 
If I were an emulator programmer, I could improve sound emulation. 
 
- Checking one of the highest series of osc/volume setting ($b0...$b8, 
for example) could give a fair approximation of the TED volume steps, 
related to the TED volume setting. 
 
A proper emulation of the TED behaviour, including digi tricks could be then the following: 
 
   - Each oscillators could be emulated as simple (incrementing counter type) square generators. The output level is either 0 or 100%. If the oscillator is set off, assume 0. If on, then... The correct formula for the output is 'f=Phi(single clock)/8/(1024-((frqvalue+1)&1023))'. If 
'frqvalue' is between $03fb and $03fd, assume constant 50% output. If 
'frqvalue'=$03fe, or 'constant level mode' is selected (bit 8 of $ff11 
is set), assume 100% output. 
 
   - (Something should be done in order to emulate noise correctly; if someone wants, I sample the lowest frq TED noise wave with my PC - I think it could be easy to play this back at the speed derived from the above oscillator formula.) 
 
   - Multiple each current output level by the current volume (in %). 
This current volume is given by the volume step table, indexed with the TED volume. 
 
   - Add the two resulting values together and store to the next position of the output wave (to the sound card). See next one... 
 
(Expect some aliasing problems at least at the higher frequencies: 
generating square waveforms of some 10-20khz at the sampling rate of 
44khz or even 48khz implies lots of undersampling problems. The 
'theoretical' squarewave one tries to play contains plenty of strong overtones that appear as aliasing (if one knows how a SID music converter routine on the Plus/4 sounds, he for sure knows the typical sound that I mean). SID emulators on PC used to solve this by oversampling in software, applying a low-pass filter algorithm to the high-sampled stream and playing this through the sound output (this definitely improves sound quality). But this is a different problem). 
 
If I were experimenting with digi playback on a real machine... 
 
Well I'd probably try to get a good sounding digi $ff11 table, by optimizing a series that give the closest output levels to the linear characteristic (split the '100%' range into the needed number of pieces, 
and select the nearest DC offset for each needed value - better do that using the absolute results, not percents since it's more accurate, but the idea is the same). (I sure did it ;-) Well not much improvements to the previous digi tables - if anyone wants, I can give you my results). 
 
BTW, Richard Atkinson also promised to make some measurements - expect that sometime on the list. I'd say these should be more accurate. 
 
With regards, 
 
L. 
 
Ps. Some of you could also be curious to know how the TED actually generates the output. I thought I better include Richard's original post here, that he sent to the cbm-hackers mailing list about one month ago. 
...As a comment: it's very interesting how Commodore avoided completely any analog design in this sound generator (unlike the SID design is). 
The TED is fully digital. ...Well, it makes sense, after all, not putting some analog circuits to the closest neigborhood of a video generator circuit ;-) 
 
> 
The waveform coming out of the SND pin is digital, pulse-width modulated. I think the width is expressed in master clock cycles (14.3 or 17.7 MHz) and the period of the cycle depends on whether both channels are on or just one. The volume bits set the length of the pulse and if only one channel is on the period is doubled so that the DC voltage level is halved. I have yet to make a quantitative table of the mark-space ratios with different register settings but that's definitely the next thing to do. 
> 
 |  
  |   |   
 Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon |