4

I want to make sound with a specific frequency. Something like:

Console.Beep(500, 1000);

But this is only for integer values of Hertz. How can I make for example 500.1Hz? Thanks.

Knowledge Cube
  • 990
  • 12
  • 35
Ferenz
  • 39
  • 4
  • 3
    First of all, you can't. Second, there are no fractions in Hertz, this unit is always measured and set to whole numbers (integers) – Koby Douek Jun 08 '17 at 10:17
  • 1
    But tone A has 440.00 Hz and tone C has 523.25Hz. So how can I make C? – Ferenz Jun 08 '17 at 10:20
  • You can't - You will have to round the number – Koby Douek Jun 08 '17 at 10:22
  • 1
    Hertz are fraction unit... so there must be some solutions. – Ferenz Jun 08 '17 at 10:25
  • How about using MIDI? There is a toolkit here: https://github.com/tebjan/Sanford.Multimedia.Midi – Palle Due Jun 08 '17 at 10:28
  • Yeah, but Midi can play only exatly tone, I need all frequencys. – Ferenz Jun 08 '17 at 10:42
  • 5
    Possible duplicate of [Creating sine or square wave in C#](https://stackoverflow.com/questions/203890/creating-sine-or-square-wave-in-c-sharp) – TheHvidsten Jun 08 '17 at 13:02
  • how hard are you willing to work to emit an arbitrary frequency ? a heavy handed technique would be to make calls to Web Audio API where you are free to synthesize an arbitrary audio curve in PCM format of any frequency, fractional cycles per second or whatever you wish ... ? – Scott Stensland Jun 08 '17 at 17:43
  • @FandaKožnar the reason you can't use arbitrary fractional frequencies with `Console.Beep` is because the hardware isn't designed for that. You'll have to go through your systems sound system. –  Jun 08 '17 at 17:58
  • 1
    @KobyDouek He can't use fractional units of Hertz here because (as you probably know) `Console.Beep` will only work with integer values. [But it is entirely possible to have fractional units of Hertz, even below 1Hz, since it's an SI unit.](https://en.wikipedia.org/wiki/Hertz#SI_multiples) – Knowledge Cube Jun 08 '17 at 18:05
  • @GTHvidsten You'll have to explain why that's a duplicate, because AFAICT the only thing these two questions have in common as far as what they're asking for is playing sound. It's related, but not an exact copy. – Knowledge Cube Jun 08 '17 at 18:07
  • 2
    @ChristopherKyleHorton Question is about playing sound with fractions of Hz. The related question has answers and examples that will play sound at any (`double`) Hz. – TheHvidsten Jun 08 '17 at 18:17
  • @ChristopherKyleHorton it doesn't have to be an *exact* duplicate. According to [Meta](https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled), "Questions may be duplicates if they have the same (potential) answers." The marked question does indeed answer this question. –  Jun 08 '17 at 19:47

0 Answers0