Coder Social home page Coder Social logo

piano's Introduction

Piano

A low dependency terminal piano player writen in Perl.

Many perl sound examples I have come across have needed /dev/dsp/ support. This requires OSS compatibility support and is not automatically available in my distro. Audio::DSP fails. While it can be installed, I have explored ways I may bypass this. padsp is one option. It can be used to start a program to give it OSS compatibility and access to /dev/dsp etc.

In Attempt 1 Twinkle.pl. I have combined some code found in a code golf site, and combined it with a pipe into padsp and then tee to a /dev/dsp. (see refs below). A previous bug had been that the data in the piano aplication would only produce outputs on alternate calles. It appears that the piping/processing of the sounds waits until 1024 bytes are sent...

open (my $dsp,"|padsp tee /dev/audio > /dev/null") or   die qq(Couldn't execute for piping);

Attempt 2 maps 96 key piano to notes and frequencies and a sinewave generator

SampleMaker (Attempt 3)

  • Draws the piano and notes with reference a keyboard.
  • creates and saves a sample file so does not need to be recreated (using storable)
  • outputs keys data as keys are pressed ( key pressed, note represented, and frequency) as debug.
  • realised that octaves dont go A..G, but C..B !!
  • works but not for the A keys!!!..Help!!

Final version PIANO.pl

(Enable sound in the video)

PIANO.webm

Frequency to data conversion

key to frequency converter

Number of keys to middleA= keys_to_A4 Frequency of middle A (note A4, key keys_to_A4) is 440hz; all other keys can be derived from this freqency=440 * 2 ** ((KeyNumber - keys_to_A4)/12)

simple sin wave

$sps=8000       #  sample size
$resolution=128 #  peak to peak
@sample_data=map {$resolution *  $_ *  2 * $freq * pi/$sps} (0..$sps-1)

Resources

Twinkle Twinkle Little Star, Code Golf

padsp

Check out morsify

Pure Perl Beep using ioctl

Music notes

piano's People

Contributors

saiftynet avatar

Watchers

 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.