News for hackers. Stuff that matters.
Re:Generate raw WAV output by hooking malloc and read by ericHosick on Monday July 28, 2014 @11:06PM (#8100512)
Re:Generate raw WAV output by hooking malloc and read by thegeomaster on Tuesday July 29, 2014 @02:37AM (#8100977)

    void* read( int fd, void * data, size_t count)
    {
      ...
      gen_square_wave( 44100 , CLAMP(count, 20, 20000 ), CLAMP( sizeof(data), 100 , 1700), 0.7 );
I don't get it, isn't sizeof(data) always the same, and usually either 4 or 8?
Re:Generate raw WAV output by hooking malloc and read by fredophile on Tuesday July 29, 2014 @10:48AM (#8102473)
It's always the same for your compiler. Using sizeof improves the portability of the code. Because sizeof is calculated at compile time it doesn't make the code any less efficient.

We often think about pointers as being 4 bytes but that isn't necessarily the case. How would a 32 bit pointer map to the addressable memory of 64 bit hardware?

Re:Generate raw WAV output by hooking malloc and read by reubenmorais on Tuesday July 29, 2014 @03:55PM (#8104588)
I think his point is more about clamping the value than about using sizeof. It indicates the author expected that value to vary, but it doesn't.
Re:Generate raw WAV output by hooking malloc and read by fredophile on Tuesday July 29, 2014 @08:11PM (#8105722)
Depending on your application I can see where you might still want to clamp the result. However, I think you're right in this case since the clamped range doesn't make much sense here.
Re:Generate raw WAV output by hooking malloc and read by taejo on Tuesday July 29, 2014 @03:31AM (#8101089)
Since sizeof is a compile-time construct, it's always always the same (in C; in C++ there are templates to consider)
Re:Generate raw WAV output by hooking malloc and read by nitrogen on Tuesday July 29, 2014 @10:34AM (#8102414)
I haven't read the code, but it looks like this is a bug, or at least superfluous
Re:Generate raw WAV output by hooking malloc and read by bitwize on Tuesday July 29, 2014 @10:42AM (#8102446)
Yeah, the result of the sizeof operator always compiles to a constant. It may vary from system to system and compiler to compiler, but it's written into the executable as a constant.
Re:Generate raw WAV output by hooking malloc and read by ejr on Tuesday July 29, 2014 @11:49AM (#8102879)
Re:Generate raw WAV output by hooking malloc and read by pronoiac on Tuesday July 29, 2014 @02:55AM (#8101009)
It sounds like when I piped /dev/random to a midi device. (Or was it /dev/urandom and TiMidity++?)

It was like demos; I would be stunned at the emergent complexity and compactness, and it would only elicit shrugs from friends.

Re:Generate raw WAV output by hooking malloc and read by ibisum on Tuesday July 29, 2014 @07:29AM (#8101660)
I'm reminded of some of my favourite C 1-liners for synthesis:

    main(t){
        for(t=0;;t++)
            putchar(t*(((t>>12)|(t>>8))&(63&(t>>4))));
            //putchar(t>>7|t%45)&(t>>8|t%35)&(t>>11|t%20); // try this too!
    }
.. there's a whole world of 1-liners for synthesis out there, and some of them, frankly, are astounding. Sound is such a beautiful way to understand math ..
Re:Generate raw WAV output by hooking malloc and read by akx on Tuesday July 29, 2014 @09:18AM (#8102027)
These are called bytebeat nowadays.

See viznut's (seminal) intro to the genre.

http://countercomplex.blogspot.fi/2011/10/algorithmic-sympho...

https://www.youtube.com/watch?v=GtQdIYUtAHg

Re:Generate raw WAV output by hooking malloc and read by ibisum on Thursday July 31, 2014 @05:10AM (#8113135)
Thanks for the update - bytebeat sounds like something thats a lot more searchable than 'c one-liners that generate sound' .. ;)

Great stuff, eh?

Re:Generate raw WAV output by hooking malloc and read by Newtie on Tuesday July 29, 2014 @12:01PM (#8102947)
Very cool, though I'm having trouble getting any audio out trying it myself. I can build & LD_PRELOAD the .so fine, but the pipe to aplay produces jibberish in the terminal without audio.
Re:Generate raw WAV output by hooking malloc and read by cowpewter on Monday July 28, 2014 @11:11PM (#8100522)
Reminds me of when I was a kid, and I had a Tandy CoCo and a tape recorder deck that was the only way to save any programs you wrote on it. I tried playing the data tape a few times.
Re:Generate raw WAV output by hooking malloc and read by mikecsh on Tuesday July 29, 2014 @03:23AM (#8101072)
Yes! I used to have an Amstrad CPC 464 with a tape deck and it would play the tape through its internal speaker as it was loading a program into memory. The amount of time sat around watching screens like this:

https://www.youtube.com/watch?v=OvChkOHgDIo

Re:Generate raw WAV output by hooking malloc and read by acannon828 on Monday July 28, 2014 @11:02PM (#8100498)
This seems cool, though I don't entirely understand it. "Generates raw WAV output by hooking malloc() and read()." What does that mean exactly?
Re:Generate raw WAV output by hooking malloc and read by delinka on Monday July 28, 2014 @11:13PM (#8100528)
It uses hooking to intercept calls to malloc() and read(), calls the real functions, generates a square wave whose frequency is based on the size of the operation, dumps the generated sound data to WAV, returns the output of the real function calls.
Re:Generate raw WAV output by hooking malloc and read by viciousplant on Monday July 28, 2014 @09:37PM (#8100289)
transform logic to sound? hmm interesting idea
Re:Generate raw WAV output by hooking malloc and read by andrewchambers on Monday July 28, 2014 @11:35PM (#8100566)
memory allocations to sound.
Re:Generate raw WAV output by hooking malloc and read by niix on Monday July 28, 2014 @11:05PM (#8100511)
Heh really cool
Re:Generate raw WAV output by hooking malloc and read by andyzweb on Monday July 28, 2014 @09:07PM (#8100193)
oh wow this is fun
Re:Generate raw WAV output by hooking malloc and read by MBCook on Monday July 28, 2014 @10:45PM (#8100458)
To the tune of Sound of Silence by Simon & Garfunkel:

    Hello malloc() my old friend,
    I've come for mem'ry once again,
    Because a pointer silently creeping,
    Filled buffer that I was keeping,
    And the signal that I trapped was a bus error.
    Didn't care.
    Because I still... have malloc()

    There were pages that I missed.
    My OS had sent them to disk.
    Try my best to not hit swap,
    Looking for data I could safely drop,
    I compressed some bits that I kept stored in place
    Freed some space.
    But then I still... used malloc().