Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple sounds in C++
    primarykey
    data
    text
    <p>Using C++ 11 in Visual Studio 2012, I'm trying to sounds which I've observed in Pascal. In Pascal, it seems like you're able to send a frequency to the internal speaker, which plays this frequency until you tell it to stop (or until you tell it to play a different frequency). So here's what I need:</p> <ul> <li>I must be able to specify the frequency of the sound</li> <li>The sound must have little or no gap (up to maybe 5ms would be acceptable)</li> <li>I do not want to use external sound libraries (please do not waste my time by suggesting them, unless they are <strong>incredibly</strong> lightweight and provide an exceptionally wide range of use)</li> <li>Preferably, the sound would be played on internal speaker, rather than through the computer's regular speakers</li> </ul> <p>I can't find any include-able libraries/headers in visual studio which provide the ability to send a waveform to the internal speaker. I'm willing to try to work directly with the internal speaker (I know this would be hard, but I'm not an idiot - I think I can figure it out, with some guidance), but I can't find any documentation on accessing the internal speaker in Windows.</p> <p><strong>EDIT</strong>: From <a href="https://stackoverflow.com/questions/10216931/play-sound-on-internal-speakers-and-possibility-to-use-old-xp-api-function">this post</a>, I was able to gather that most computers nowadays don't actually have an internal speaker. Bummer. That's fine though - I can use the connected speakers, but I still have the following requirements:</p> <ul> <li>I need to be able to specify a frequency and have the speakers play that frequency until I tell them to stop</li> <li>I would rather not use external libraries</li> </ul> <p><strong>EDIT 2</strong>: Here's the class I'm working on:</p> <pre><code>#define HALF_NOTE 1.059463094359 // HALF_NOTE ^ 12 = 2 #include &lt;Windows.h&gt; #include &lt;math.h&gt; class SoundEffect { public: SoundEffect(){} void Play() { for (int i = 0; data[i + 1] &gt; 0; i++) { Beep(16 * pow(HALF_NOTE, data[i++] - 1), data[i] * 10); // (frequency of c0) * (twelfth root of 2) ^ (number of half steps above c0) // Ideally, the code would look more like this (pseudocode): // sound(16 * pow(HALF_NOTE, data[i++] - 1)); // Start playing the specified frequency // delay(data[i] * 10); } // nosound(); } int&amp; operator[] (int location) { return data[location]; } private: int data[256]; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload