Get this song stuck in my head

-5

Your challenge is to play these notes (speakers or to a sound file) in this order:

C
A
F
G

Specifically, you must play these frequencies one after the other:

261.63 Hz
220.00 Hz
174.61 Hz
196.00 Hz

with an allowed error of +/- 5 Hz.

If you output to a file, please use a .ogg or .mp3, or raw bytes that can be fed to aplay. The notes must last at least 100ms, and less than 5s. They must be played for the same duration.

No, this is not a converter from notes to a sound file! You just need to play some frequencies!

programmer5000

Posted 2017-05-16T15:45:56.117

Reputation: 7 828

Question was closed 2017-05-24T04:56:53.413

8

Please consider using the Sandbox in the future to get feedback on your challenges before posting them to the main site.

– Mego – 2017-05-16T15:57:18.553

2Part of the problem is probably that I had to look up chord, but even now that I did, I'm not sure how to translate chords into something a computer can understand, how C,Am,F,G is a transposition of F,Dm,A#,C, what exactly you mean by in any format, and which methods of "playing" are acceptable. – Dennis – 2017-05-16T15:58:25.770

2>

  • Not everybody knows music. I am aware of what you mean, having played piano for 3 years. Anybody who hasn't played instruments/isn't aware of that is kinda lost. You'd need a quick explanation of what a chord is/how to transpose things. 2. "Play the notes" is kinda unclear. Do you mean output a sound file?
  • < – Rɪᴋᴇʀ – 2017-05-16T16:01:01.647

    Also, define chord? Are you saying a standard 3 note chord? Can it be a separated chord? – Rɪᴋᴇʀ – 2017-05-16T16:04:35.757

    @programmer5000 no, that's not what I mean by separated chord. For example, can we play C7 Am F7 G? What specific notes do the chords need to contain? Or can they be anything, as long as it's that base chord? – Rɪᴋᴇʀ – 2017-05-16T16:10:39.823

    3

    This seems like a simpler version of https://codegolf.stackexchange.com/q/11463/194 or https://codegolf.stackexchange.com/q/272/194 and I'm not sure what it adds to the site.

    – Peter Taylor – 2017-05-16T16:15:54.570

    4Play how? One after the other or all at once? For how long? Once or in a loop? Are these the only allowed frequencies? If not, which ones are allowed? Which formats for "sound files" are acceptable? – Dennis – 2017-05-16T17:55:52.647

    2The challenge should contain all of the necessary information needed to craft a solution. Linking to another website that explains basic music theory is not acceptable, because of link rot. Challenges need to be self-contained, and explaining basic music theory (notes, frequencies, and chords) is really not difficult. – Mego – 2017-05-16T17:57:08.413

    Also, what sound quality? Would a square wave do? – John Dvorak – 2017-05-16T17:57:16.647

    @JanDvorak a square wave is fine. – programmer5000 – 2017-05-16T17:57:57.010

    @Dennis is that better? – programmer5000 – 2017-05-16T17:58:30.740

    You specified the spacing between notes, but not how long each of them should be. – John Dvorak – 2017-05-16T17:59:11.050

    @JanDvorak It is ±10 Hz. – programmer5000 – 2017-05-16T18:06:37.023

    1@programmer5000 put that in the question... – John Dvorak – 2017-05-16T18:07:10.367

    @JanDvorak done. – programmer5000 – 2017-05-16T18:07:22.727

    10 Hz seems like a very large variance to allow. That's nearly a half step either direction for each note. – Mego – 2017-05-16T18:08:59.970

    @Mego now it's 5Hz. – programmer5000 – 2017-05-16T18:09:52.497

    You might do better following this format https://codegolf.meta.stackexchange.com/a/1512/68029

    – Notts90 supports Monica – 2017-05-16T18:35:35.347

    @Notts90 that's not going to help. His problem is underspecification, not bad formatting. – Rɪᴋᴇʀ – 2017-05-16T18:53:46.347

    @Riker What is underspecifyed? – programmer5000 – 2017-05-16T18:54:51.527

    2This turned out to be a dupe. ("Output a sound of a certain frequency") – Rɪᴋᴇʀ – 2017-05-16T18:58:06.233

    @Riker I found the template and other FAQ bits helpful in making my question complete. Of course sandbox too. – Notts90 supports Monica – 2017-05-16T19:04:16.793

    3Having read the history, I think it's sad what happened. You wanted chords, but nonmusicians didn't get it. Then you said it was OK to do either chords or just root notes (but chords need more code so why do them?) and nonmusicians were confused by transposition. Finally you restricted to one key, but tried to be flexible on octaves (but didn't explain that meant frequencies could be multiplied by powers of 2) so you were forced to restrict to a single octave. It's a good question but if it had been sandboxed it might've been received better in a form closer to your original intention. – Level River St – 2017-05-16T22:07:32.383

    Back in the early days of the site, when popularity contests were allowed I wrote this https://codegolf.stackexchange.com/a/21690/15599 . It has a C G A F progression with broken fifth chords: (CG)8 (GD)8 (AE)8 (FC)8. There's no need to play the middle note of the chord: your brain interprets them as major or minor due to context.

    – Level River St – 2017-05-16T22:23:31.520

    Answers

    3

    JS, 254 bytes

    Gets annoying after a while. Weird things happen when used in multiple tabs.

    c=new AudioContext();x=c.createOscillator();x.type="sine";x.frequency.value=261.63;x.start(0);y=c.createGain();n=y.gain.value=0;x.connect(y);y.connect(c.destination);setInterval(()=>(x.frequency.value=[261.63,220,174.61,196][n%4],n++,y.gain.value=1),500)

    programmer5000

    Posted 2017-05-16T15:45:56.117

    Reputation: 7 828

    Why the downvote? – programmer5000 – 2017-05-16T20:16:27.297

    5heheh, I can slow down a note by vigorously scrolling my browser. – Level River St – 2017-05-16T21:51:29.557

    3

    Bash + beep, 32 bytes

    beep -f261 -nf220 -nf175 -nf196
    

    If the pcspkr module isn't loaded, it must be loaded by the script, and it counts toward the byte count, then add 'insmod pcspkr\n' to the beginning, change to 36 bytes, and run as root.

    pizzapants184

    Posted 2017-05-16T15:45:56.117

    Reputation: 3 174

    1

    C#, 93 bytes

    ()=>{var k=new int[]{261,220,174,196};for (int s=0;s<4;s++){System.Console.Beep(k[s],500);}};
    

    LiefdeWen

    Posted 2017-05-16T15:45:56.117

    Reputation: 3 381

    1

    Python 2, 61 bytes

    from winsound import*
    exec'Beep(%s,100);'*4%(261,220,174,196)
    

    Dead Possum

    Posted 2017-05-16T15:45:56.117

    Reputation: 3 256

    1

    C++ (windows), 84 bytes

    include<windows.h>
    int i;void f(){Beep((int[]){261,220,174,196}[i++],500);i<4&&f();}
    

    Khaled.K

    Posted 2017-05-16T15:45:56.117

    Reputation: 1 435