GithubHelp home page GithubHelp logo

killedbyapixel / zzfx Goto Github PK

View Code? Open in Web Editor NEW
530.0 11.0 36.0 840 KB

A Tiny JavaScript Sound FX System

Home Page: https://zzfx.3d2k.com

License: MIT License

JavaScript 100.00%
sound javascript sound-effects sound-synthesis game-development codegolf html5 sizecoding

zzfx's Introduction

ZzFX - Zuper Zmall Zound Zynth

NPM Package Build Size NPM Downloads DeepScan

ZzFX is a tiny sound generator designed to produce a wide variety of sound effects with minimal code overhead. It's perfect for games, prototypes, and any web application that needs sound without the bulk of traditional sound files.

ZzFX Image

๐ŸŒŸ Features

  • Compact: Less than 1 kilobyte when compressed!
  • Versatile: 20 controllable parameters for diverse sound effects.
  • No Dependencies: Standalone with no external libraries.
  • Cross-Browser: Compatible with nearly all web browsers.
  • Open Source: MIT licensed, use it anywhere!

๐Ÿ”Š Why Use ZzFX?

  • Code-Driven Sound: Add or change sound effects with just one line of code.
  • Lightweight: No sound asset files mean faster download times.
  • Prototyping: Ideal for placeholder sound effects.
  • Game Jams: Minimal overhead for size-limited competitions like JS13K.
  • Not Just for Games: Enhance any website with sound.

๐Ÿš€ How to Use

  • Download from github or use npm install zzfx
  • Import ZZFX as a module with using import {ZZFX, zzfx} from './ZzFX.js'
  • Or paste the code from ZzFXMicro.min.js
  • To play a sound just call zzfx(), something like zzfx(...[,,,,.1,,,,9])
  • Use the ZzFX sound designer web app to craft new sounds.

Sample sounds...

zzfx(...[,,925,.04,.3,.6,1,.3,,6.27,-184,.09,.17]); // Game Over
zzfx(...[,,537,.02,.02,.22,1,1.59,-6.98,4.97]); // Heart
zzfx(...[1.5,.8,270,,.1,,1,1.5,,,,,,,,.1,.01]); // Piano
zzfx(...[,,129,.01,,.15,,,,,,,,5]); // Drum

๐ŸŽถ ZzFX Music

๐Ÿ› ๏ธ ZzFX UI Features

  • Random Sound Generation: Create sounds from presets.
  • Sound Management: Auto-save, rename, and favorite sounds.
  • Sound Visualization: View sound wave images on playback.
  • Sharing: Load sounds via pasted zzfx code.
  • Export/Import: Drag-and-drop support for sound lists.
  • Offline Playback: Save sounds as .wav files.

๐Ÿ–ฅ๏ธ ZzFX Micro Code

Here's all the code you need to play ZzFX sounds with JavaScript!

let // ZzFXMicro - Zuper Zmall Zound Zynth - v1.3.0 by Frank Force ~ 1000 bytes
zzfxV=.3,               // volume
zzfxX=new AudioContext, // audio context
zzfx=                   // play sound
(p=1,k=.05,b=220,e=0,r=0,t=.1,q=0,D=1,u=0,y=0,v=0,z=0,l=0,E=0,A=0,F=0,c=0,w=1,m=0,B=0
,N=0)=>{let M=Math,d=2*M.PI,R=44100,G=u*=500*d/R/R,C=b*=(1-k+2*k*M.random(k=[]))*d/R,
g=0,H=0,a=0,n=1,I=0,J=0,f=0,h=N<0?-1:1,x=d*h*N*2/R,L=M.cos(x),Z=M.sin,K=Z(x)/4,O=1+K,
X=-2*L/O,Y=(1-K)/O,P=(1+h*L)/2/O,Q=-(h+L)/O,S=P,T=0,U=0,V=0,W=0;e=R*e+9;m*=R;r*=R;t*=
R;c*=R;y*=500*d/R**3;A*=d/R;v*=d/R;z*=R;l=R*l|0;p*=zzfxV;for(h=e+m+r+t+c|0;a<h;k[a++]
=f*p)++J%(100*F|0)||(f=q?1<q?2<q?3<q?Z(g*g):M.max(M.min(M.tan(g),1),-1):1-(2*g/d%2+2)
%2:1-4*M.abs(M.round(g/d)-g/d):Z(g),f=(l?1-B+B*Z(d*a/l):1)*(f<0?-1:1)*M.abs(f)**D*(a<
e?a/e:a<e+m?1-(a-e)/m*(1-w):a<e+m+r?w:a<h-c?(h-a-c)/t*w:0),f=c?f/2+(c>a?0:(a<h-c?1:(h
-a)/c)*k[a-c|0]/2/p):f,N?f=W=S*T+Q*(T=U)+P*(U=f)-Y*V-X*(V=W):0),x=(b+=u+=y)*M.cos(A*
H++),g+=x+x*E*Z(a**5),n&&++n>z&&(b+=v,C+=v,n=0),!l||++I%l||(b=C,u=G,n=n||1);p=zzfxX.
createBuffer(1,h,R);p.getChannelData(0).set(k);b=zzfxX.createBufferSource();
b.buffer=p;b.connect(zzfxX.destination);b.start()}

๐ŸŽฎ Games Using ZzFX

Space Huggers / Packabunchas / Galaxy Rider / The Adventures of Captain Callisto / Welcome to Space / Bogus Roads / NoteCraft / The Wandering Wraith / Bounce Back / Hue Jumper / Bubba's Back Room / Backstabber Hero / Spendotron: 2019 / Dioretsa / Back 2 Back / Quick Wins / Back Relax / Back To The Island / Backspace It / Back To The Stars / Can't Get Back / Letchworth Village / Noegnud / Sausage Redemption / Marshmallow Sky / Big Champ / I want to google the game / Edge Not Found / Stolen Sword / Highway 404 / The Last Spartan / OS13k / Crab Story / Cooking for Skully / Egg Time Rewind / Charon Jr. / 13 / Soul Surf / Dead Again / Trench Fisher / Path to Glory / Merlin vs Alfonso / Casual Crusade / Squirtcopter

ZzFX Image

zzfx's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zzfx's Issues

Spectrogram

Thanks for the great library.
Very smart approach to sfx, can be used to describe many basic sounds.
Just a suggestion - is there a sense to add spectrogram to the preview?
I was going to replicate some drum sounds in zzfx, spectrogram is missing...

Sort parameters by estimated frequency

I noticed that in the sounds I used for my game there were a number of parameters that are generally undefined, like randomness, pitchJumpTime, repeatTime... however the last two, tremolo and decay are always used, so it's not possible shorten the arrays to take advantage of the defaults.

Perhaps it would be useful to tweak the parameter order for some byte size gains?

Multiple effects in a single run

Trying to recreate some real sounds with zzfx I found out it may be helpful to run multiple zzfx simultaneously.
I started thinking would that be something possible/desirable?
I can envision simple API expansion as ZZFX.PlaySamples(ZZFX.BuildSamples(...a), ZZFX.BuildSamples(...b))

(btw: what's the reasoning for naming methods with cap letter? Usually that convention in JS is for classes)

Custom modulation function

Right now half-cosine is used for modulation, eg.

zzfx.play(...[,0,1925,,2.4,0,,,,,,,,,2,,,.5])

produces the following spectrogram:
image

Would be nice to have another modulation types, eg. sin:
image
saw:
image
tri:
image

Use `Math.sign` instead of own implementation

Noticed that both ZzFX and ZzFXMicro implement a sign function. In the context where this is used, it can be replaced with Math.sign, which has fairly good browser support.

Happy to provide a PR.

npm package

Hello mate,

What do you think about distributing this awesome tool as a npm package?

Thanks for your help!

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.