Skip to content

Supakornn/js-jinglebells

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”” Jingle Bells

πŸ“ Description

This project plays the "Jingle Bells" song using the Web Audio API 🎡

🎹 Usage in the Project

In this project, we use AudioContext to generate the notes for the "Jingle Bells" song. Here's how it works:

  1. 🎼 Create an AudioContext:

    const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  2. 🎡 The playNote function is used to play a note:

    const playNote = (frequency, duration = 0.3, startTime = 0) => {
      const oscillator = audioContext.createOscillator();
      const gainNode = audioContext.createGain();
    
      oscillator.type = "sine";
      oscillator.frequency.setValueAtTime(frequency, startTime);
    
      oscillator.connect(gainNode);
      gainNode.connect(audioContext.destination);
    
      gainNode.gain.setValueAtTime(1, startTime);
      gainNode.gain.exponentialRampToValueAtTime(0.001, startTime + duration);
    
      oscillator.start(startTime);
      oscillator.stop(startTime + duration);
    };
  3. 🎢 Define the frequencies of the notes:

    const noteFrequencies = {
      C4: 261.63,
      D4: 293.66,
      E4: 329.63,
      F4: 349.23,
      G4: 392.0,
      A4: 440.0,
      B4: 493.88,
      C5: 523.25
    };
  4. πŸŽ„ Sequence of notes in the "Jingle Bells" song:

    const jingleBells = [
      { note: "E4", duration: 0.3 },
      { note: "E4", duration: 0.3 },
      { note: "E4", duration: 0.6 }
      // ...other notes...
    ];

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 68.0%
  • CSS 23.2%
  • HTML 8.8%