source: gs3-extensions/audioDB/trunk/src/perllib/plugins/AudioDBPlugin.pm@ 24338

Last change on this file since 24338 was 24338, checked in by davidb, 13 years ago

Plugins for processing audio files with audioDB/fftExtract and store results as associated files

File size: 5.5 KB
Line 
1###########################################################################
2#
3# AudioDBPlugin.pm -- for extracting Chroma and Power Log features to work
4# with Queen Marys audioDB
5#
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2011 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28package AudioDBPlugin;
29
30use BasePlugin;
31use FFTExtractor;
32
33use strict;
34no strict 'refs'; # allow filehandles to be variables and viceversa
35no strict 'subs';
36
37use gsprintf 'gsprintf';
38
39sub BEGIN {
40 @AudioDBPlugin::ISA = ('BasePlugin', 'FFTExtractor');
41}
42
43my $enable_streaming_list =
44 [{'name' => "disabled", 'desc' => "Do not create any video file optimised for streaming over the Internet."},
45 {'name' => "flv", 'desc' => "Uses the FLV format for streaming media. Better to target old computers."},
46 {'name' => "mp4", 'desc' => "Uses the MP4 container with H264 and AAC codecs. Better quality at very low bitrates but more ressources intensive."},
47 {'name' => "mp3", 'desc' => "(audio only) Uses MP3 for psuedo streaming."}
48 ];
49
50my $streaming_mime_types = { "flv" => "video/flv",
51 "mp4" => "video/mp4",
52 "mp3" => "audio/mpeg" };
53
54my $arguments =
55 [
56 { 'name' => "compute_fft_features",
57 'desc' => "{FFTExtractor.compute_fft_features}",
58 'type' => "enum",
59 'list' => [{'name' => "true", 'desc' => "{common.true}"},
60 {'name' => "false", 'desc' => "{common.false}"}],
61 'deft' => "false",
62 'reqd' => "no" },
63 { 'name' => "process_exp",
64 'desc' => "{BasePlugin.process_exp}",
65 'type' => "regexp",
66 'deft' => &get_default_process_exp(),
67 'reqd' => "no" },
68
69 { 'name' => "enable_streaming",
70 'desc' => "{MultimediaPlug.enable_streaming}",
71 'type' => "enum",
72 'list' => $enable_streaming_list,
73 'deft' => "disabled",
74 'reqd' => "no" }
75 ];
76
77my $options = { 'name' => "AudioDBPlugin",
78 'desc' => "{AudioDBPlugin.desc}",
79 'abstract' => "no",
80 'inherits' => "yes",
81 'args' => $arguments };
82
83
84
85sub new {
86 my ($class) = shift (@_);
87 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
88 push(@$pluginlist, $class);
89
90 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
91 push(@{$hashArgOptLists->{"OptList"}},$options);
92
93
94 my $ffte_self = new FFTExtractor($pluginlist, $inputargs, $hashArgOptLists,1);
95 my $base_self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
96
97 my $self = BasePlugin::merge_inheritance($ffte_self,$base_self);
98
99 return bless $self, $class;
100}
101
102sub get_default_process_exp {
103 my $self = shift (@_);
104
105 return q^(?i)(\.mp3|\.wave?|\.aif[fc]?|\.au|\.snd|\.og[ga])$^;
106}
107
108sub begin {
109 my $self = shift (@_);
110 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
111
112 $self->SUPER::begin(@_);
113 $self->FFTExtractor::begin(@_);
114}
115
116
117
118# do plugin specific processing of doc_obj
119sub process {
120 my $self = shift (@_);
121 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
122
123 my $outhandle = $self->{'outhandle'};
124 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
125
126 my $top_section = $doc_obj->get_top_section();
127
128 # associate original file
129 # if filename ext not .wav convert (optionally cached) to wav
130
131 my $wav_filename;
132
133 my ($input_ext) = ($filename_full_path =~ m/\.(.*?)$/);
134 $input_ext = lc($input_ext);
135
136
137 if ($input_ext ne "wav") {
138 $wav_filename = $self->convert_audio_format($filename_full_path,"wav");
139 }
140 else {
141 $wav_filename = $filename_full_path;
142 }
143 $doc_obj->associate_file($wav_filename, "audio.wav", "audio/wav", $top_section);
144
145 if ($self->{'enable_streaming'} ne "disabled") {
146
147 my $streamable_ext = lc($self->{'enable_streaming'});
148
149 if ($input_ext ne $streamable_ext) {
150 # make streamable version
151 my $streamable_filename
152 = $self->convert_audio_format($filename_full_path,$streamable_ext);
153
154 $doc_obj->associate_file($streamable_filename,
155 "streamable.$streamable_ext",
156 $streaming_mime_types->{$streamable_ext},
157 $top_section);
158 }
159 }
160
161 #
162 # Opportunity here to segment, use beat-tracking ...
163 #
164
165 if ($self->{'compute_fft_features'} eq "true")
166 {
167 # compute chroma 12 and associate file
168 my $chr12_filename = $self->compute_fft_features($wav_filename,"chroma");
169 $doc_obj->associate_file($chr12_filename, "doc.chr12",
170 "text/plain", $top_section);
171
172 # compute power log and associate file
173 my $powerlog_filename = $self->compute_fft_features($wav_filename,"power-log");
174 $doc_obj->associate_file($powerlog_filename, "doc.power",
175 "text/plain", $top_section);
176 }
177
178 #we have no text - adds dummy text and NoText metadata
179 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
180
181 return 1;
182}
183
184
185
1861;
187
188
189
Note: See TracBrowser for help on using the repository browser.