Created
January 31, 2019 08:50
-
-
Save Liteolika/678bd2fba9edf2cc3b1529093a2ebd54 to your computer and use it in GitHub Desktop.
Lite leksaker till Salim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace SalimsLekstuga | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var lek = new SalimsLeksak(); | |
Console.WriteLine(lek.DeviceInfo.InstalledMemory); | |
lek.TunePlayer.PlayTune(); | |
Console.ReadKey(); | |
} | |
} | |
public class SalimsLeksak | |
{ | |
public TunePlayerImpl TunePlayer = new TunePlayerImpl(); | |
public DevInfoImpl DeviceInfo = new DevInfoImpl(); | |
public class TunePlayerImpl | |
{ | |
[DllImport("kernel32")] | |
static extern bool Beep(UInt32 frequency, UInt32 duration); | |
public void PlayTune() | |
{ | |
Beep(Tones.C4, ToneLenths.Full); | |
Beep(Tones.C4, ToneLenths.Full); | |
Beep(Tones.C4, ToneLenths.Full); | |
Beep(Tones.E4, ToneLenths.Full); | |
Beep(Tones.D4, ToneLenths.Full); | |
Beep(Tones.D4, ToneLenths.Full); | |
Beep(Tones.D4, ToneLenths.Full); | |
Beep(Tones.F4, ToneLenths.Full); | |
Beep(Tones.E4, ToneLenths.Full); | |
Beep(Tones.E4, ToneLenths.Full); | |
Beep(Tones.D4, ToneLenths.Full); | |
Beep(Tones.D4, ToneLenths.Full); | |
Beep(Tones.C4, ToneLenths.Quarter); | |
} | |
public void Beep(int tone, int length) | |
{ | |
Beep(tone, length); | |
} | |
public static class ToneLenths | |
{ | |
public static UInt32 Quarter = 2000; | |
public static UInt32 Full = 500; | |
public static UInt32 Half = 250; | |
} | |
public static class Tones | |
{ | |
public static UInt32 C4 = 261; | |
public static UInt32 D4 = 293; | |
public static UInt32 E4 = 329; | |
public static UInt32 F4 = 349; | |
public static UInt32 G4 = 392; | |
public static UInt32 A4 = 440; | |
public static UInt32 B4 = 493; | |
public static UInt32 C5 = 523; | |
} | |
} | |
public class DevInfoImpl | |
{ | |
// http://www.geoffchappell.com/studies/windows/win32/kernel32/api/ | |
[DllImport("kernel32")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
static extern bool GetPhysicallyInstalledSystemMemory(out long TotalMemoryInKilobytes); | |
public string InstalledMemory | |
{ | |
get | |
{ | |
GetPhysicallyInstalledSystemMemory(out long memKb); | |
var gb = (memKb / 1024 / 1024); | |
return $"{gb} GB of RAM installed."; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment