16
Community Contests / Code Golf - The Reboot #8
« on: July 20, 2015, 04:12:15 am »
Hey, it's me again, Juju, hosting the eighth iteration of Code Golf: The Reboot. This week, the output will be... sound. Yep, you heard right. Pun intended.
The assignment today is a simple A4 sine wave, sample rate of 8000 Hz, in raw wave format. But first, you'll want to understand at least a little how to make one. First, know you'll have to output 8000 bytes to make one second, but you don't have to output all that in exactly one second. To make a simple A4 (frequency of 440 Hz), look at the graph for sin(x). Map the y from [-1,1] to [0,255] (don't forget to round it to remove the decimals!) and try to fit the wave you get ([0,2π[) 440 times in those 8000 bytes. Then just output the bytes you just generated, no header or anything. On calc, if you can output those bytes through the link port with the timing, that would be great (no Freq(), you Axe people!), otherwise, you can just output a list with the 999 first numbers you get (makes for about 1/8 of a second) or an infinite loop that disps the numbers (if you output on screen, you don't need the timing), or whatever the easiest for you. On PC, you can output the raw bytes in an infinite loop or the 8000 first ones (makes for one second) so I can pipe them through aplay.
tl;dr you have to output a very specific sin() function with specific parameters. Should be simple enough.
The rules are still the same, if you have any questions, please ask. Have fun!
Ranking
@3298 - SysRPL - 53 bytes
The assignment today is a simple A4 sine wave, sample rate of 8000 Hz, in raw wave format. But first, you'll want to understand at least a little how to make one. First, know you'll have to output 8000 bytes to make one second, but you don't have to output all that in exactly one second. To make a simple A4 (frequency of 440 Hz), look at the graph for sin(x). Map the y from [-1,1] to [0,255] (don't forget to round it to remove the decimals!) and try to fit the wave you get ([0,2π[) 440 times in those 8000 bytes. Then just output the bytes you just generated, no header or anything. On calc, if you can output those bytes through the link port with the timing, that would be great (no Freq(), you Axe people!), otherwise, you can just output a list with the 999 first numbers you get (makes for about 1/8 of a second) or an infinite loop that disps the numbers (if you output on screen, you don't need the timing), or whatever the easiest for you. On PC, you can output the raw bytes in an infinite loop or the 8000 first ones (makes for one second) so I can pipe them through aplay.
tl;dr you have to output a very specific sin() function with specific parameters. Should be simple enough.
The rules are still the same, if you have any questions, please ask. Have fun!
Ranking
@3298 - SysRPL - 53 bytes