Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.68 KB

README.md

File metadata and controls

58 lines (44 loc) · 1.68 KB

strings

Build Status Scrutinizer Code Quality

Calculates string lengths, frequencies, intervals, harmonics, etc.

Example

<?php

require_once 'vendor/autoload.php';

use ExtendedStrings\Strings\HarmonicCalculator;
use ExtendedStrings\Strings\Instrument;
use ExtendedStrings\Strings\Note;

// Find all the possible harmonics on a violin for the sounding pitch D5.
$harmonics = (new HarmonicCalculator())
    ->findHarmonics(Note::fromName('D5'), Instrument::fromPreset('violin'));

foreach ($harmonics as $harmonic) {
    $string = $harmonic->getString();
    $stringNote = Note::fromFrequency($string->getFrequency());
    $baseNote = Note::fromFrequency($harmonic->getBaseStop()->getFrequency($string));
    $harmonicNote = Note::fromFrequency($harmonic->getHalfStop()->getFrequency($string));
    $soundingNote = Note::fromFrequency($harmonic->getSoundingFrequency());

    echo "String: $stringNote\n";
    if ($harmonic->isNatural()) {
        echo "  Harmonic pressure on: $harmonicNote\n";
    } else {
        echo "  Artificial harmonic: $baseNote : $harmonicNote\n";
    }
    echo "  Sounding pitch: $soundingNote\n";
    echo "\n";
}

Result:

String: D4
  Harmonic pressure on: D5
  Sounding pitch: D5

String: G3
  Harmonic pressure on: D5 +2c
  Sounding pitch: D5 +2c

String: G3
  Harmonic pressure on: D4 +2c
  Sounding pitch: D5 +2c

String: G3
  Artificial harmonic: D4 : D5
  Sounding pitch: D5