Advertisement
Krystal_Amaia

Untitled

Jul 3rd, 2023
3,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. class Note {
  6.     public int Frequency { get; set; }
  7.     public int Duration { get; set; }
  8.  
  9.     public Note(int frequency, int duration) {
  10.         Frequency = frequency;
  11.         Duration = duration;
  12.     }
  13. }
  14.  
  15. class Program {
  16.     static void Main(string[] args) {
  17.         // Chorus notes and durations
  18.         Console.ReadKey();
  19.         List<Note> chorus = new List<Note>()
  20.         {
  21.             new Note( 392, 60 ),
  22.             new Note( 440, 60 ),
  23.             new Note(523, 60  ),
  24.             new Note(440, 60  ),
  25.             new Note(659, 120  ),
  26.             new Note(659, 60  ),
  27.             new Note(587,240 ),
  28.  
  29.             new Note( 392, 60 ),
  30.             new Note( 440, 60 ),
  31.             new Note(523, 60  ),
  32.             new Note(440, 60  ),
  33.             new Note(587, 120),
  34.             new Note(587, 60),
  35.             new Note(523, 120),
  36.  
  37.             new Note(494, 60),
  38.             new Note(440, 60)
  39.            
  40.  
  41.         };
  42.  
  43.         // Tempo (in beats per minute)
  44.         int bpm = 120;
  45.  
  46.         // Calculate delay between notes based on tempo
  47.         int delay = (int)((60.0 / bpm) * 1000);
  48.  
  49.         // Play the entire chorus with the correct tempo
  50.         for (int i = 0; i < 2; i++)  // Repeat the chorus twice
  51.         {
  52.             foreach (var note in chorus) {
  53.                 Console.Beep(note.Frequency, (int)note.Duration *2 );
  54.                 Thread.Sleep(delay / 2);    
  55.             }
  56.             Thread.Sleep(delay);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement