Archive for July, 2022

A quick glance as Titanic: Adventure Out Of Time resources

Saturday, July 30th, 2022

Recently somebody asked me how to play MOV files from the game. My answer was that I don’t know and we need to wait until somebody reverse engineers of that engine. Meanwhile I took a second look to see if I missed something apparent (spoiler: no).
(more…)

WWIII as the test of political systems

Sunday, July 24th, 2022

As I wrote previously, I have all reasons to consider what happens now to be World War III and today I want to rant on the political systems of participating countries and how it affects them. For the better understanding of it you should know two terms (both coming from Germany for some reason though it’s disputed for the latter term): finlandisation and Demokratur (literally “democratorship” from democracy+dictatorship, also known as “hybrid” democracy or controlled democracy, i.e. where the system is formally democratic but in reality it’s just a show; for example in GDR any party could exist as long as it was in the alliance with the ruling party so it did not matter for whom you were voting in the end, in North Korea there are two or three parties and all of their members are also the members of the ruling party; all the cases where it does not matter how you voted, only how the votes were counted, and where you have clauses like “a person running for a president in Belarus must have at least five years of experience as a president of Belarus” all fall into this category).

Anyway, let’s look how it all went for the various participants.

The first group is post-Soviet countries. When Soviet Union was dissolved, the republics it was formed from split into three categories: Baltic states that did not want to preserve the communistic past and moved on to the democratic future (which was a right step), countries that were essentially privatised by their rulers (just look at the personalities of first “presidents” of Georgia, Kazakhstan, russia, Turkmenistan and Uzbekistan who were heads of those states at Soviet time and remained in power for decades after that, often passing the post to the personally appointed heir) and countries that were stuck in the middle by replacing the initial ruler after first couple of years but preserving a lot of the Soviet legacy and later either stagnating or falling outright into dictatorship (for example, lukashenko might be the only president of Belarus but the post has been established in 1994, exactly when the first Ukrainian president had resigned).

The second group are various European countries (plus USA) that are mostly democratic except for a couple of democratorship countries (like Hungary). Mainly I can describe them as bureaucratic democracies, with the idea is that the heads of the state are like hired managers that are supposed to serve people’s interests. And, as in large companies, they mostly serve their own interests while making people disinterested in changing things. One of the consequences is that those “managers” stay in power longer than normally elected presidents should (local example: Angela Merkel served as the chancellor for 16 years while it feels for me that ten years should be a limit). Another consequence is that they stifle their opposition (related local example: there was no prominent politician left in the Merkel’s party to be her successor) and they can do what serves them better (we’ll talk about it later when it’s time to say something about gas affecting European politics and finlandisation happening because of it). A related thing: because of the rigidity and bureaucratisation of the political system (most things you can do need to be approved by various committees and other political organs), those heads of the states usually can’t make any drastic domestic policy changes so they resort to foreign politics (just ask any Boris Johnson).

The third group is various non-democratic countries like mainland China (the real China on Taiwan demonstrates how it can be done differently), Iran (people hardly remember it has a president), Syria (is there any reason to comment?) and Türkiye (I call it this way to distinguish newly forming sultanate from the somewhat democratic Turkey and the old Ottoman Empire).

So, how the war affected those political systems?

Bureaucratic democracies showed their slow reaction and ineptitude. Plus it showed how far the process of finlandisation by cheap natural gas went. Of course there’s Hungary that rather honestly says that it won’t survive without cheap fuel from russia (yet it sold Serbia some gas recently) and repeats what kremlin wants it to say (the stuff about sanctions not working, that the war should be ended with talks because 1938 Munich agreement worked so well and so on). Germany is much more disgusting: on the surface it pretends to care, in reality it’s been corrupted (Gazprom Schröder is just the most prominent example) since after 2014 when russia tried to blackmail Europe with gas for the first time and the EU started to develop rules for creating common grid and energy independency, Germany kept sabotaging those efforts and even sold some of its strategic infrastructure to russian gas monopoly (including gas storage facilities); it promised but hasn’t given Ukraine any heavy munition (beside some PzH 2000 which was a big surprise) and blocked other countries from giving Ukraine their Germany-made tanks; recently it specifically lifted some of the sanctions to return compressor turbine to russia after its blackmailing. In my opinion all those current and former higher-ups should be put to prison for corruption and betraying national interests. There’s somewhat similar story with the Switzerland that tries to remain so neutral that I joke it’ll revoke licenses to all its military equipment the instant a country that bought it goes to war. At least some other countries are not that bad and are not willing to close eyes to anything in exchange for cheap gas and oil.

Demokratures are doing more or less fine (China, Hungary, Türkiye and even Belarus) with the one notable exception (you can easily guess which one).

Ukraine is actually doing better than before 2013 (in political sense, whatever happens on its territory is horrible) since the war forged and tempered the national identity (many nations really started to exist only after a freedom war). It also showed what the real enemy is and that Ukraine should purge remains of communist and russian culture (after all, if one of the first things the invaders do is reinstating Lenin monuments that means it’s that’s how they mark their territory and all such markers should be removed from the territory not belonging to them—along with their dead bodies if required). Actually starting from about 2018 a lot of people were tired of frozen conflict and soon newly elected president Zelensky actually tried to downside army somewhat. And then russia accused Ukraine of trying to take occupied Ukrainian territories back and went to occupy even more of Ukrainian territories (and to prove that all ties with it should be severed). But unlike russia, Ukraine is built on traditions of people respecting freedom (maybe even too much, hence the saying that two Ukrainians would make three hetmans) and despite the lack of communications between the Ukrainian troops and their commanders in the first days of war they were able to act on their own. Such country deserves a future.

russia, on the other hand, has never been a democratic land. Kievan Rus’ had democracy, various Hanseatic league members (like Novgorod or Pskov republics) had democracy, even Golden Horde had some democracy. Suzdal principality (where Moscow was built and which later expanded into what we see now) preferred to follow East Roman Empire and to get rid of all possible freedoms. It conquered the aforementioned republics, it eliminated the right of serfs to change their landlord (they could do it once a year before late XVIth century but not in the following three hundred years). Later it conquered large territories and almost always changed the life there for the worse (after conquering Ukraine and part of Belarus it introduced serfdom there and also pale of settlement; whatever happened to Uzbekistan after it got conquered is a sad tale as well). There’s one characteristic feature there—russia preferred to turn its own territory into colonies as it was afraid to manage overseas colonies (that’s why Alaska and Fort Ross were sold to the USA, it’s probably the only case when russia ceded some of its territory voluntarily).

When this rather inhuman regime was replaced with another one in 1917, not many things have changed. There was just one party in the country and you had to belong to it to make any career, there was propiska system where you essentially had to obtain a permit before you could move somewhere and at collective farms (before 1950s IIRC) you had to obtain a permit from the head of that collective farm in order to get an internal passport so you could get propiska and move to a town. As for the politics, there was “the bloc of communists and non-partisans” which created a term “Soviet choice” where you can freely choose from one thing. And all unpopular measures (like rising prices) were provided under the pretext that the working class had asked for it themselves.

So what followed this nice country? Something not that different: the first president of RSFSR co-signed a treaty that dissolved Soviet Union, became the first president of russia and remained at that post until 2000 when he essentially transferred it to the appointed heir. One could argue it was a democratic time when there were more or less free elections but during that time the democracy was destroyed too, mostly under the pretext that if you give people a right to choose then communists will return to power and nobody wants that. So they moved from the usual trickery with rigged voting to getting oligarchs’ support by giving them away state property (essentially the Central Bank decided to store state money in various private banks belonging to certain people who used that money to buy state property or to get it as a collateral for credits they gave to the state with the state money they got) and essentially taming the opposition making it official (unlike USA where two major parties sometimes change positions, in russia the official opposition always remains the official opposition but always votes in favour of the legislation that the dictator or his people tells them to vote for; it got especially obvious in the last decade let alone this year). So when Yeltsin decided to retire, he tried to ensure that he and his Family (daughter, son-in-law and couple of oligarchs around them) remain unpunished, so he appointed a certain guy and oligarchs (who owned all media) ensured that he was elected. Thus an even sadder part of their history began.

The reign of the current dictator started with the Second Chechen War which was won by wiping all what they could. One of the remarkable things at that time was FSB fabricating terrorist acts itself (either to shift blame to Chechen terrorists or to report some cases they managed to “prevent”). One such case got nicknamed “Ryazan’ sugar” after FSB agents leaving a sack of “sugar” in a basement of one living building in Ryazan’. Nobody got punished for that and it set the tone for all the following events (both committing war crimes and blaming them on the others and not punishing underlings for neither failures nor crimes, because that would be treated as a sign of weakness before public. Very democratic). And that’s how it ended in the current state where everybody lies to cover the failures and nobody gets punished for it (essentially only disloyalty gets punished).

This system can exist only in an environment rich of resources where you can waste most of them (because corruption will eat most of it) and yet what remains is enough to sustain the lavish lifestyle of the elites and there’s something for the common folk as well. But they decided to start a way which has cut their income significantly and caused an internal struggle for the dwindling resources (just search the news for how many top managers of large russian companies have died recently), the common folk is ignored as it always has been. So how it can end for them? I see three alternatives (not counting the MAD one): russia dissolves further into smaller states that might not become better but at least they can be forgotten about; russia becomes yet another North Korea—a Chinese colony where almost everything belong to the state (and to the army), everybody works for peanuts, they blame America for their bad life and they do not see or desire any other way of living; or russia might remain a terrorist state like any such state around Israel that russia is friends with—in this case Ukrainian live will be rather similar to Israeli one with regular attacks that are mostly annoying and show their hate. In either case I don’t see it winning since you can’t win by constantly lying to yourself. And showing that how little you honour any agreement as soon as it stops benefiting you is not a good way to make businesses work with you (China does the same thing but it does it much smarter and using point strikes, so it gets a pass for now).

To summarise my long incoherent ramblings in one sentence, this war shows that not all democratic regimes are really democratic and that almost all of the regimes are holding fine except for the one built on lies and incompetency. I expect it to fall apart suddenly, the same way as its predecessor did (even if the war was cold back then).

A cursory glance at Daniel codecs

Sunday, July 10th, 2022

Recently Paul B. Mahol turned my attention to the fact there are codecs with human names so why not take a look at them?

The first disappointing thing is that you need to register in order to receive a link for downloading that software. Oh well, throwaway mail services exist and it’s not the first codec I’ve seen doing that (though I’ve forgotten its name already like I’ll forget about this codec). Then it’s the binary size. I remember thinking that Go2Somewhere single 15MB .dll is too much but here’s is even larger (because they’ve decided to bundle a bunch of other decoders and demuxers instead of just one codec).

In either case, what can I say about the codec? Nothing much really. They both seem to be DCT-based intermediate codecs that group blocks into slices. Daniel2 uses larger tiles in slices, probably to accommodate for the wider variety of supported chroma formats (unlike its predecessor it supports different colourspaces, chroma subsamplings and bitdepths). The claimed high (de)coding speed comes from the same approach as in VBLE (does anybody remember it? I still remember how Derek introduced its author to me at one of VDDs). Yes, they simply store coefficients in fixed amount of bits and transmit bit length for each tile to use.

The only really curious thing I’ve found is some combinatorial coding approach I’ve never seen anywhere else. Essentially it stores something like sum in a table and for each value only the number of table entries is transmitted. Actual value is decoded as (max(table[0], ..., table[len - 1]) + min(table[0], ..., table[len - 1]) + 1) / 2 and then the decoded value is subtracted from all table elements used in the calculation. I have no idea why it’s there and what it’s good for but it exists.

Overall, it was not a complete waste of time.

Spectral Band Replication in various audio codecs

Thursday, July 7th, 2022

While the war continues I try to distract myself with something less unpleasant, recently it was implementing SBR support for AAC decoder in NihAV. And since I’ve done that why not talk about this technology and its varieties?

The idea of saving bits in lossy codec by coding less important high frequencies in an approximate way is not very new, the first case that comes to mind was aacPlus codec from Coding Technologies that served as a base for AAC SBR (and MP3Pro if you remember such thing). It allows to code the upper part of the spectrum very efficiently compared to the normal AAC codec (I’d say it takes 4-12kbps for that compared to 50-60kbps used for the lower frequencies) which allowed to cut audio bitrate significantly comparing to AAC-LC of similar quality. And since it was a good idea, other codecs used it as well but in different format (because patent infringements are fun when both parties employ hordes of lawyers).

So, let’s look at how it’s done in the codecs I can remember (if you know more feel free to comment):

  • AAC SBR (also mp3PRO but who cares)—the original that inspired other implementations. It works by splitting frame into series of 64-band slots (using complex numbers unless it’s a coarse low-power SBR that uses only real numbers), copying lower frequencies into high ones using a certain shape and adding scaled noise or tones (those two are mutually exclusive). For transmission efficiency lots of those parameters are derived from the configuration (that is transmitted once for couple frames) and essentially only envelopes used to shape coefficients and noise plus some flags are coded. You have to generate a lot of tables (like how QMF bands are grouped for four modes of operation, what gains to use on coefficients/noise/tones for each QMF band in each slot and so on). Eventually there were other variants developed (because there are other AAC codecs that could use it) but the approach remains the same;
  • E-AC-3—this codec has SPectral eXtension which divides frame into fixed sub-bands and copies data from lowed sub-bands, applies a specific scale to that data and blends it with noise scaled with another scale;
  • AC-4—this one has A-SPX that looks a lot like the original SBR (and considering that D*lby got the team behind it it’s not that surprising). I can’t be bothered to look at the finer details but from a quick glance it looks very similar (starting with all those FixVar and VarFix envelopes). If you want to know more about the implementation just ask Paul B. Mahol, it should be more fun than the usual questions about AC-4 he gets;
  • ATRAC9 (but not earlier)—this codec seems to split spectrum into four parts, fills them either with mirrored coefficients from below or with noise and applies coarser or finer scaling to those bands;
  • WMA9 (or was it WMAPro or WMA3?)—as usual it’s “we should overengineer AAC” approach. There’s not much known about how it really functions but it seems to split higher frequencies into variable-length bands and code motion vectors for each band telling from which position to copy (and since audio frames in MDCT-based codec are essentially P-frames, this is too close to being a video codec for my taste). There are three modes of operation for the bands too: copy data, fill with noise, or copy only the large coefficients and fill the rest with noise. I have an impression they tried to make it less computation-heavy than AAC SBR while having the similar or larger amount of features.

I guess you can see how these approaches are different yet alike at the same time and why it was not much fun to implement it. Yet I still don’t consider this time wasted as I gained more understanding on how it works (and why I didn’t want to touch it before). Now maybe it’s time to finally play with inline assembly in Rust.