Folks, I am an engineer who learned Pascal back in my day and I am trying to get around object-oriented languages, with limited success. I'm just getting started on C#, so please bear with me.
I copied some code I found at https://blogs.msdn.microsoft.com/dawate/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c/ and now I am trying to run it, but there's something wrong at line 128.
The original code was
- public enum WaveExampleType
- {
- ExampleSineWave = 0
- }
-
- public class WaveGenerator
- {
-
- WaveHeader header;
- WaveFormatChunk format;
- WaveDataChunk data;
-
- }
-
- public WaveGenerator(WaveExampleType type)
- {
-
- header = new WaveHeader();
- format = new WaveFormatChunk();
- data = new WaveDataChunk();
-
-
- switch (type)
- {
- case WaveExampleType.ExampleSineWave:
-
- uint numSamples = format.dwSamplesPerSec * format.wChannels;
-
- data.shortArray = new short[numSamples];
- int amplitude = 32760;
- double freq = 440.0f;
-
-
- double t = (Math.PI * 2 * freq) / (format.dwSamplesPerSec * format.wChannels);
- for (uint i = 0; i < numSamples - 1; i++)
-
- for (int channel = 0; channel < format.wChannels; channel++)
- {
- data.shortArray[i + channel] = Convert.ToInt16(amplitude * Math.Sin(t * i));
- }
- }
-
- data.dwChunkSize = (uint)(data.shortArray.Length * (format.wBitsPerSample / 8));
- break;
- }
- }
But I get the return type error for line 1. (line 128 at this online editor: http://rextester.com/KOVPK29971). What is wrong here? I get that the intention was to leave room for a future implementation of a different WaveExampleType using the switch/case thing, but why does one have to write anything inside the parenthesis in line 1 and why does it have the same name as the class?
I know it's a very simple thing, and I realize the point is I don't understand the whole point behind creating a class and then something else with the same name. Remember, I learned Pascal. Could someone please point how to correct the code and the idea behind it? Thanks in advance!