Giter VIP home page Giter VIP logo

wojciechmarek / musicfy Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 0.0 16.25 MB

Simple music player with demo songs, internet radio, and Spotify collection with live music visualisation and equalizer features.

Home Page: https://musicfy-omega.vercel.app

TypeScript 99.16% HTML 0.16% CSS 0.68%
audio-player audioapi emotion nx react spotify styled-components dark-theme typescript internet-radio spectrum-analyzer vfd vfd-display canvas audio-mixer audio-processing microphone redux redux-toolkit

musicfy's Introduction

Musicfy

A simple audio player app, allowing the play of some demo songs, internet radio stations, and use the Spotify music collection (not ready yet).

Description

The app aims to learn how to use the Browser WebAudio API to play and apply audio effects on it, Canvas API to generate visualizations and get knowledge about Spotify API.

Demo

A demo is available at https://musicfy-omega.vercel.app/.

โš ๏ธ Regarding the async audio.play() function implementation and the race conditions in the Chromium-based browsers, the app might not work on Chrome, Brave, Edge, and Opera. Use Firefox instead !!1!

Screenshots

Radio stations

Radio

Visualizations

Visualizations

Equalizer

Equalizer

Web Audio API

The Web Audio API is a high-level JavaScript API for processing and synthesizing Audio in web applications. This API aims to include capabilities found in modern game audio engines and some of the mixing, processing, and filtering tasks found in modern desktop audio production applications. The API is capable of dynamically positioning/spatializing multichannel sound sources in 3D space - generated GitHub Copilot, probably powered by Google or Wikipedia.

Basics of the Web Audio API

The app's interface may suggest that using the Web Audio API is complicated, but it's not. The most basic (and working) way to start playing with the audio in the browser is to create a new Audio object, assign an audio source to it (through URL) and invoke the .play() method:

const audio = new Audio();
audio.src = 'https://example.com/song.mp3';
audio.play();

What can be the audio source for the Audio object?

Almost everything you can supply through the URL, such as a local file, a remote file, a stream, etc.

How it works in Musicfy?

The heart of the app is an audio processor. The audio processor is an invisible component (returning null) called AudioProcessor. It listens to the events in the Redux Store, applies changes to the Audio object, and manages the audio context, the audio nodes, and effects. It also handles the audio spectrum analysis and shares data through the Redux Store.

Nevertheless, still, the most relevant line of code is:

const setNewAudioUrlAndStartPlay = useCallback((url: string) => {
  // (...)

  audio.current = new Audio(url); // <-- this line

  // (...)
}, []);

What is the audio context?

The audio context is the main object in the Web Audio API. It represents the audio-processing graph, which is built from audio sources, audio processors, and audio destinations. You can think about it as a virtual audio mixer, where you can connect the audio sources to the audio processors and the audio processors to the audio destinations. The audio context also manages the audio nodes and effects - GitHub Copilot again ๐Ÿ˜….

The audio nodes and effects

The audio nodes are the building blocks of the audio context. They are the audio sources, audio processors, and audio destinations. The audio nodes can be connected, and the audio context is responsible for managing them.

In Musicfy, the AudioNodes, BiquadFilters, and frequency analyzers are connected to each other in the setupAudioGainNodesAndAnalyzers() method. Their references are kept in the component using React's useRef() hook. The techniques manipulating the audio nodes and filters are called in the useEffect() hook.

On the other hand, there is also a setInterval() function inside the startAnalyserInterval() method, which is responsible for updating the Redux Store with the current audio spectrum data. The mentioned function is called every 20ms, which gives the 50 HZ frequency of the updates.

Used technologies

  • ๐ŸŽ Repository: Monorepo powered by NX
  • ๐Ÿงฐ Frameworks: React, Redux Toolkit
  • ๐Ÿ› ๏ธ Tools: yarn, eslint, prettier, conventional commits, react-router
  • ๐ŸŽจ Styling: styled ui by emotion, lucide icons
  • โ˜๏ธ Data source: 3 demo songs, internet radio stations, Spotify API
  • ๐Ÿ’Ž Others: desktop-first approach

How to start

  1. Clone the repository.
  2. Install node.js and yarn.
  3. Install dependencies with yarn install.
  4. Run the project with yarn web.

musicfy's People

Contributors

wojciechmarek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.