Jump to content

Wikipedia:Reference desk/Archives/Computing/2021 January 10

From Wikipedia, the free encyclopedia
Computing desk
< January 9 << Dec | January | Feb >> Current desk >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


January 10[edit]

"Bitshift variations" song[edit]

How does this code actually work? (Source: https://txti.es/bitshiftvariationsincminor)

echo "g(i,x,t,o){return((3&x&(i*((3&i>>16?\"BY}6YB6%\":\"Qj}6jQ6%\")[t%8]+51)>>o))<<4);};main(i,n,s){for(i=0;;i++)putchar(g(i,1,n=i>>14,12)+g(i,s=i>>17,n^i>>13,10)+g(i,s/3,n+((i>>11)%3),10)+g(i,s/5,8+n-((i>>10)%3),9));}"|gcc -xc -&&./a.out|aplay

Ponzammo (talk) 08:30, 10 January 2021 (UTC)[reply]

If it works for you, you must be on a Linux system with an ALSA sound card driver. Not having one I cannot try this out. The C program produces an infinite stream of bytes, but I do not feel inclined to figure out the intentionally obfuscated code. Even if you figure it out, it will not make sense unless you understand the default encoding of aplay. The man page does not specify it. The .wav file format would be a plausible candidate for this default, but I see no way the C code could produce the requisite wave data. The .au file format would be another plausible candidate, but again, I see no way the C code could produce the requisite magic number.  --Lambiam 11:01, 10 January 2021 (UTC)[reply]
If you send aplay data with no intelligible header, it defaults to PCM data. In the case of my machine, that default is unsigned 8 bit mono at 8000 Hz - I don't know how universal that default is, but the OP's code assumes something of that nature. For clarity, we can write a more legible program that synthesises a simple waveform, which can be piped to aplay:
#!/usr/bin/env python3
import sys

# unsigned 8 bit mono triangle waveform
up =   bytes(x for x in range(0,256,7))
down = up[::-1] # reversed

while True:
    sys.stdout.buffer.write(up)
    sys.stdout.buffer.write(down)
-- Finlay McWalter··–·Talk 12:46, 10 January 2021 (UTC)[reply]
Reading the defaults for the individual options in the man page for aplay, unsigned 8 bit mono at 8000 Hz is indeed a standard default. -- Finlay McWalter··–·Talk 00:42, 11 January 2021 (UTC)[reply]
As a general remark, on the spectrum of obfuscated source-code, the program in the original post is "not very difficult to read." For example, I frequently read and build the entries from the IOCCC (one of the more famous obfuscated C code "competitions") - I find many of these to be entertaining and educational on a variety of fronts.
The sample source-code here is not very obfuscated - it's just poorly formatted, and relies on many default behaviors of the C programming language. Whether your C compiler will honor this specific dialect will depend on exactly which version of GCC (or other compiler) is present.
What we've got is a sum of filtered sawtooth functions - it's quite trivial to build a sawtooth wave out of a for-loop with incrementing index, depending on integer-wraparound to reset the signal value; and that data is passed to a variety of bitwise math that is essentially constructing some kind of harmonic "music"-like tones.
So to answer the question about how it works - here's a deep link directly into the middle of one of my favorite books: filtered white noise. It is a mathematical fact (derived formally in the entire lecture on noise analysis and deeply detailed in many free books available from the same author) - when you apply specially-constructed filtering to any input signal, especially one that begins with harmonic waveforms - you can easily produce an output signal that has characteristics mimicking a musical instrument. By carefully crafting the filter, one can yield the specific properties that make music sound musical - things like timbre and harmonics - which have very simple mathematical forms expressible in various ways.
So to simplify the explanation: the source code in the example presented in this question produces a periodic signal (using a for-loop with integer wrap-around); and then it filters that periodic signal. It does so on four separate instances of a periodic signal - a linear combination of periodic waveforms - a poor-man's "sum of sinusoids" - ostensibly to add timbre. It filters these through a very ugly noise-filter, namely the function g(i,x,t,o) - which uses a very ugly block of code to construct a strange LUT - so we're essentially building an FM Synthesizer. And it does all of this using very poorly spaced sourcecode in the C language, relying on several default behaviors of the default C compiler, resulting in a sample program that is fairly difficult to understand and extremely difficult to compile on any computer that differs in even the slightest manner from the original author's expectations.
The point is, this is "complicated" code because it's very ugly and undocumented, but it's a standard method - sort of an "atom" from which the "molecules" of bigger signal-processing algorithms get built - so it's instantly recognizable to anyone who does this kind of signal processing on a regular basis.
The output - which is binary - is interpreted as an audio input by aplay, a test-tool provided by the Advanced Linux Sound Architecture system, an integrated part of many Linux systems that can directly interface to the sound output hardware.
Nimur (talk) 18:28, 11 January 2021 (UTC)[reply]
And a note to the wise: this sample-program is pretty harmless - but it's a great example of why users should be careful about copying text to their terminal. This text, when copied to the terminal, generates source-code, compiles that source-code, and then executes that source-code, and in fact pipes the program output to a hardware device-driver. If a user does not understand why this is a risk "in general," the user probably has no business using a terminal in the first place - for any purpose whatsoever. Copying commands to your terminal when you don't understand every single part of the command presents an extraordinarily hazardous computer-security risk. Nimur (talk) 18:32, 11 January 2021 (UTC)[reply]
Consider me nerd-sniped. I was able to get the program to execute on macOS, by installing mplayer and gcc via Homebrew, and running the following:
alias aplay="mplayer -cache 1024 -quiet -rawaudio samplesize=1:channels=1:rate=8000 -demuxer rawaudio -"
gcc-10 song.c && ./a.out | aplay;
After spending way too much time tinkering with the obfuscated source code, I wrote a slightly more legible C program which produces the same output, and hopefully explains how it's being generated. Not sure anyone else will find that useful, but here it is.
// song.c
// Deobfuscated by Roxy
// Outputs an 8-bit 8 kHz PCM song to stdout
// Can be played using aplay, sox, or mplayer
#include <stdio.h>

// generates an square(?) wave with the given frequency
int wave(int i, int freq, int octave) {
  return (1 & (i * freq >> octave)) << 4;
}
// there are two 8-note sequences
// the song switches between them after 20 measures.
int note(int measure, int t) {
  int sq1[] = { 117, 140, 176, 105, 140, 117, 105, 88 };
  int sq2[] = { 132, 157, 176, 105, 157, 132, 105, 88 };
  return (((measure >> 2) % 4 != 0) ? sq1 : sq2)[t % 8];
}
// main method
int main() {
  for (int i = 0;; i++) {
    int beat = i >> 10;       // counts 16th notes
    int measure = beat / 16;  // increments every whole note
    int wav = 0;
    if (measure >= 0) {  // sequence 1: whole notes
      int t = measure;
      wav += wave(i, note(measure, t), 12);
    }
    if (measure >= 8) {  // sequence 2: half note oscillator
      int t = measure ^ (beat / 8);
      wav += wave(i, note(measure, t), 10);
    }
    if (measure >= 16) {  // sequence 3: eigth note oscillator
      int t = measure + ((beat / 2) % 3);
      wav += wave(i, note(measure, t), 10);
    }
    if (measure >= 24) {  // sequence 4: sixteenth note oscillator
      int t = measure + (beat % 3);
      wav += wave(i, note(measure, t), 9);
    }
    putchar(wav); // write byte to stdout
  }
}
Ciao! RoxySaunders (talk) 19:55, 11 January 2021 (UTC)[reply]
Thanks to RoxySaunders for providing source that builds and runs (in an unmodified form!) with modern, non-pathological tools!
As a note, one does not necessarily have to set sampling-rate at 8000 Hz. The song will sound musical - or at least chiptuney - at a variety of sampling frequencies. This is a great way for the enthusiast to explore the interrelationship between arpeggio, vibrato, and tremolo, which are all really the same exact thing implemented with different bandwidth! (... with some apologies to our music theory enthusiasts who may take offense - after all, without loss of generality, a sufficiently formal treatment can describe every audio signal as a sum of sinusoids - which is what makes computerized digital audio possible!)
For the user with less time, less ALSA, and more access to commercial software, here's sound in MATLAB. Nimur (talk) 22:15, 11 January 2021 (UTC)[reply]
Also, to fill in details for anyone not well-versed in Unix terminal: the C program feeds its output (the sound data) to standard output. This gets piped to aplay's stdin. As you can see from the man page, aplay reads stdin if not given a filename. aplay itself is a compact media player provided as part of ALSA. Programming exercise for those interested: extend the C program to play the audio itself by utilizing the ALSA libraries. --47.152.93.24 (talk) 03:43, 12 January 2021 (UTC)[reply]

Dead website[edit]

Say that you try to access a website that you have accessed many times over many years ... and, out of the blue, it's no longer available. Is there any way to find out what happened to it? (For example, the site "went out of business", etc., or whatever.) There is no error message or redirect or any such thing. The computer just sits there for several minutes ... with the hour-glass icon for "waiting" ... and, eventually, it says this: Problem loading page. The connection has timed out. The server at www.fyndit.com is taking too long to respond. The site could be temporarily unavailable or too busy. Try again in a few moments. If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web. As indicated above, the website is www.fyndit.com ... it is (or was?) a website somewhat similar to eBay. Thanks. 32.209.55.38 (talk) 23:52, 10 January 2021 (UTC)[reply]

The site is (or was) the words "find it", with the intentional mis-spelling of "fynd". 32.209.55.38 (talk) — Preceding undated comment added 23:57, 10 January 2021 (UTC)[reply]
There are sites that you can use to get a "third opinion" and rule out whether it is your local network or browser: Down For Everyone? A network timeout could mean many, many kinds of things have gone wrong in the network layer. The provider may have lost their DNS hosting. The DNS may point to a dead host instead of the real, live one. The host could be indeed switched off. I don't know if you're asking about "what happened to it" in an IT sense or a business sense. This is the computing reference desk. We could bring several tools to bear to fynd out what became of the server that was hosting this service. We can't really know if they are out of business, out of money, everyone quit, whatever the business reasons may be for such an outage, that is beyond our scope. Elizium23 (talk) 00:28, 11 January 2021 (UTC)[reply]
Fyndit.com shows an insecure website claiming they are "Currently down for maintenance". I hope that when they come up, they have TLS certificates. Elizium23 (talk) 00:30, 11 January 2021 (UTC)[reply]
It sort of looks to me like fyndit.com has been on life support for a while. Their maintenance page is copyright until 2016 and most sites updates those notices every year. Their Facebook page, Twitter and blog seem to have died in 2015 [1] [2] [3]. Their iOS app seems to be dead [4] no idea since when since Apple's apps store is fairly crap at providing info on the open web. Their pinterest, no idea since pinterest doesn't seem to believe in dates [5]. Looking at the archived version of their website, [6] most of the links and I mean simple ones like FAQ, contact us, hiring, privacy policy etc don't work. I think because of archiving issues with their complicated site as I can see signs of a privacy policy in search engine results and I'm surprised they would have kept it this long if the privacy page was dead. But if those links really were dead for years, that's another sign of how bad things were. Obviously someone needed renew the domain and perform other essential maintenance and was even still working on parts of it e.g. their G+ link was removed [7] but frankly I'm surprised you still found it useful last year. Maybe it'll be back, but I wouldn't count on it long term. Their community forum seems to have had a similar maintenance message for a long time [8] [9] [10] Nil Einne (talk) 03:57, 11 January 2021 (UTC)[reply]
Both ping and dig tell me that www.fyndit.com resolves to IP 52.218.234.34, which is hosted by Amazon Technologies Inc.; whois produces "redacted for privacy" for almost everything, except that the registrant organization is Tutupata, Inc., based in California. The registry was last updated 2020-05-07, which is fairly recent. It looks like they did not pay the bill to Amazon. The latest capture by the Archive Team (which can use your donations) is from October 3, 2020, when FyndIt were still in the air. Here the FyndIt app is described as "FyndIt by Tutupata, Inc", but iTunes says it is not available in any store I tried (US, EU, India). There is an app named "fyndit.co" in Apple's app store, but it does not seem related. The signs point to the demise of FyndIt, Inc. and the website and app. I found no signs of life for Tutupata, Inc., either; in fact, FyndIt appears to have been a new incarnation of Tutupata rather than a spin-off.[11]  --Lambiam 14:58, 11 January 2021 (UTC)[reply]
Lambiam, the Amazon IP indicates they were hosted on AWS, which can sometimes indicate that a company was being run on-the-cheap rather than self-hosting (although plenty of respectable companies host in the cloud too.) Elizium23 (talk) 18:32, 11 January 2021 (UTC)[reply]