Audio-TinySoundFont

 view release on metacpan or  search on metacpan

t/012-attrs.t  view on Meta::CPAN

use strict;
use Test::More;
use FindBin qw/$Bin/;
use Audio::TinySoundFont;

use autodie;
use Try::Tiny;
use List::Util qw/sum/;

my $sf2_file = "$Bin/tiny.sf2";
my $tsf      = Audio::TinySoundFont->new($sf2_file);

sub p10
{
  my @samples = reverse sort unpack 's<*', shift;
  splice( @samples, int( @samples * .1 ) );
  return sum(@samples) / scalar(@samples);
}

# Volume
{
  $tsf->volume(-1.0);
  $tsf->note_on('');
  $tsf->note_off('');
  my $volneg1 = $tsf->render;

  $tsf->volume(-0.0001);
  $tsf->note_on('');
  $tsf->note_off('');
  my $volnsm = $tsf->render;

  $tsf->volume(0.0);
  $tsf->note_on('');
  $tsf->note_off('');
  my $vol0 = $tsf->render;

  # Because of how TSF handles the lower limit for gain, this is equal to 0.
  $tsf->volume(0.00001);
  $tsf->note_on('');
  $tsf->note_off('');
  my $volll = $tsf->render;

  $tsf->volume(0.0001);
  $tsf->note_on('');
  $tsf->note_off('');
  my $volsm = $tsf->render;

  $tsf->volume(0.5);
  $tsf->note_on('');
  $tsf->note_off('');
  my $vol05 = $tsf->render;

  $tsf->volume(0.9999);
  $tsf->note_on('');
  $tsf->note_off('');
  my $vol49s = $tsf->render;

  $tsf->volume(1.0);
  $tsf->note_on('');
  $tsf->note_off('');
  my $vol1 = $tsf->render;

  $tsf->volume(1.0001);
  $tsf->note_on('');
  $tsf->note_off('');
  my $volld = $tsf->render;



( run in 1.667 second using v1.01-cache-2.11-cpan-df04353d9ac )