Hmm... When I think again, that really does not make any notable change in other than possibly few first values (like 0-10) for the rest (10-255) it is quite a same if the error is like 10 or 10.01
How about this kind of brute force way to find optimal solution:
- Find all different PSG register combinations.
- Calculate analog value for each combination and place the results to a "line". If two absolutely same values are calculated the combination that contains bigger or smaller number is stored for later use.
- Take last number in a line (generated from 15,15,15) now let's call that number X
LOOP:
- divide X to 256 steps in a line
- find closest value for each step.
- substract the step from closest value and add the result to error counter
- after all steps are gone trough store the X and error counter to table
- take previous from X value in a line and repeat LOOP until about 3/4 of the numbers on the line are gone trough.
- sort the list by error counter and you have the optimal solution!
- sort the register combinations so that biggest/smallest register value is first.
- make the result look nice and put it online
I think, it is better to do this on PC as this requires quite some CPU power and memory, but it should find the optimal solution as far as we agree, that 0,0,0 is best combination to start the table. (This can be wrong assumption.) You may also want to add value, that is smaller than one step to each step to decrease error counter value, but as I already said in beginning of this post, the change is propably VERY minimal.
@@NYYRIKKI
Here is (untested) example routine, that plays sample using that table: ...
Tested. And works but It sounds low pitch.( So delay is no needed.)
http://webs.ono.com/WYZ/4BIT.bin
http://webs.ono.com/WYZ/8BIT.bin
http://webs.ono.com/WYZ/cez8bit.wav
PS: Maybe background noise too.
% Compute all the output values for a channel
n=0:15;
Q=sqrt(2).^n;
Q=Q/max(Q);
Q(1)=0;
% Compute alla the output values on 3 channels
n=1;
II = zeros(4096,4);
for i1=0:15
for i2=0:15
for i3=0:15
QQ(n) = Q(i1+1)+Q(i2+1)+Q(i3+1);
II(n,: ) = [QQ(n),i1,i2,i3];
n=n+1;
end
end
end
% cancel duplicates
[h,i] = sort([ QQ , -1, 1e6]);
w = h(find(diff(h)));
w = [ w(2:end)];
% store in T non duplicate outputs with the corresponding PSG volumes
T = [];
for i=1:length(w)
j=find(II(:,1)==w(i));
T = [T; II(j(1),: )];
end
% T has 849 different values !! This is the full dynamic of our PSG
% Now we need to find which values best approx a 8bit PCM input
% digital sample in input
xxx = 0:255;
% analog 8bit PCM sample : NOTE the scale factor ! this is for maximize the SNR
x=xxx/255*1.45;
% find the best quantization level for each value of x
y = zeros(size(x));
q = y;
for n=1:length(x)
[m,i]= min(abs(T(:,1)-x(n)));
y(n) = T(i,1);
q(n) = i; % Store the index corresponding to the output level
end
% This matrix has on the first column the 8bit PCM input, on the second column the PSG output, on the last 3 columns the PSG voulmes
B8b = [xxx',T(q,: )];
save B8b.txt B8b -ascii
% quantization error
e = x-y;
S = norm(x)/sqrt(length(x));
E = norm(e)/sqrt(length(e));
% display the SNR
20*log10(S/E)
Ok, that was fast
@WYZ
do you want to try my table ?
As far as I can understand it
should give an SNR almost
identical to the one of a 8bit
PCM player.
@NYYRIKKI
Problems with matlab?
It could of course be optimized a lot by changing the table to have a byte for each channel - you could then use OUTI, and remove the (slow) RLD stuff.
Also, you can use a ‘fast loop’ to improve the looping speed.
~Grauw
My table:
db 0,0,0 ; 0 0,0000
db 0,0,1 ; 1 0,0078
db 0,0,2 ; 2 0,0110
db 0,0,3 ; 3 0,0156
db 0,0,4 ; 4 0,0221
db 0,1,4 ; 5 0,0299
db 1,2,3 ; 6 0,0345
db 0,1,5 ; 7 0,0391
db 1,3,4 ; 8 0,0455
db 1,4,4 ; 9 0,0520
db 2,3,5 ; 10 0,0579
db 0,0,7 ; 11 0,0625
db 1,3,6 ; 12 0,0676
db 1,4,6 ; 13 0,0741
db 1,7,1 ; 14 0,0781
db 1,3,7 ; 15 0,0859
db 3,5,6 ; 16 0,0911
db 0,1,8 ; 17 0,0962
db 1,5,7 ; 18 0,1016
db 1,2,8 ; 19 0,1072
db 1,6,7 ; 20 0,1145
db 3,3,8 ; 21 0,1196
db 0,0,9 ; 22 0,1250
db 2,5,8 ; 23 0,1307
db 0,2,9 ; 24 0,1360
db 4,5,8 ; 25 0,1417
db 3,6,8 ; 26 0,1482
db 4,6,8 ; 27 0,1547
db 1,7,8 ; 28 0,1587
db 1,5,9 ; 29 0,1641
db 3,5,9 ; 30 0,1719
db 0,8,8 ; 31 0,1768
db 5,7,8 ; 32 0,1821
db 0,7,9 ; 33 0,1875
db 0,3,10 ; 34 0,1924
db 0,4,10 ; 35 0,1989
db 2,3,10 ; 36 0,2035
db 2,4,10 ; 37 0,2099
db 1,5,10 ; 38 0,2158
db 1,8,9 ; 39 0,2212
db 1,6,10 ; 40 0,2288
db 2,6,10 ; 41 0,2320
db 5,5,10 ; 42 0,2393
db 8,9,5 ; 43 0,2446
db 2,10,7 ; 44 0,2503
db 3,7,10 ; 45 0,2549
db 4,7,10 ; 46 0,2614
db 1,11,2 ; 47 0,2689
db 1,8,10 ; 48 0,2730
db 1,4,11 ; 49 0,2799
db 6,7,10 ; 50 0,2835
db 1,5,11 ; 51 0,2891
db 5,8,10 ; 52 0,2964
db 8,9,8 ; 53 0,3018
db 2,6,11 ; 54 0,3052
db 2,9,10 ; 55 0,3128
db 3,9,10 ; 56 0,3174
db 4,9,10 ; 57 0,3239
db 3,7,11 ; 58 0,3281
db 4,7,11 ; 59 0,3346
db 5,7,11 ; 60 0,3438
db 1,8,11 ; 61 0,3462
db 8,10,8 ; 62 0,3536
db 6,7,11 ; 63 0,3567
db 7,9,10 ; 64 0,3643
db 5,11,8 ; 65 0,3696
db 0,9,11 ; 66 0,3750
db 2,3,12 ; 67 0,3802
db 2,12,4 ; 68 0,3867
db 1,5,12 ; 69 0,3926
db 0,6,12 ; 70 0,3977
db 1,6,12 ; 71 0,4056
db 2,6,12 ; 72 0,4088
db 7,10,10 ; 73 0,4161
db 4,6,12 ; 74 0,4198
db 9,9,10 ; 75 0,4268
db 3,12,7 ; 76 0,4317
db 2,11,10 ; 77 0,4378
db 3,10,11 ; 78 0,4424
db 4,10,11 ; 79 0,4489
db 2,8,12 ; 80 0,4530
db 7,12,6 ; 81 0,4602
db 4,8,12 ; 82 0,4640
db 6,10,11 ; 83 0,4710
db 9,10,10 ; 84 0,4786
db 6,12,8 ; 85 0,4861
db 7,10,11 ; 86 0,4893
db 3,9,12 ; 87 0,4942
db 4,9,12 ; 88 0,5007
db 7,8,12 ; 89 0,5044
db 0,2,13 ; 90 0,5110
db 1,13,2 ; 91 0,5189
db 1,3,13 ; 92 0,5234
db 1,13,4 ; 93 0,5299
db 2,4,13 ; 94 0,5331
db 7,9,12 ; 95 0,5411
db 3,10,12 ; 96 0,5460
db 9,10,11 ; 97 0,5518
db 2,13,6 ; 98 0,5552
db 0,7,13 ; 99 0,5625
db 1,7,13 ; 100 0,5703
db 6,10,12 ; 101 0,5745
db 3,7,13 ; 102 0,5781
db 4,7,13 ; 103 0,5846
db 7,10,12 ; 104 0,5928
db 8,13,1 ; 105 0,5962
db 10,11,10 ; 106 0,6036
db 6,7,13 ; 107 0,6067
db 2,11,12 ; 108 0,6146
db 8,13,5 ; 109 0,6196
db 4,11,12 ; 110 0,6257
db 6,8,13 ; 111 0,6326
db 2,9,13 ; 112 0,6360
db 3,9,13 ; 113 0,6406
db 11,12,6 ; 114 0,6477
db 9,10,12 ; 115 0,6553
db 5,9,13 ; 116 0,6563
db 7,11,12 ; 117 0,6661
db 6,9,13 ; 118 0,6692
db 0,10,13 ; 119 0,6768
db 1,10,13 ; 120 0,6846
db 2,13,10 ; 121 0,6878
db 3,10,13 ; 122 0,6924
db 4,10,13 ; 123 0,6989
db 10,12,10 ; 124 0,7071
db 8,9,13 ; 125 0,7134
db 0,1,14 ; 126 0,7149
db 0,3,14 ; 127 0,7227
db 9,11,12 ; 128 0,7286
db 2,3,14 ; 129 0,7338
db 7,10,13 ; 130 0,7393
db 3,4,14 ; 131 0,7448
db 0,11,13 ; 132 0,7500
db 1,11,13 ; 133 0,7578
db 2,6,14 ; 134 0,7623
db 3,14,6 ; 135 0,7669
db 4,6,14 ; 136 0,7734
db 10,11,12 ; 137 0,7803
db 3,7,14 ; 138 0,7852
db 4,7,14 ; 139 0,7917
db 6,14,6 ; 140 0,7955
db 9,10,13 ; 141 0,8018
db 2,8,14 ; 142 0,8065
db 7,11,13 ; 143 0,8125
db 4,8,14 ; 144 0,8176
db 5,8,14 ; 145 0,8267
db 0,9,14 ; 146 0,8321
db 8,11,13 ; 147 0,8384
db 2,9,14 ; 148 0,8432
db 3,9,14 ; 149 0,8477
db 10,10,13 ; 150 0,8536
db 7,8,14 ; 151 0,8580
db 2,12,13 ; 152 0,8646
db 3,12,13 ; 153 0,8692
db 4,12,13 ; 154 0,8757
db 0,10,14 ; 155 0,8839
db 5,12,13 ; 156 0,8848
db 1,10,14 ; 157 0,8917
db 12,13,6 ; 158 0,8977
db 4,14,10 ; 159 0,9060
db 4,10,14 ; 160 0,9060
db 5,10,14 ; 161 0,9151
db 9,14,8 ; 162 0,9205
db 10,11,13 ; 163 0,9268
db 6,14,10 ; 164 0,9281
db 8,12,13 ; 165 0,9419
db 8,13,12 ; 166 0,9419
db 7,10,14 ; 167 0,9464
db 9,9,14 ; 168 0,9571
db 0,11,14 ; 169 0,9571
db 2,11,14 ; 170 0,9682
db 8,10,14 ; 171 0,9723
db 9,12,13 ; 172 0,9786
db 4,11,14 ; 173 0,9792
db 5,11,14 ; 174 0,9884
db 0,13,13 ; 175 1,0000
db 6,11,14 ; 176 1,0013
db 1,13,13 ; 177 1,0078
db 0,2,15 ; 178 1,0110
db 1,2,15 ; 179 1,0189
db 1,3,15 ; 180 1,0234
db 1,4,15 ; 181 1,0299
db 2,4,15 ; 182 1,0331
db 1,5,15 ; 183 1,0391
db 3,5,15 ; 184 1,0469
db 1,6,15 ; 185 1,0520
db 3,6,15 ; 186 1,0598
db 0,7,15 ; 187 1,0625
db 1,12,14 ; 188 1,0685
db 5,6,15 ; 189 1,0754
db 9,11,14 ; 190 1,0821
db 4,7,15 ; 191 1,0846
db 5,12,14 ; 192 1,0919
db 1,15,8 ; 193 1,0962
db 11,13,12 ; 194 1,1036
db 4,8,15 ; 195 1,1105
db 4,8,15 ; 196 1,1105
db 5,15,8 ; 197 1,1196
db 0,9,15 ; 198 1,1250
db 6,8,15 ; 199 1,1326
db 2,15,9 ; 200 1,1360
db 3,9,15 ; 201 1,1406
db 8,12,14 ; 202 1,1490
db 5,9,15 ; 203 1,1563
db 5,9,15 ; 204 1,1563
db 6,9,15 ; 205 1,1692
db 6,9,15 ; 206 1,1692
db 8,15,8 ; 207 1,1768
db 1,10,15 ; 208 1,1846
db 2,10,15 ; 209 1,1878
db 3,10,15 ; 210 1,1924
db 4,10,15 ; 211 1,1989
db 0,13,14 ; 212 1,2071
db 8,9,15 ; 213 1,2134
db 2,14,13 ; 214 1,2182
db 3,13,14 ; 215 1,2227
db 4,13,14 ; 216 1,2292
db 10,12,14 ; 217 1,2374
db 7,10,15 ; 218 1,2393
db 11,13,13 ; 219 1,2500
db 6,13,14 ; 220 1,2513
db 1,11,15 ; 221 1,2578
db 2,11,15 ; 222 1,2610
db 7,13,14 ; 223 1,2696
db 4,11,15 ; 224 1,2721
db 5,11,15 ; 225 1,2813
db 5,11,15 ; 226 1,2813
db 6,11,15 ; 227 1,2942
db 13,14,8 ; 228 1,2955
db 9,10,15 ; 229 1,3018
db 11,12,14 ; 230 1,3107
db 7,11,15 ; 231 1,3125
db 7,11,15 ; 232 1,3125
db 9,13,14 ; 233 1,3321
db 9,13,14 ; 234 1,3321
db 8,11,15 ; 235 1,3384
db 8,15,11 ; 236 1,3384
db 10,10,15 ; 237 1,3536
db 10,10,15 ; 238 1,3536
db 1,12,15 ; 239 1,3614
db 2,15,12 ; 240 1,3646
db 3,12,15 ; 241 1,3692
db 4,12,15 ; 242 1,3757
db 10,13,14 ; 243 1,3839
db 5,12,15 ; 244 1,3848
db 6,12,15 ; 245 1,3977
db 6,12,15 ; 246 1,3977
db 6,12,15 ; 247 1,3977
db 0,14,14 ; 248 1,4142
db 7,12,15 ; 249 1,4161
db 1,14,14 ; 250 1,4220
db 10,11,15 ; 251 1,4268
db 3,14,14 ; 252 1,4298
db 4,14,14 ; 253 1,4363
db 5,14,14 ; 254 1,4455
db 5,14,14 ; 255 1,4455
@ARTRAG
Yeah, matlab is not my tool. Also very ugly output, congratulations.
@Grauw
Current OUT solution is faster than OUTI but I still vote for byte/channel. I just made the routine for existing table.
Very much better