Is there any method to play mp3
without having speaker, using Console.Beep
?

- 2,634
- 5
- 22
- 33

- 57
- 1
- 4
-
2+1 for the creepy idea! :-D – Rob Nov 06 '13 at 08:32
-
5Welcome to Stackoverflow. Did you try anything so far? Show your effort first so people might show their. Please read [FAQ] and [ask] – Soner Gönül Nov 06 '13 at 08:32
-
1Beep is one of the error handling function, You want to play a mp3 when something goes wrong in the app :) ? – Kurubaran Nov 06 '13 at 08:50
-
In the school, we do not have speaker and I want to play any music. It's also good if i could convert an mp3 file to .MID and then play it using console.beep or anything what can make sound through the motherboard's beeping speaker. – user2959514 Nov 07 '13 at 10:40
3 Answers
That's not possible. Music is composed of many frequencies at different volume levels, all mixed together to create a complex wave form. A mix that very rapidly changes over time.
Console.Beep() only produces one frequency with no control over volume. The ability to change that frequency over time is also severely restricted, the transitions are not smooth. It will never sound like anything more than a beep.
Playing back MP3 requires a device that can convert a digital signal to an analog one that drives a speaker. Readily available in any machine today, integrated in the motherboard. Also used today to produce the Console.Beep() sound, modern machines don't have a speaker anymore.

- 922,412
- 146
- 1,693
- 2,536
-
I found something: http://stackoverflow.com/questions/1643122/is-it-possible-to-generate-complex-tones-in-c What is it? Can I use it for this, or is this used for something else? – user2959514 Nov 07 '13 at 09:59
I was trying to make something similar i.e. given an mp3 file I was trying to generate Console.Beep commands to represent the approximation of the audio signal. Goertzel algorithm is a good start to find frequencies for your samples and duration can be easily calculated using the amount of samples you pass in to the algorithm.
What I've found out is that this approach works great with uniform and continuous audio signals, however if you want to convert something more complex like a song it will discard major features giving you just a crude approximation of overall frequency for your given samples which in turn make it unrecognizable compered to your input.
Here is the code for the algorithm I've used:
private static double GoertzelAmplitude(IReadOnlyList<float> samples, double freq, int sampleRate)
{
var tmp1 = 0.0;
var tmp2 = 0.0;
var normalizedfreq = freq / sampleRate;
var coeff = 2 * Math.Cos(2 * Math.PI * normalizedfreq);
for (var i = 0; i < samples.Count; i++)
{
var newTerm = samples[i] + coeff * tmp1 - tmp2;
tmp2 = tmp1;
tmp1 = newTerm;
}
var power = tmp2 * tmp2 + tmp1 * tmp1 - coeff * tmp1 * tmp2;
return power;
}

- 126
- 2
- 3
http://msdn.microsoft.com/en-us/library/4fe3hdb1(v=vs.110).aspx explains how to use the Beep(Int32, Int32) method to play the first few notes of a song.
however, there are 2 big issues with this: console.beep is not supported on 64 bit windows 7 and windows XP, and has no overload with 2 Int32 parameters on anything ME or lower.
if you want to do this, you got 2 options for your song: the first is to hardcode your song. If you want the song to be interchangeable, you can use an MP3 parser like Intelliscore (http://www.intelliscore.net/) to read the song into a .MID file, then read that .MID file out again.

- 3,439
- 5
- 29
- 59
-
And how could I get the frequency of the tones from a .MID file? I wouldn't like to use a third-party software. – user2959514 Nov 07 '13 at 10:06