36
3
Introduction
Some days ago I needed a metronome for something. I had none available so I downloaded an app from the App Store. The app had a size of 71 MB!!!
71 MB for making tic-toc...?!
So code-golf came into my mind and I was wondering if some of you guys could improve this.
Challenge
Golf some code that outputs some sound. It's pretty irrelevant what kind of sound. If required create some sound file... but a System beep will do the job as well. (Here is some sound I created... nothing special.)
Input: The beats per minute the metronome outputs.
Example
This is a non-golfed Java-version! It's just to show you the task.
public class Metronome {
public static void main(String[] args) throws InterruptedException {
int bpm = Integer.valueOf(args[0]);
int interval = 60000 / bpm;
while(true) {
java.awt.Toolkit.getDefaultToolkit().beep();
// or start playing the sound
Thread.sleep(interval);
System.out.println("Beep!");
}
}
}
Rules
You may not use external libaries, only tools of the language itself are allowed.
Only the bytes of the source code count... not the sound file.
This is code-golf, so the submission with the least amount of bytes wins!
EDIT:
Example output: So something like this would be the output for 120 bps: link
1Can you add a few examples for I/O (record some sound and upload it, post the links here)? – Addison Crump – 2016-01-23T14:25:53.780
What kind of I/O example do you mean? P.S. There is already some sound I created, look under Challange ;) – PEAR – 2016-01-23T14:28:47.553
Oh, I know about that. It's just that we typically show a few input/output examples. – Addison Crump – 2016-01-23T14:29:51.980
Oh, ok... I'll edit the question. – PEAR – 2016-01-23T14:31:12.317
2Question: when you say "external libraries", does that include the libraries that are suggested with the language? (I won't use this, but an example is in Vitsy wherein I can access shell or JS (but JS is builtin)) – Addison Crump – 2016-01-23T17:48:15.597
Is the answer allowed to run out of memory or blow the call stack at some point? – Martin Ender – 2016-01-23T18:33:01.993
Are command line options for an interpreter counted / allowed? – ChatterOne – 2016-01-23T18:43:30.767
Can we use external audio sounds? – Downgoat – 2016-01-23T18:47:20.763
@DOWNGOAT: Of course you can! You can use the file I uploaded (see question) or use another sound. This is not important. – PEAR – 2016-01-23T18:51:30.987
@ChatterOne Yes. Count how many bytes you need to add to the invocation which is usually between 1 and 3 bytes for single-character flags.
– Martin Ender – 2016-01-23T18:52:00.963@ETHproductions: Yes, you can. But it's even shorter if you download and rename them, isn't it? – PEAR – 2016-01-23T18:55:30.593
Can we get the input speed from a file? – Downgoat – 2016-01-23T19:06:40.230
@Doᴡɴɢᴏᴀᴛ: Yes, I did not specify the input. – PEAR – 2016-01-23T19:08:19.470
3
Can you add a leaderboard snippet in?
– Addison Crump – 2016-01-23T21:53:08.4001I suspect the majority of that app you downloaded is pretty graphics and sound effects. It's like those flashlight apps that do nothing but turn the screen all white but still manage to somehow use up tens of MB... – Darrel Hoffman – 2016-01-24T15:13:48.380
1What's the requirement on accuracy? In your sample, both
beep()
and console output aren't exactly instant IIRC. Neithersleep()
is known for beeing accurate. – Num Lock – 2016-01-25T09:04:49.290