arflech
He/Him
Joined: 5/3/2008
Posts: 1120
^I know; all you said was that you tested in Linux and Cygwin, so I tested in native Windows. :-D Also that property of "HTML is ON" is odd; I figured out that was why .h kept disappearing in include directives, but I wonder why the code tag isn't treated as a pure CDATA section or like a pre element or something, where no tags inside the code tags will be parsed.
i imgur com/QiCaaH8 png
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Nach wrote:
Well I thought it was obvious for the most part, with good function names and clear strings which says what it does. <...> What I do find very enlightening about your mini program is that it has a PNG encoder. I never considered doing that without using libpng.
Thank you for humoring me. Some 20 edits later, I have to admit that I am surprised as well, how simple turns out to be the PNG format, and the code that generates a valid PNG file (albeit without using fancy huffman coding, but valid nevertheless). arflech, the biggest problem in porting that code to Winsock is the use of fdopen(). In POSIX, all file descriptors are equal, and they can all be used with the same system calls. In Microsoft Windows, sockets live in an entirely different universe than file handles, and a function that can read from a file (such as fgets, in this case) cannot read from a socket.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
I still wonder...what components of Cygwin do I need installed to see the animation?
i imgur com/QiCaaH8 png
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Bisqwit wrote:
I am surprised as well, how simple turns out to be the PNG format, and the code that generates a valid PNG file (albeit without using fancy huffman coding, but valid nevertheless).
In comparison, GIF turns out to be really complicated. I had to make a GIF writer for a project at work, and even though this code, similarly to the PNG writer I posted, does the least necessary work to produce legal "compressed" stream, it is considerably lengthier than the PNG writer. * (This is a simplified version of the code I wrote for work; the actual version creates an animated GIF. I also wrote the actual code in C++; this sample is in C.) [code c]static void WriteGIF89a( FILE* fp, unsigned width, unsigned height, const unsigned char* data) { unsigned palette_extra = 64-n_palette_colors; /* assuming 32<n<=64 */ const unsigned framesize = width * height; const unsigned char GifHdr[] = { 'G','I','F','8','9','a', width&0xFF, width>>8, height&0xFF, height>>8, 0x80 | // global color table (palette) ((8-1)*16) | // 8-bit colors (0*8) | // palette is not sorted (6-1), // 64 colors (2^6) n_palette_colors-2, // background color index 0 // dummy aspect ratio }; const unsigned char ImageDescriptor[] = { 0x2C, 0,0,0,0, // left,top position width&0xFF, width>>8, height&0xFF, height>>8, 0 }; fwrite(GifHdr, sizeof(GifHdr), 1, fp); fwrite(&palette[0], n_palette_colors*3, 1, fp); fwrite(&palette[0], palette_extra *3, 1, fp); fwrite(ImageDescriptor, sizeof(ImageDescriptor), 1, fp); { unsigned char minbits = 6; /* 6 bits are enough to convey image pixels */ unsigned codebits = minbits+1, clrcode = 1 << minbits, eoicode = clrcode+1; unsigned pos, bumppos, outcode = clrcode, bufbits = 0, n_bufbits = 0; unsigned char buffer[256] = {0}; #define buflen buffer[0] fputc(minbits, fp); for(pos=0; ; ) /* This code copied and adapted from ungifwrt in gifsicle */ { bufbits |= outcode << n_bufbits; for(n_bufbits += codebits; n_bufbits >= 8; n_bufbits -= 8) { buffer[1 + buflen++] = bufbits & 0xFF; if(buflen >= 255) { fwrite(buffer,buflen+1,1,fp); buflen=0; } bufbits >>= 8; } if(outcode == clrcode) { bumppos = pos + (clrcode - 2); } else if(pos == bumppos) { outcode = clrcode; continue; } else if(outcode == eoicode) { break; } outcode = (pos < framesize) ? data[pos++] & ((1 << minbits)-1) : eoicode; } if(n_bufbits) buffer[1 + buflen++] = bufbits; if(buflen > 0) fwrite(buffer,buflen+1,1,fp); #undef buflen fputc(0, fp); } fputc(0x3B, fp); }[/code] *) Or so I wanted to claim, but turns that after I removed the animation handling code, it is about the same length as the PNG writer. Oops.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
arflech wrote:
Anyway, yesterday I used an Ubuntu machine to compile that Chrono Trigger-related C code (after compiling TCC and then using TCC to compile TCC), and the program still didn't seem to do anything.
While running, it is to be accessed with another program. A program commonly utilized in Internet-capable computers.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
EEssentia wrote:
If you do that, then you need to format it so that it is more readable. For example:
bool Point::operator<(const Point& rhs)
{
    return x != rhs.x ?
        x < rhs.x : y != rhs.y ?
        y < rhs.y : z < rhs.z;
}
I much prefer
bool Point::operator<(const Point& rhs)
{
    return x != rhs.x ? x < rhs.x :
           y != rhs.y ? y < rhs.y :
           z < rhs.z;
}
And since we are in the topic of "guess what this program does", the next question would be: Which encoding does the following function perform (function name obfuscated so that it won't give the answer right away):
void foo(const unsigned char* begin, const unsigned char* end, std::string& dest)
{
    while(begin < end)
    {
        unsigned value = 0;
        char buf[6] = { 'z', 0, 0, 0, 0, 0 };
        for(int i = 0; i < 4; ++i, ++begin)
            value = value << 8 | (begin<end ? *begin : 0);
        if(value || begin > end)
            for(int i = 0; i < 5; ++i, value/=85) buf[4-i] = value%85+33;
        dest += buf;
    }
    if(begin > end) dest.resize(dest.size()-(begin-end));
}
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
Bisqwit wrote:
arflech wrote:
Anyway, yesterday I used an Ubuntu machine to compile that Chrono Trigger-related C code (after compiling TCC and then using TCC to compile TCC), and the program still didn't seem to do anything.
While running, it is to be accessed with another program. A program commonly utilized in Internet-capable computers.
I uploaded it to a website and gave it the filename chrono.cgi after compiling, then sent it to ~/cgi-bin/ and gave it chmod 777 and tried to run it in Opera...and all I get is an HTTP 500 error
Nach wrote:
arflech wrote:
It is sad that GCJ still does not understand Java 1.6 or even all of Java 1.5
It is sad that the Java language has so many iterations in such a short time.
Java 6 has been available since 2006 (soon it should be eclipsed by Java 7 though), and GCJ has stopped active development; one the one hand it is good that most of Java itself is open-source, but then again javac doesn't compile to native code like GCJ does.
i imgur com/QiCaaH8 png
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
arflech wrote:
Bisqwit wrote:
arflech wrote:
Anyway, yesterday I used an Ubuntu machine to compile that Chrono Trigger-related C code (after compiling TCC and then using TCC to compile TCC), and the program still didn't seem to do anything.
While running, it is to be accessed with another program. A program commonly utilized in Internet-capable computers.
I uploaded it to a website and gave it the filename chrono.cgi after compiling, then sent it to ~/cgi-bin/ and gave it chmod 777 and tried to run it in Opera...and all I get is an HTTP 500 error
The program in itself is a server, you don't want to run it as CGI. You'll also see in the source code which port it runs on.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
I feel massive loads of hurrgurdy-gurrgurdy here:(
i imgur com/QiCaaH8 png
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Warp wrote:
And since we are in the topic of "guess what this program does", the next question would be: Which encoding does the following function perform (function name obfuscated so that it won't give the answer right away):
void foo(const unsigned char* begin, const unsigned char* end, std::string& dest)
{
    while(begin < end)
    {
        unsigned value = 0;
        char buf[6] = { 'z', 0, 0, 0, 0, 0 };
        for(int i = 0; i < 4; ++i, ++begin)
            value = value << 8 | (begin<end ? *begin : 0);
        if(value || begin > end)
            for(int i = 0; i < 5; ++i, value/=85) buf[4-i] = value%85+33;
        dest += buf;
    }
    if(begin > end) dest.resize(dest.size()-(begin-end));
}
Well, since it contains the magic number 85 and seems to be about encoding numeric values into a buffer, and it reminds me of a similar encoding scheme encountered in either PDF or FLV files, I don't remember which, I had to check. I did a locate base85, and found a file in Git's source code that does something like that. I'm satisfied with that hypothesis. The rest of the code seems to be about encoding the length of the string in the buffer, so a decoder knows how long a string to decode, assuming lack of that information from other sources. So in short, the answer to your question is: Ascii85.
Post subject: Powers of C++ and compile-time constants
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Bisqwit wrote:
One more in the series of "what does this do?". And more to the point, how? Language: C++ [code c++] #include <assert.h> namespace ValueTest { enum { n = 8*sizeof(unsigned long) }; template<typename Enumerator> struct SetMax { int result; inline void receive(int value) { if(value > result) result = value; } inline SetMax() : result(0) { Enumerator::send_values(*this); } }; template<typename Enumerator, int i> struct BitSet { unsigned long result; inline void receive(int value) { if(value >= n*i && value < n*(i+1)) result |= (1UL << (unsigned(value) % n)); } inline BitSet(unsigned value) : result(0) { Enumerator::send_values(*this); result &= (1UL << (value % n)); } }; template<typename Enumerator> inline bool TestValue(unsigned value) { const int max_recognized = SetMax<Enumerator>().result; // ^Should become a compile-time constant assert(max_recognized < n*8); // ^If this assertion fails, the number of values // is too great for this code (256 on 32-bit, 512 on 64-bit). /* Compile-time magic will reduce this code to a minimal * set of branches and bit-tests. Generally more effective * than a switch-case. */ if(value < n*4 || !(max_recognized >= n*4)) {if(value < n*2 || !(max_recognized >= n*2)) {if(value < n*1 && max_recognized >= n*0) return BitSet<Enumerator,0>(value).result; else if(value < n*2 && max_recognized >= n*1) return BitSet<Enumerator,1>(value).result; } else {if(value < n*3 && max_recognized >= n*2) return BitSet<Enumerator,2>(value).result; else if(value < n*4 && max_recognized >= n*3) return BitSet<Enumerator,3>(value).result; }} else {if(value < n*6 || !(max_recognized >= n*6)) {if(value < n*5 && max_recognized >= n*4) return BitSet<Enumerator,4>(value).result; else if(value < n*6 && max_recognized >= n*5) return BitSet<Enumerator,5>(value).result; } else {if(value < n*7 && max_recognized >= n*6) return BitSet<Enumerator,6>(value).result; else if(value < n*8 && max_recognized >= n*7) return BitSet<Enumerator,7>(value).result; }} return false; } } struct IsOneOfTheseSet { template<typename Receiver> static inline void send_values(Receiver& r) { r.receive(2); r.receive(3); r.receive(5); r.receive(7); r.receive(11); r.receive(13); r.receive(17); r.receive(19); r.receive(23); r.receive(29); r.receive(31); r.receive(37); r.receive(41); r.receive(43); r.receive(47); r.receive(53); r.receive(59); r.receive(61); } bool operator() (unsigned value) const { return ValueTest::TestValue<IsOneOfTheseSet> (value); } } IsOneOfThese; #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { int value = atoi(argv[1]); return printf("%d%s.\n", value, IsOneOfThese(value) ? " is": " is not"); }[/code] Hint: Look at the generated assembler code at maximum optimization levels – preferably use GCC.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
	.file	"valuetest.cpp"
	.def	___main;	.scl	2;	.type	32;	.endef
	.section .rdata,"dr"
LC0:
	.ascii " is\0"
LC1:
	.ascii " is not\0"
LC2:
	.ascii "%d%s.\12\0"
	.text
.globl _main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
	pushl	%ebp
	movl	%esp, %ebp
	andl	$-16, %esp
	subl	$16, %esp
	call	___main
	movl	12(%ebp), %eax
	movl	4(%eax), %eax
	movl	%eax, (%esp)
	call	_atoi
	cmpl	$31, %eax
	ja	L2
	movl	%eax, %ecx
	andl	$31, %ecx
	movl	$1, %edx
	sall	%cl, %edx
	andl	$-1601558356, %edx
	setne	%cl
L3:
	movl	$LC0, %edx
	testb	%cl, %cl
	je	L4
L5:
	movl	%edx, 8(%esp)
	movl	%eax, 4(%esp)
	movl	$LC2, (%esp)
	call	_printf
	leave
	ret
L2:
	cmpl	$63, %eax
	jbe	L8
L4:
	movl	$LC1, %edx
	.p2align 4,,4
	jmp	L5
L8:
	movl	%eax, %ecx
	andl	$31, %ecx
	movl	$1, %edx
	sall	%cl, %edx
	andl	$673221152, %edx
	setne	%cl
	jmp	L3
.globl _IsOneOfThese
	.bss
_IsOneOfThese:
	.space 1
	.def	_atoi;	.scl	2;	.type	32;	.endef
	.def	_printf;	.scl	2;	.type	32;	.endef
It compares the first command-line argument to one of the first 18 prime numbers; the above assembly code was not helpful. I did notice that the executable was a lot smaller than the last few times I compiled a simple program with GCC; it was about 5.5KB, about the size I get from TCC when compiling simple C programs. Just for laughs I decided to look at the output of using Visual C++; the asm was unwieldy and the executable was 2MB and it crashed with no arguments (instead of saying "0 is not.").
i imgur com/QiCaaH8 png
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
It's even better in 64-bit: (Irrelevant lines omitted)
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string " is" 
.LC1:
        .string " is not"
.LC2:
        .string "%d%s.\n" 
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        subq    $8, %rsp
        movq    8(%rsi), %rdi
        movl    $10, %edx
        xorl    %esi, %esi
        call    strtol
        cmpl    $63, %eax
        movl    %eax, %esi
        jbe     .L11
.L8:
        movl    $.LC1, %ecx
.L9:
        movq    %rcx, %rdx
        movl    $.LC2, %edi
        xorl    %eax, %eax
        addq    $8, %rsp
        jmp     printf
        .p2align 4,,10
        .p2align 3
.L11:
        movl    %eax, %ecx
        movl    $1, %eax
        movabsq $2891462833508853932, %rdx
        andl    $63, %ecx
        salq    %cl, %rax
        movl    $.LC0, %ecx
        testq   %rdx, %rax
        jne     .L9   
        jmp     .L8
That's awfully small code for such complex looking program. The method of comparing to the list of prime numbers is by checking the given number against a single bitmask. This demonstrates well the fact that abstraction in C++ does not necessarily reflect runtime overhead. There are zero method calls or pointers in this assembler code, even though the C++ code was rife with functors and references.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
One of my tiny musical tunes as a an ANSI C++ program. This will generate a MIDI file to stdout. Run by redirecting the output to a file, e.g:
./prog > result.mid
#include <string>
#include <iostream>
#include <cstdio>
typedef std::string S;int Kf=128,Ko=144;
static S n(int v,int k) {return (k--?n(v>>8,k)+(char)v:S());} /* Big-endian encoder */
struct mt{
  S s/*stream*/;int d/*delay*/,c/*channel*/,P/*last note number*/;
  mt(int t):d(0),c(t),P(0) {me(88,"\4\2\30\10");me(81,n(1000000,3));}
  S G() {return me(47),"MTrk"+n(s.size(),4)+s;} /* End track and return as string */
  void F() {if(d>>14)B((d>>14)|Kf);if(d>>7)B((d>>7)|Kf);B(d&127);d=0;} /* Flush delay */
  void B(char c) {s+=c;} /* Append raw byte */
  void by(int c) {if(c&0x80)F();B(c);} /* Append byte, flush delay when starts a new event */
  void d2(int T,int a) {by(T|c);B(a);} /* Two-byte event */
  void t3(int T,int a,int b=127) {d2(T,a);by(b);} /* Three-byte event */
  void me(int t,S a=S()) {by(255);B(t);B(a.size());s+=a;} /* Meta event */
  void dif(int c,int p,int b,int o=0)
    {if(c!='!')t3(Kf,P),t3(Ko,P=c+o,b); d+=p;} /* Ascii note */
  void com(int Patch,const char*s,int p,int b=127,int o=0)
    {for(d2(0xC0,Patch);*s;)dif(*s++,p,b,o);}/* Note parser */
}A(0),B(1),C(2),D(9),M(4),N(5);
#define X2(s) s s
#define X4(s) s s s s
#define ABI(b,c) #b"!"#b X2(#b"!")X2(#c"!")#c X2(#c"!")

int main(void)
{
  int De=133;
  C.com(0,"!",10*2);
  A.com(0,"!",20*2);
  X4(X2(
  A.com(0, ABI(T,T)ABI(T,T)ABI(T,T)"SRS!V!V!V!!!!!!!", De,127);
  B.com(0, ABI(L,Q)ABI(P,O)ABI(M,K)"JJJ!M!O![!!!!!!!", De,127);
  C.com(0, ABI(O,M)ABI(K,K)ABI(P,P)"OOO!O!S!S!!!!!!!", De,127);
  M.com(35,"0!!!!!!5!!!!!!!!8!!0!3!7!!!!!!!!5!!!!!!3!!!!!!!!2!!!!!!!7!!!!!!!", De,127,-12);)
  N.com(75,X4(X4(X4("!")))
           "T!TT!Q!Y!X!V!T!!P!!WV!T!O!!!!!!!P!!PT!P!O!P!K!!!M!O!J!C!M!!!!!!",De,127);
  N.com(75,"$",De,0,0);)
  
//  std::cout << "MThd"+n(6,4)+n(1,2)+n(6,2)+"\3\232"+A.G()+B.G()+C.G()+D.G()+M.G()+N.G();

  std::string tmp = "MThd"+n(6,4)+n(1,2)+n(6,2)+"\3\232"+A.G()+B.G()+C.G()+D.G()+M.G()+N.G();
  std::fwrite(tmp.data(), 1, tmp.size(), stdout);
}


/* Chart of note names:
 -  A-0     9  A-1      E  A-2    Q  A-3   ] A-4   i A-5   u A-6
 .          :           F         R        ^       j       v
 /  B-0     ;  B-1      G  B-2    S  B-3   _ B-4   k B-5   w B-6
 0  C-1     <  C-2      H  C-3    T  C-4   ` C-5   l C-6   x C-7
 1          =           I         U        a       m       y
 2  D-1     >  D-2      J  D-3    V  D-4   b D-5   n D-6   z D-7
 3          ?           K         W        c       o
 4  E-1     @  E-2      L  E-3    X  E-4   d E-5   p E-6
 5  F-1     A  F-2      M  F-3    Y  F-4   e F-5   q F-6
 6          B           N         Z        f       r
 7  G-1     C  G-2      O  G-3    [  G-4   g G-5   s G-6   ! is used
 8          D           P         \        h       t         for pauses
*/
In GCC, compiles without compiler warnings.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
I tried playing the MIDI file but it wouldn't load in Anvil Studio (an editor for MIDI files).
i imgur com/QiCaaH8 png
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
arflech wrote:
I tried playing the MIDI file but it wouldn't load in Anvil Studio (an editor for MIDI files).
Hmm. The program assumes that std::cout does not do any changes to the binary data, such as changing LFs to CRLFs. It is possible it only works properly on Unix systems. EDIT: I completely forgot that some systems require such changes. I suck at C (or C++). To change the program such that it works also on Windows, change the std::cout line to:
  std::string tmp = "MThd"+n(6,4)+n(1,2)+n(6,2)+"\3\232"+A.G()+B.G()+C.G()+D.G()+M.G()+N.G(); 
  std::fwrite(tmp.data(), 1, tmp.size(), stdout);
And add #include <cstdio> to the beginning of the file.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
ooo, I will try changing those characters in SciTE and if that fails, I will try compiling in Cygwin EDIT: it worked, I just opened the MIDI file in SciTE and changed "Line-End Characters" from CR+LF to LF and then chose the "Convert Line-End Characters" option
i imgur com/QiCaaH8 png
Post subject: mp3 streaming and vintage NES songs
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
arflech wrote:
I uploaded it to a website and gave it the filename chrono.cgi after compiling, then sent it to ~/cgi-bin/ and gave it chmod 777 and tried to run it in Opera...and all I get is an HTTP 500 error
Here is code that is to be used in the manner you described. Requires libmp3lame (found in LAME, the mp3 encoder) to compile and to run. I would have added my own mp3 encoder but I found it too complex to write, even if I know the exact sine waves I'm going to produce… And I couldn't find any other streaming audio codec that would work and be less complex. Wav is simple, but cannot be streamed…
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <lame/lame.h>

static const char* const channels[4] = {
  "S3802A020m!5gYW!\\!W1gZ\221Zm!4gYW!\\m!4d\\\\\\\\2g!\\y!YS3803AB10yP3dMNP2"
  "gUPW1dSyS2mPNyP3dMNP2gYUW1dZyZ2mYWyP3dMNPgUjPyS3dPQSgXjS2gVSdVj[2gXUdXj]m_"
  "Vm_W1UmSVmSS38028F20UOdNPQSUWXWUWUSQSQPLNPQSUWUOdSUSQPONMNPQSUWXWOQRTUWXWj"
  "DW1dIgIW1jNdN4gSX]\\6dZ\\!Z\\Z2gYU4d!UWYgZ6dXZ!XZX2gVS4d!STVOeXTOLHCZVQNJE"
  "[XTOLH\\WTPKHP0",
  "S3702A020m!5gUU!U!W1gS\221Sm!4gUU!Um!4dTTTT2g!Ty!YS3703AB10yM3dIKM2gPMW1dN"  
  "yN2mNNyM3dIKM2gPMW1dSyS2mPNyM3dIKMgPjMyP3dLNPgSjP2gSOdSjV2gUQdUjXW12mWWW1m"
  "KVmKS37018F70U2jNIgL2jNIgN2jLGgK2jLGgM2jNIgL2jNIgOS37028000jDW1dDgDW1jIdI4"
  "gNSXY6dWY!WYW2gUP4d!PPUgV6dUV!UVU2gSN4d!NNSOeTOLHC@VQNJEBXTNLHBZWPNKDP0",
  "S81000000g=Ad==!===!===g!2d==g=2d==7g!8;8;<=Ad==!===!===g!6d==88882g!8S090"  
  "000008d!KKDD??8ZYS81000000g=Ad==!===!===g!2d;=g;Ad;;!;;;!;;;g!2d9;P1g=Ad=="
  "!===!===g!2d;=g@Ad@@!@@@!@@@g!2d>@6iCCCEEE\221GYgBP7Yg@P7YgBP3YgCP3YgDP7Yg"
  "=P7Yg;P7Yg<P3Yg>P3S090000004dKKKKgDAdK?DK!DK!??Q0",
  "YS390081103g!'-2d''g'2d''g-2d''g'2d-'g-6d''''''g-2d--P1Y3g!'-2d''g'2d''g-2"
 "d''g'2d-'g-6d''''''g-2d--P3Y3g!'-2d''g'2d''g-2d''g'2d-'g-6d''''''g-2d--P3P0" 
}; /* This data is indeed extracted (and converted) from the game's ROM. */ 
static const double tick_factor = (44100/60)*2.5/4.0;
static const double freqmul = (440.0)/(std::pow(2.0, 'Q'/12.0)) / 44100.0;
/* 'Q' = A3 (440 Hz). See the table in http://tasvideos.org/forum/p/222583#222583 . */
static class Decoder
{
    unsigned chno, length, n_notes, loopcount, shape,vib, remticks, remwait, remdecay, voltick;
    const char* cur, *A[2];
    double hz, pos, decaypower;
public:
    Decoder(int ch)
      : chno(ch), length(0), n_notes(0), loopcount(0), shape(0),vib(0), remticks(0),
        remwait(0), remdecay(0), voltick(0), cur(channels[ch]), pos(chno*0.2)
    {
    }
    double Tick() // Synthesize the waveform, read more song if necessary   
    {
        static int dutytables[4] = {1,2,4,6}, noise=1<<14;
        while(!remticks) Read();
        if(remwait > 0) { --remwait; return 0.5; } else { --remticks; ++voltick; }
        double hztmp = vib ? hz*(1 + 0.025*std::sin(voltick/700.0)) : hz; // apply vibrato
        pos = std::fmod(pos + hztmp, 1.0);
        int wave=0;  
        if(chno < 2) // square wave
            wave = (pos*8 < dutytables[(shape>>16)&3]) ? 0 : 4;
        else if(chno == 2) // triangle wave
            return (voltick*(3*240/44100.0) >= (shape>>24)) // check volumecurve
                     ? 0.5 : ((pos < 0.5) ? pos*2 : 2*(1-pos));
        else // noise generator
            for(; pos >= 0.005; pos -= 0.005, wave = ((noise+1) & 2))
                 noise = (((noise<<13)^(noise<<14))&16384) | (noise/2); 
        double basevol = (shape>>24) & 15; // base volume from volume envelope
        basevol -= decaypower * (voltick<remdecay ? voltick : remdecay);
        return basevol>0 ? wave * basevol / 92.0 : 0.0;
    }
private:
    void Read() // Read a command from the song data
    {
        const char* begin = cur; int n_notes_orig = n_notes, loop_orig = loopcount;
        if(n_notes > 0) { --n_notes; DoNote(*cur); }
        else switch(*cur)
        {
            case 'Y': case 'Z': A[*cur-'Y'] = cur; break; // loop anchors
            case 'W': remwait = (*++cur - '0') * tick_factor; break; // note delay
            case 'S': std::sscanf(cur+1, "%8X", &shape); cur += 8; // volume & waveform
                      // VVddLLSS (V=volume|env, d=duty, L=curve length, S=curve strength)   
                      voltick = 0; break;
            case 'U': case 'V': vib=*cur-'U'; break;
            case 'P': case 'Q': // loop
                if((cur[1] - '0') != 0 // loopcount 0 means infinite loop
                && (cur[1] - '0') == loopcount++)   //  break loop when
                  { loopcount=0; cur += 1; break; } // the loop count is reached
                cur = A[*cur-'P']; // go to the loop anchor
                break;
            default: // set note length for next N notes
                unsigned char t = *cur;
                if(t >= 'a') n_notes = 1;
                else if(t <= '9') { n_notes = (t - '0') + 0;  ++cur; }
                else              { n_notes = (t - 'A') + 10; ++cur; }
                length = 4*((unsigned char)(*cur) - 'a');
        }
        ++cur;
        /*fprintf(stderr, "n=%d, loop=%d, cur=%.*s\n", n_notes_orig, loop_orig,
            cur<begin ? 3 : cur-begin, begin);*/
    }
    void DoNote(char c) // Setup a note with current length & shape values
    {
        hz = c == '!' ? 0 : std::pow(2.0, c/12.0)*freqmul;
        remticks       = tick_factor*length - remwait;
        voltick        = 0;
        remdecay       = ((shape&0x7F00) >>  8) * (tick_factor) / 4.0;
        decaypower     = ((shape&0xF0)   >>  4) / (tick_factor) * 0.25;
        if(chno==3) { remdecay *= 64; decaypower *= 2; }
        /*fprintf(stderr, "Doing note %u (%g hz), %u ticks (len %u)\n",
            (unsigned)c, hz*44100,
            remticks, length);*/
    }
} Decoders[4] = { Decoder(0), Decoder(1), Decoder(2), Decoder(3) };

int main()
{
    std::fprintf(stdout, "Content-type: audio/mpeg\n\n");

    lame_global_flags* lame = lame_init();
    lame_set_in_samplerate(lame, 44100);  lame_set_num_channels(lame, 1);
    lame_set_out_samplerate(lame, 44100);
    lame_set_quality(lame, 7); lame_set_preset(lame, 40);
    lame_init_params(lame);

    unsigned char mp3buf[8192]; short audio[512];
    for(unsigned a=0;;)
    {
        double d = 0;
        for(int c=0; c<4; ++c) d += Decoders[c].Tick() / 4.0;
        if(d < -1) d = -1; else if(d > 1) d = 1;
        audio[a] = (int)(d*32767);
        if(++a >= sizeof(audio)/sizeof(*audio))
        {
            std::fwrite(mp3buf, 1, lame_encode_buffer(
                lame, audio, audio, a,
                mp3buf, sizeof(mp3buf)), stdout);
            a=0;
        }
    }
    std::fwrite(mp3buf, 1, lame_encode_flush(
        lame, mp3buf, sizeof(mp3buf)), stdout);
    return lame_close(lame);
}
Note: It's not an accurate emulation. Simple trial and error got me only so far with the volume and vibrato curves, and the noise formula. Try also this for the data (one of my favourite NES melodies):
"YS3D009210qCiDeF\201Ce!qAiA2eC9S3D0392108e[[Y![[Y!P1ZYS3D029210iH6eTH!FTHP1Y"
"iJ6eTJ!HTJP1YiH6eTH!FTHP1iJ6eTJ!HTJiG6eTJ!GTJW1S3D039210iWViWUAeWY![!Y!W!WiY"
"7eVW!V!T!W1eRViRe!m^Ui\\W1i[Vi[U7e[YW^!\\!m[e`W1e_Vq_U3e![_W1ebV\201bUiO2e!M"
"W1eMViMU3eK!MW1eMViMU3eHKMiOeM6iRPOMKJe!iO2e!MW1eMViMU3eK!MW1eMViMU3eHKMiOeM"
"6iRPOSVYe[Q0",
"YS37029220c!Ne?OK?OHKDOK?KO?KO>MJ>MFJcCS3D0392202eVVi!2eVVi!P1ZS38029220c!Oe"
"?OK?OHKDOK?KO?KO>MJ>MFJCOeMJ>JM>JM?OK?OHKDOK?KO?KOFe>MJ>MFJCMJ>JM>JcMS380392"
"10g!qWAeWY![!Y!W!WiY7eVW!V!T!W1eRiRe!m^i\\q[7e[YW^!\\!m[e`W1e_q_2e![c_\201bY"
"iK2e!JmJ3eH!JmJ3eDHJOc\\WT`\\WT`\\WT`\\WT`[VSO[VSO8c[VSO[VSOP1Q0",
"S35000000Oe?OK?OHKDOK?KO?KO>MJ>MFJCOeMJ>JM>JM?OK?OHKDOK?KO?KOCe>MJ>MFJCMJ>J8"
"cTTTTQQNNZOe?OK?OHKDOK?KO?KO>MJ>MFJC8eMJ>JM>JMQ34eHKJHiF4e!D!FiF4e!DHJYeDP7Y"
"eGP74eHKJHiF4e!D!FiFKe!DHJDHKDHKDHJCGJCGJOQ0",
"YS38008270e'PGS380084402e//i!2e//i!YS38008270e'PGS380084402e//i!8c//////..YS"
"3D0082702e''S3D008440e/S3D008270e'P0"
Or this (rather good):
"YS3E018410eI2cLLeL2cLL3eLI!2cIIeL2cLL7eLI!PNP!2cLLeL2cLLAeLI!P!N!L!Ni!e!2cNN"
"eN2cNNGeNK!P!N!L!K!I!IPSmRAeI!IPSR!WX!2cLLeL2cLL3eLI!2cIIeL2cLL7eLI!PNP!2cLL"
"eL2cLLAeLI!P!N!L!Ni!e!2cNNeN2cNNGeNK!P!N!L!K!I!IPSmR8eI!IPSR!SW2S3E029010eUi"
"UqUeS4iXUSUe!qSeSmU8ePQPL!LPSyUeS4iXUSUW1eSqS8eSPST!TTWq\\S3F009530VyDeB4iGE"
"DEW2eDqDiDeB4iGEDEW1e@q@3e@BD\201?S3F029530U5eI!IPSmR8eI!IPSR!SW1S3F039530Ve"
"UqUiU3eSU!mX4e\\ZXWqUiU3eSU!mX2eXZiXqW3eWUSm\\3iZXW3eWXWqU8eI!IPSR!SW2S3F029"
"530UeUiUqUeS4iXUSUe!qSeSmU8ePQPL!LPSyUeS4iXUSUW1eSqS8eSPST!TTWm\\S3F0195305e"
"L!LLKiLeU4iSQPN6eN!PP!Pi!DeN!PP!P!NL!LLKiLeU4iSQPN4e!KLKW1eIqI\201!P0",
"YS3A018410e!2cIIeI2cII3eID!2cDDeI2cII7eID!LKL!2cIIeI2cIIAeID!L!K!I!Ki!e!2cKK"
"eK2cKKAeKG!L!K!I!Gi!5eI!IPSmR8eI!IPSRSUP1S3A029210c!W2eUiUqUeS4iXUSUe!qSeSmU"
"8ePQPL!LPSyUeS4iXUSUW1eSqS8eSPST!TTWW2i\\cLS3A009210eI2cLLeL2cLL3eLI!2cIIeL2"
"cLL7eLI!PNP!2cLLeL2cLLAeLI!P!N!L!Ni!e!2cNNeN2cNNAeNK!P!N!L!KS3A029210i!5eI!I"
"PSmR8eI!IP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file, and play it with either mpg123 or mplayer:
./mp3gen > tmp.mp3 &
mplayer tmp.mp3
P.S. I would like to see how this code would look like if written in Haskell. Apparently someone has written an MP3 decoder in Haskell and turned it into a teaching article: http://blog.bjrn.se/2008/10/lets-build-mp3-decoder.html If you're only interested in the music, you can listen to these at:
Post subject: More on mp3 streaming and vintage NES songs
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Related to the above, here is something that I wrote in 1999:
#define _POSIX_SOURCE 1 /* Song length: 55 seconds (24 seconds of loop). */
/*/echo "$0 is not an executable but a C source file. Compiling it now..."
n=`basename $0`;gcc -O2 -Wall -W -pedantic -o /tmp/$n "$0";/tmp/$n $*;exit; */
static char*Title="Selfplayer for /dev/audio (8-bit, µ-law)\n" 
"This file has been compiled from a file created with intgen.";
typedef unsigned char by;char*A,*tmp="nesmusa.$$$",*a0;
static by*z=(by*)"+l=6*mM*JlmZmom+mom)omm5lm8CoZ@Ig3QCDe^l=B*0Z@mJ+NZK*RJ)OJ+"
"5B*7<N+CNJ4LbZ=NZKRRK)O;+5HHF<n51N20Vb:UFZ^UCAY<U?""=a4doK*bJCe5(*(ToM2*2bZ7"
"FV_5AAd<_?AAedmK5XJ9=Ud<OL@lflK2J*Ae5H*4<oMB60b:=CZK2BK)fJ+5T+(<OM2(Bb:;BZKg"
"X*8=Vd2O8@Tf?Sm)+J+4M>\\Cnfb^[o)7:+4m=BE1NZ(Db:1:*So)^Z<4]=J7GBnl*1fI[m)d8+5"
"J72<B+4NJ7<Ybo+(;K)M`+5^J7<6D1NJ7Z`:\\3d+^bm)Cn55(DM<V[(OROAa*Dnm+ZHH)g=45Bn"
"(^oBAYdS_CAedlKo*A)d3^CBa5PM)<6+6BAm*6:*^ABm5@o(bnN2*XHY]TU)+::@l=^*1N:1BRXY"
"K*ZT0mEL<6*3Ncm:*^*TU)+*DBlenN2*FBYm+fHY)m745fR^<NF\\N:PDbZ>0X+RoF?""=5JdK<^"
"_>N2*DZXYK*:+1m5VE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QgD]_LAod@\\gNQcDe5n81<f6:NJ*Bc*R@Z++YH)Kg(5"
"Bd7X_VA1eD\\_NAclXoWA>eB\\[NU56e7\\_NAadd__AAel\\oOAndb_[AU5Ze7<:N7NBd>bJ)]Z"
"+^ZH)cK7f<SO8AWd0_E@]fLS?9ATd>_a);265D:)<*g1N2\\EbZKA[K9fH)WX(5@(D<>NKNJ[Jb*"
"Bob+(*H)Z7)5Z_7<>N1N2\\Eb:d_Z+@d*A]dT_?AAddo+D2VO1add__AAed\\]OMa4e?\\ANecK7"
"BK)8c(5(K7dO\\aNe`\\gO]aLeo\\ALen\\cOe5(K:*",
s[5][65536],l[299999],sn[32]="Logo by NESMusa";
#include <stdio.h>
#include <unistd.h>
static int S,h,OF,PN,d,p=1,r,k,i,a,c,CO,j,x,T=288,f=8000,LS=0,
P[12],H[99],IL[99];FILE*fo;
static int Out(int v){int e=0,s=1,f=0;if(OF)v=128+v/30;else for((s=(v<0))?v=-v
:0;e<8;e++)if((f=((v+32)>>(e+1))-16)<16)break;return fputc(OF?v:~((s<<7)|(e<<4
)|f),fo);}void gn(void){for(f=0;A[1]>='0'&&A[1]<='9';f=f*10+*++A-'0');}int
G(int n){while((k=1<<n)>p)d+=p*(by)((*z++^134)+84),p*=64;PN=d&(k-1);d/=k,p
/=k;return PN;}int main(int C,char**V){if(V)a0=*V;for(P[CO=i=0]=907;++i<12;P[i
]=P[i-1]*89/84);while(--C)if(*(A=*++V)=='-')while(*A&&A[1])
*++A=='r'?gn(),0:*A=='d'?OF=1:*A=='h'?h=1:0;
fprintf(stderr,"%s\n\nUsage:\t %s [options]\n"
"Example: %s\n\t %s -dr22050|esdcat -b -m -r 22050\nOptions:\n"
"\t -d\tPlay in linear format instead & use /dev/dsp if not piped\n"
"\t -r#\tSelect sampling rate in Hz\n\t -h\tThis help\n\n",Title,a0,a0,a0);
if(h)exit(0);for(r=3220,LS=1810,c=4;c--;)for(a=0;a<r;)if((S=G(7))-7)
l[c+8*a+4]=S,l[c+8*a++]=G(6)^63;else for(i=G(10),S=G(8);S--;a++)
l[a*8+4+c]=l[(a-i)*8+4+c],l[a*8+c]=l[(a-i)*8+c];
for(i=IL[0]=IL[1]=32;--i>=0;s[0][i]=(i&24)?170:20)s[1][i]=16*(i<16?i:31-i);
for(i=IL[2]=999;--i>=0;s[2][i]=(a=a*999+1)%200);
if(isatty(fileno(fo=stdout)))fo=fopen(A=OF?"/dev/dsp":
"/dev/audio","wb");if(!fo){perror(A);exit(-1);}a=c=i=sn[29]=0;
for(fprintf(stderr,"Playing built-in song (%s)...\n",sn);;
i<3?i++:((c?c--^Out(S/9):++a>=r?a=LS:(c=f*5/T)),i=S=0)){
x=l[a*8+4+i],j=i?i-1:0;H[i] += P[x%12]<<x/12;
if(IL[j])S += (s[j][((unsigned)H[i]/f)%IL[j]]-128)*l[a*8+i];}}
And another:
#define _POSIX_SOURCE 1 /* Song length: 94 seconds (89 seconds of loop). */
/* This source was optimized with Findbest of the Bisqwit's Midtools pack */
/*/echo "$0 is not an executable but a C source file. Compiling it now..."
n=`basename $0`;gcc -O2 -Wall -W -pedantic -o /tmp/$n "$0";/tmp/$n $*;exit; */
static char*Title="NES-S3M player for /dev/audio (8-bit, µ-law)\n"
"This file has been compiled from a file created with intgen.";
typedef unsigned char by;char*A,*In,*tmp="nesmusa.$$$",*a0;
static by*z=(by*)"1v;FLTehJaWk1``f2:dwP2J3l>XEAKRn<eAJSl>YECkoF=LdSRWk@ioFXve"
"SdWkHtoF@we3iWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhw"
"e3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFh"
"we3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoFhwe3vWkPwoF"
"hwe3vWkPwoFhwe3vWkPwoFhwe3vWkPw_nLPwL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v<k9@afjMd_0=Hwf>d?09OwnMPRu0XHow:n=YRu0"
"XH_2LnwPRUXtKo8An1jgUPvK?XRngYRUQGIoj;Y>d?PYLGn30MZEk1h8mgu0tK?8AYFBU\\j8mBZ"
"]L;YNBu\\j9mG[3N?dFHe`joV1BHe`JQm2[?NGnWPRU:dHO>:nERSu2HH_?b`FPU0k0n2d=H;`NP"
"u0k1ng[3O?fFTehJamR[=OGfVTuK_2:nwgRU@M3",
o[256],w[256][64],NN[8],s[5][65536],l[299999],
sn[32]="DrWily Alpha by NESMusa";
#include <stdio.h>
#include <unistd.h>
static int ss,m,IN,IV[99],IP[256],PP[100],b,M,I,D[99],Bxx,Cxx,B,Ss,CP,
At[256][64],Np=0,S=SEEK_SET,h,OF,PN,d,p=1,r,k,i,a,c,CO,j,x,T=250,f=8000,LS=0,
P[12],H[99],IL[99];FILE*fo,*fi;
#define rw(a) a=fgetc(fi),a|=fgetc(fi)<<8
static int Out(int v){int e=0,s=1,f=0;if(OF)v=128+v/30;else for((s=(v<0))?v=-v
:0;e<8;e++)if((f=((v+32)>>(e+1))-16)<16)break;return fputc(OF?v:~((s<<7)|(e<<4
)|f),fo);}void gn(void){for(f=0;A[1]>='0'&&A[1]<='9';f=f*10+*++A-'0');}int
G(int n){while((k=1<<n)>p)d+=p*(by)((*z++^4)-52),p*=64;PN=d&(k-1);d/=k,p/=k;
return PN;}int main(int C,char**V){
if(V)fi=stdin,a0=*V;for(P[CO=a=i=C?0:(fseek(fo,0,SEEK_END),r=ftell(fo)/8,rewind(fo),
fread(l,8,r,fo),fclose(fo),remove(tmp),z=(by*)In,main(-1,0))]=907;++i<12;P[i
]=P[i-1]*89/84);if(C<0){if(isatty(fileno(fo=stdout)))fo=fopen(A=OF?"/dev/dsp":
"/dev/audio","wb");if(!fo){perror(A);exit(-1);}a=c=i=sn[29]=0;
for(fprintf(stderr,"Playing %s (%s)...\n",*z-'*'?z:z+1,sn);;
i<3?i++:((c?c--^Out(S/9):++a>=r?a=LS:(c=f*5/T)),i=S=0)){
x=l[a*8+4+i],j=i?i-1:0;H[i] += (D[j]?D[j]*P[x%12]/14500:P[x%12])<<x/12;
if(IL[j])S += (s[j][((unsigned)H[i]/f)%IL[j]]-128)*l[a*8+i];}}
while(--C)if(*(A=*++V)-'-')In=A;else if(A[1])while(*A&&A[1])
*++A=='r'?gn(),0:*A=='d'?OF=1:*A=='h'?h=1:0;else In="*stdin";
if(!In){fprintf(stderr,"%s\n\nUsage:\t %s [options] nesfile.s3m\n"
"Example: %s mman3_d2.s3m\n\t %s -dr22050 cv2b.s3m|esdcat "
"-b -m -r 22050\nOptions:\n"
"\t -d\tPlay in linear format instead & use /dev/dsp if not piped\n"
"\t -r#\tSelect sampling rate in Hz\n\t -h\tThis help\n\n",Title,a0,a0,a0);
if(h)exit(0);for(r=4704,LS=224,c=4;c--;)for(a=0;a<r;)if((S=G(7))-118)
l[c+8*a+4]=S,l[c+8*a++]=G(6)^63;else for(i=G(9),S=G(6);S--;a++)
l[a*8+4+c]=l[(a-i)*8+4+c],l[a*8+c]=l[(a-i)*8+c];
for(i=IL[0]=IL[1]=32;--i>=0;s[0][i]=(i&24)?170:20)s[1][i]=16*(i<16?i:31-i);
for(i=IL[2]=999;--i>=0;s[2][i]=(a=a*999+1)%200);z=(by*)"built-in song";
main(i,0);}if(*In-'*')fi=fopen(In,"rb");if(!fi||!(fo=fopen(tmp,"wb+")))
{perror(fi?tmp:In);return-1;}fread(sn,1,32,fi);rw(m);rw(IN);
rw(PN);fseek(fi,49,S);x=fgetc(fi);T=fgetc(fi)*2;fseek(fi,0x60,S);
fread(o,m,1,fi);for(i=0;i<IN;i++)rw(IP[i]);for(i=0;i<PN;i++)rw(PP[i]);
for(i=0;i<IN;i++)fseek(fi,IP[i]*16+13,S),fgetc(fi),rw(LS),rw(IL[i]),rw(j),
fseek(fi,8,SEEK_CUR),IV[i]=fgetc(fi),fseek(fi,3,SEEK_CUR),
rw(D[i]),fseek(fi,LS*16,S),fread(s[i],1,IL[i],fi);
for(;;){if(CO>=m)main(0,V);if((CP=o[CO])-254){fseek(fi,PP[CP]*16,S);
rw(i);if(!i)PP[CP]=0;if(PP[CP])fread(z=s[4],i-=2,1,fi);for(r=0;r<64;r++){if(!r)ss=1;
a?0:w[CO][r]?(LS=At[CO][r]),main(0,V):(At[CO][r]=ftell(fo)/8,(w[CO][r]=1));
Bxx=Cxx=-1,Ss=ss,j=B=ss=0;if(PP[CP])while((b=*z++)-(M=I=0)){
if(b&32){if(!a){if(*z<254)NN[(b&3)+4]=*z%16+12*(*z/16);else
if(*z==254)NN[b&3]=0;if(z[1]&&*z!=254)NN[b&3]=IV[z[1]-1];}z+=2;}
if(b&64){if(!a)NN[b&3]=*z;z++;}if(b&128){M=*z++;I=*z++;}
if(M==1&&!a)x=I;M==2?Bxx=I:M==3?Cxx=I:M==4?ss=1:0;
if(M==19){if(I/16==11)*((B=I&15)?&ss:&Ss)=1;if(I/16==14)j=I&15;}}if(a)
a--;else{if(Ss)Np=ftell(fo);for(i=(j+1)*x;i;i--)fwrite(NN,1,8,fo);
if(B){c=ftell(fo)-Np;fseek(fo,Np,S);fread(l,1,c,fo);
fseek(fo,Np+c,S);for(i=B;i;i--)fwrite(l,1,c,fo);}
if(Bxx>=0){CO=Bxx-1;if(Cxx<0)break;}
if(Cxx>=0){a=(Cxx&15)+10*(Cxx/16);break;}}}}CO++;}}
Running example:
./program -dr44100|aplay - -fcd -c1 -fU8
Thus the technology improves! :) I installed them also here:When I wrote these, I was not aware of the fact that NES has different square wave types. (But iNES didn't write the distinction to its .snd files either.) These are also weirdly transponed (play at wrong pitch).
Post subject: QBasic live programming
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
The first time ever that I do live* programming as a performance. http://www.youtube.com/watch?v=TUa5HJUebEA I seem to remember that someone once, many years ago, said something to me about this. Never thought I would actually do it. *) This was only live for the fact that I recorded it in real time without re-rerecording or cuts; it was rehearsed.
Joined: 10/3/2005
Posts: 1332
I was more surprised by the fact that QBasic was doing code folding and some kind of prettifying. Maybe I should do Pong in Emacs + Common Lisp. :p
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Dromiceius wrote:
I was more surprised by the fact that QBasic was doing code folding and some kind of prettifying.
QBasic** stores the program internally in a tokenized format for fast interpretation and small memory use, and as part of it, all redundant whitespace within* legal statements is deleted. For rendering, the statement is reconstructed with built-in prettifying rules. *) Excluding whitespace that precedes an apostrophe comment and indentation preceding the statement. (Whitespace in DATA or within string constants is not redundant.) **) GW-BASIC, MBASIC and BASICA, QBasic's predecessors, did the same, except they preserved whitespace. Identifiers were converted to uppercase. I think PET Basic / C64 Basic, branched from the same development tree, did that too.
nfq
Player (94)
Joined: 5/10/2005
Posts: 1204
Bisqwit wrote:
[CO=a=i=C?0:(fseek(fo,0,SEEK_END),r=ftell(fo)/8,rewind(fo), fread(l,8,r,fo),fclose(fo),remove(tmp),z=(by*)In,main(-1,0))]=907;++i<12;P[i ]=P[i-1]*89/84);if(C<0){if(isatty(fileno(fo=stdout)))fo=fopen(A=OF?"/dev/dsp": "/dev/audio","wb");if(!fo){perror(A);exit(-1);}a=c=i=sn[29]=0; for(fprintf(stderr,"Playing %s (
I'm surprised anyone can understand anything about that. You programmers must have a higher IQ than Einstein. All I see is random words, numbers and letters. I watched your youtube video too, and you write really fast. Do you use a normal "qwerty" keyboard layout?
Joined: 10/3/2005
Posts: 1332
Bisqwit wrote:
QBasic** stores the program internally in a tokenized format for fast interpretation and small memory use, and as part of it, all redundant whitespace within* legal statements is deleted. For rendering, the statement is reconstructed with built-in prettifying rules.
Yeah— now that you mention it, I remember a certain TDWTF article that touched on an interesting application of QBasic's tokenization. I'm just surprised. I logged quite a few hours writing QBasic in junior high, but remember nothing like that. Then again, I never learned to use TYPE, DIM, or SUB properly, either. >_>
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
nfq wrote:
Bisqwit wrote:
[CO=a=i=C?0:(fseek(fo,0,SEEK_END),r=ftell(fo)/8,rewind(fo), fread(l,8,r,fo),fclose(fo),remove(tmp),z=(by*)In,main(-1,0))]=907;++i<12;P[i ]=P[i-1]*89/84);if(C<0){if(isatty(fileno(fo=stdout)))fo=fopen(A=OF?"/dev/dsp": "/dev/audio","wb");if(!fo){perror(A);exit(-1);}a=c=i=sn[29]=0; for(fprintf(stderr,"Playing %s (
I'm surprised anyone can understand anything about that. You programmers must have a higher IQ than Einstein. All I see is random words, numbers and letters. I watched your youtube video too, and you write really fast. Do you use a normal "qwerty" keyboard layout?
that code was not written with good style; judicious use of newlines and indentation yields this:
#define _POSIX_SOURCE 1 /* Song length: 55 seconds (24 seconds of loop). */
/*/echo "$0 is not an executable but a C source file. Compiling it now..."
n=`basename $0`;gcc -O2 -Wall -W -pedantic -o /tmp/$n "$0";/tmp/$n $*;exit; */
static char*Title="Selfplayer for /dev/audio (8-bit, µ-law)\n"
"This file has been compiled from a file created with intgen.";
typedef unsigned char by;
char*A,*tmp="nesmusa.$$$",*a0;
static by*z=(by*)"+l=6*mM*JlmZmom+mom)omm5lm8CoZ@Ig3QCDe^l=B*0Z@mJ+NZK*RJ)OJ+"
"5B*7<N+CNJ4LbZ=NZKRRK)O;+5HHF<n51N20Vb:UFZ^UCAY<U?""=a4doK*bJCe5(*(ToM2*2bZ7"
"FV_5AAd<_?AAedmK5XJ9=Ud<OL@lflK2J*Ae5H*4<oMB60b:=CZK2BK)fJ+5T+(<OM2(Bb:;BZKg"
"X*8=Vd2O8@Tf?Sm)+J+4M>\\Cnfb^[o)7:+4m=BE1NZ(Db:1:*So)^Z<4]=J7GBnl*1fI[m)d8+5"
"J72<B+4NJ7<Ybo+(;K)M`+5^J7<6D1NJ7Z`:\\3d+^bm)Cn55(DM<V[(OROAa*Dnm+ZHH)g=45Bn"
"(^oBAYdS_CAedlKo*A)d3^CBa5PM)<6+6BAm*6:*^ABm5@o(bnN2*XHY]TU)+::@l=^*1N:1BRXY"
"K*ZT0mEL<6*3Ncm:*^*TU)+*DBlenN2*FBYm+fHY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b:cCZ+_AK);b(]<MOl@o"
"g`QeE]]LM?m@lgnQa)DJ75:X7@Od`^g@QgD]_LAod@\\gNQcDe5n81<f6:NJ*Bc*R@Z++YH)Kg(5"
"Bd7X_VA1eD\\_NAclXoWA>eB\\[NU56e7\\_NAadd__AAel\\oOAndb_[AU5Ze7<:N7NBd>bJ)]Z"
"+^ZH)cK7f<SO8AWd0_E@]fLS?9ATd>_a);265D:)<*g1N2\\EbZKA[K9fH)WX(5@(D<>NKNJ[Jb*"
"Bob+(*H)Z7)5Z_7<>N1N2\\Eb:d_Z+@d*A]dT_?AAddo+D2VO1add__AAed\\]OMa4e?\\ANecK7"
"BK)8c(5(K7dO\\aNe`\\gO]aLeo\\ALen\\cOe5(K:*",
s[5][65536],l[299999],sn[32]="Logo by NESMusa";
#include <stdio.h>
#include <unistd.h>
static int S,h,OF,PN,d,p=1,r,k,i,a,c,CO,j,x,T=288,f=8000,LS=0,
P[12],H[99],IL[99];
FILE*fo;
static int Out(int v){
 int e=0,s=1,f=0;
 if(OF)
  v=128+v/30;
 else
  for((s=(v<0))?v=-v:0;e<8;e++)
   if((f=((v+32)>>(e+1))-16)<16)
    break;
 return fputc(OF?v:~((s<<7)|(e<<4)|f),fo);
}
void gn(void){
 for(f=0;A[1]>='0'&&A[1]<='9';f=f*10+*++A-'0');
}
int G(int n){
 while((k=1<<n)>p)
  d+=p*(by)((*z++^134)+84),p*=64;
 PN=d&(k-1);
 d/=k,p/=k;
 return PN;
}
int main(int C,char**V){
 if(V)a0=*V;
 for(P[CO=i=0]=907;++i<12;P[i]=P[i-1]*89/84);
 while(--C)
  if(*(A=*++V)=='-')
   while(*A&&A[1])
    *++A=='r'?gn(),0:*A=='d'?OF=1:*A=='h'?h=1:0;
 fprintf(stderr,"%s\n\nUsage:\t %s [options]\n"
         "Example: %s\n\t %s -dr22050|esdcat -b -m -r 22050\nOptions:\n"
         "\t -d\tPlay in linear format instead & use /dev/dsp if not piped\n"
         "\t -r#\tSelect sampling rate in Hz\n\t -h\tThis help\n\n",
         Title,a0,a0,a0);
 if(h)
  exit(0);
 for(r=3220,LS=1810,c=4;c--;)
  for(a=0;a<r;)
   if((S=G(7))-7)
    l[c+8*a+4]=S,l[c+8*a++]=G(6)^63;
   else
    for(i=G(10),S=G(8);S--;a++)
     l[a*8+4+c]=l[(a-i)*8+4+c],l[a*8+c]=l[(a-i)*8+c];
 for(i=IL[0]=IL[1]=32;--i>=0;s[0][i]=(i&24)?170:20)
  s[1][i]=16*(i<16?i:31-i);
 for(i=IL[2]=999;--i>=0;s[2][i]=(a=a*999+1)%200);
 if(isatty(fileno(fo=stdout)))
  fo=fopen(A=OF?"/dev/dsp":"/dev/audio","wb");
 if(!fo){
  perror(A);
  exit(-1);
 }
 a=c=i=sn[29]=0;
 for(fprintf(stderr,"Playing built-in song (%s)...\n",sn);;
     i<3?i++:((c?c--^Out(S/9):++a>=r?a=LS:(c=f*5/T)),i=S=0)){
  x=l[a*8+4+i],j=i?i-1:0;H[i] += P[x%12]<<x/12;
  if(IL[j])
   S += (s[j][((unsigned)H[i]/f)%IL[j]]-128)*l[a*8+i];
 }
}
It's still hard to understand because of the exploitation of non-obvious uses of operators like dereference, assignment, and ternary conditional, but this is easier to read at least.
i imgur com/QiCaaH8 png