annotate cpack/dml/lib/dsp.pl @ 7:3c7cc53984a6 no-matlab tip

removed rcutils as seem incompatible with this version (no history/2 defined)
author wolffd.mail@googlemail.com
date Wed, 25 Jul 2018 15:51:48 +0000
parents cef93a1252f2
children
rev   line source
Daniel@0 1 /* Part of DML (Digital Music Laboratory)
Daniel@0 2 Copyright 2014-2015 Samer Abdallah, University of London
Daniel@0 3
Daniel@0 4 This program is free software; you can redistribute it and/or
Daniel@0 5 modify it under the terms of the GNU General Public License
Daniel@0 6 as published by the Free Software Foundation; either version 2
Daniel@0 7 of the License, or (at your option) any later version.
Daniel@0 8
Daniel@0 9 This program is distributed in the hope that it will be useful,
Daniel@0 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
Daniel@0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Daniel@0 12 GNU General Public License for more details.
Daniel@0 13
Daniel@0 14 You should have received a copy of the GNU General Public
Daniel@0 15 License along with this library; if not, write to the Free Software
Daniel@0 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Daniel@0 17 */
Daniel@0 18
Daniel@0 19 :- module(dsp,
Daniel@0 20 [ spectrogram/2
Daniel@0 21 , spectrogram/3
Daniel@0 22 , spectrum/2
Daniel@0 23 , sum/2
Daniel@0 24 ]).
Daniel@0 25
Daniel@0 26 :- use_module(library(semweb/rdf_db)).
Daniel@0 27 :- use_module(library(sandbox)).
Daniel@0 28 :- use_module(library(rdfutils)).
Daniel@0 29 :- use_module(library(memo)).
wolffd@2 30 % :- use_module(library(mlserver)).
Daniel@0 31
Daniel@0 32 :- set_prolog_flag(double_quotes,string).
Daniel@0 33
Daniel@0 34 :- setting(specgram_dynamic_range,number,90,"Dynamic range in dB for spectrograms").
Daniel@0 35
wolffd@2 36 % spectrogram(URI,X) :-
wolffd@2 37 % rdf_text(URI,beets:path,P),
wolffd@2 38 % X===specgrm( monofile(P), hanning(2048),512).
wolffd@2 39
wolffd@2 40 spectrogram(URI,X).
Daniel@0 41
Daniel@0 42 :- volatile_memo spectrum(+atom,-ground).
wolffd@2 43 %spectrum(URI,X) :-
wolffd@2 44 % spectrogram(URI,Y),
wolffd@2 45 % X1===sum(Y,2),
wolffd@2 46 % persist_item(X1,X).
Daniel@0 47
wolffd@2 48 spectrum(URI,X).
wolffd@2 49
wolffd@2 50 spectrogram(URI,Offset,Length).
wolffd@2 51
wolffd@2 52 /* spectrogram(URI,Offset,Length) :-
Daniel@0 53 setting(specgram_dynamic_range,DBs),
Daniel@0 54 ( cp_audio:audio_file(URI,P,Fmt),
Daniel@0 55 ( Fmt=just(aac)
Daniel@0 56 -> MSignal=sndfile(q(P),q(enc),q(aac))
Daniel@0 57 ; MSignal=sndfile(q(P))
Daniel@0 58 )
Daniel@0 59 ; cp_audio:audio_link(URI,P,just(mp3)),
Daniel@0 60 MSignal=mp3file(q(P))
Daniel@0 61 ), !,
Daniel@0 62 ?? (specgrm( taket(Length,dropt(Offset,mixdown(MSignal))),
Daniel@0 63 hanning(2048),512,"range",DBs,"offset",Offset);
Daniel@0 64 ylim([0,15])).
wolffd@2 65 */
Daniel@0 66
wolffd@2 67 sum(Items,Sum).
wolffd@2 68
wolffd@2 69 % sum(Items,Sum) :-
wolffd@2 70 % once(member(X,Items)),
wolffd@2 71 % D===numdims(X)+1,
wolffd@2 72 % Sum===sum(cellcat(D,cell(Items)),D).
Daniel@0 73
Daniel@0 74 sandbox:safe_primitive(dsp:spectrogram(_,_,_)).