| 1 | package Audio::AMaMP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.6.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.3'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | require XSLoader; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | XSLoader::load('Audio::AMaMP', $VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return bless {}, shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # This starts the core. Essentially OO-wraps the C function. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub startCore { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startCore: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Get input parameters and check. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ($self, $corePath, $inputFile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return 0 unless $self && $corePath && $inputFile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self and $corePath and $inputFile
$self and $corePath
MC/DC0%0/3
$self and $corePath and $inputFile
$self
$corePath
$inputFile
Truth table0%0/4
A and B and C
A= $selfB= $corePathC= $inputFile
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Now attempt to invoke the core. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $core = amampStartCore($corePath, $inputFile); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($core) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Success. Stash core object and return true. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{'core'} = $core; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # Failure. Return false. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Gets a message in plain text. Essentially wraps the C function. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub getRawMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getRawMessage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | # Get input. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($self, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return undef unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $block = 0+$block; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Attempt to call amampGetRawMessage and return what it gives. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return amampGetRawMessage($self->{'core'}, $block); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Sends a plain text message. Essentially wraps the C function. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub sendRawMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sendRawMessage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Get input. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return 0 unless $message; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # Attempt to call amampSendRawMessage and return what it gives. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return amampSendRawMessage($self->{'core'}, $message); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # Sends a message arranged in a hash structure. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub sendMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sendMessage: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | # Get input. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self, %input) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return unless $input{'type'} && $input{'parameters'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input{"type"} and $input{"parameters"}
MC/DC0%0/2
$input{"type"} and $input{"parameters"}
$input{"type"}
$input{"parameters"}
Truth table0%0/3
A and B
A= $input{"type"}B= $input{"parameters"}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Construct message. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $message = "$input{'type'}:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | for (keys %{$input{'parameters'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $message .= "\t$_: $input{'parameters'}->{$_}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $message .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # Attempt to send message. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return $self->sendRawMessage($message); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Gets a message and parses it into a hash based data structure. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub getMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getMessage: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Get input. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ($self, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Get message. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $rawMessage = $self->getRawMessage($block); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return () unless $rawMessage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # Parse. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $foundType = 0; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my %message = (); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my %params = (); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | foreach $line (split(/\n/, $rawMessage)) { | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($foundType) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | # Should be a parameter. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($line =~ /^\t([\w_\-]{1,30}): (.+)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $params{$1} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } elsif ($line ne '') { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # Parse error. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # Should be type line. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($line =~ /^([\w_\-]{1,30}):$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $message{'type'} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $foundType = 1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # Parse error. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # Return message structure. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $message{'parameters'} = \%params; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return %message; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # This sub checks if the core is still alive/available. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub isCoreAlive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isCoreAlive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Just call C function to check. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return amampIsCoreAlive($self->{'core'}); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||||||||||||||||