├── .classpath
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.ltk.core.refactoring.prefs
├── README.md
├── bin
├── model
│ ├── Complex.class
│ ├── DataPoint.class
│ └── FFT.class
└── view
│ ├── AudioRecognizerWindow$1.class
│ ├── AudioRecognizerWindow$2.class
│ ├── AudioRecognizerWindow$3.class
│ ├── AudioRecognizerWindow$4.class
│ ├── AudioRecognizerWindow$5.class
│ ├── AudioRecognizerWindow$6.class
│ ├── AudioRecognizerWindow.class
│ ├── Complex.class
│ ├── DataPoint.class
│ ├── FFT.class
│ ├── MainView.class
│ └── SpectrumView.class
├── lib
├── jl1.0.1.jar
├── jtransforms-2.4.jar
├── mp3spi1.9.5.jar
├── tritonus_remaining-0.3.6.jar
└── tritonus_share.jar
├── out.txt
├── result.txt
└── src
├── model
├── Complex.java
├── DataPoint.java
└── FFT.java
└── view
├── AudioRecognizerWindow.java
├── MainView.java
└── SpectrumView.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | AudioRecognizer
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Feb 29 19:39:55 CET 2012
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.ltk.core.refactoring.prefs:
--------------------------------------------------------------------------------
1 | #Tue Mar 06 19:19:40 CET 2012
2 | eclipse.preferences.version=1
3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Shazam in Java
2 |
3 | Roy van Rijn has written wonderful post about Shazam algorithm and how to implement it on our own. To do this he placed many chunks of his project source code, but he did not upload all source code of his application because as he stated:
4 |
5 | The Shazam patent holders lawyers are sending me emails to stop me from releasing the code and removing this blogpost.
6 |
7 | It occurred that core of this algorithm is very simple. I have analyzed his post and as weekend project I have written simple Proof-Of-Concept application which outputs its findings to console. It gives surprisingly correct answers. For now I have tested 10 different mp3 audio files and this application was able to recognize each of them. Application is learning basing on path to mp3 file on your local disk or http stream of mp3 file from any source and recognize by sound from microphone.
8 |
--------------------------------------------------------------------------------
/bin/model/Complex.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/model/Complex.class
--------------------------------------------------------------------------------
/bin/model/DataPoint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/model/DataPoint.class
--------------------------------------------------------------------------------
/bin/model/FFT.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/model/FFT.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$1.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$2.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$3.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$4.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$5.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow$6.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow$6.class
--------------------------------------------------------------------------------
/bin/view/AudioRecognizerWindow.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/AudioRecognizerWindow.class
--------------------------------------------------------------------------------
/bin/view/Complex.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/Complex.class
--------------------------------------------------------------------------------
/bin/view/DataPoint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/DataPoint.class
--------------------------------------------------------------------------------
/bin/view/FFT.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/FFT.class
--------------------------------------------------------------------------------
/bin/view/MainView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/MainView.class
--------------------------------------------------------------------------------
/bin/view/SpectrumView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/bin/view/SpectrumView.class
--------------------------------------------------------------------------------
/lib/jl1.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/lib/jl1.0.1.jar
--------------------------------------------------------------------------------
/lib/jtransforms-2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/lib/jtransforms-2.4.jar
--------------------------------------------------------------------------------
/lib/mp3spi1.9.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/lib/mp3spi1.9.5.jar
--------------------------------------------------------------------------------
/lib/tritonus_remaining-0.3.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/lib/tritonus_remaining-0.3.6.jar
--------------------------------------------------------------------------------
/lib/tritonus_share.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsieroci/audio-recognizer/3028b6147dcd09f6b1bd418b8b0d2bacd7c8afc3/lib/tritonus_share.jar
--------------------------------------------------------------------------------
/result.txt:
--------------------------------------------------------------------------------
1 | 2.776351129731528;0.0 6.081891616009471;0.0 6.248358482165545;0.0 4.039451580272641;0.0 4.09061690331534;0.0
2 | 4.748661334456845;0.0 6.574298001622263;0.0 6.664765224886243;0.0 4.507581198608808;0.0 4.048400349084023;0.0
3 | 4.559446200334828;0.0 6.5495777158206465;0.0 6.785283514227635;0.0 4.607073981963845;0.0 4.101667141887968;0.0
4 | 5.194407021474162;0.0 6.754869513281541;0.0 6.790558640554784;0.0 4.3509048302669155;0.0 3.831123741440955;0.0
5 | 4.763174553391238;0.0 6.6532486913005995;0.0 6.810261359064656;0.0 4.51504960611852;0.0 4.125587209815778;0.0
6 | 4.190223110832613;0.0 7.580511446017711;0.0 6.5807941356441475;0.0 4.5126190284080305;0.0 4.296446591980841;0.0
7 | 4.90034950194506;0.0 6.85542985940148;0.0 6.858371194564375;0.0 4.462459387773671;0.0 4.11936102520027;0.0
8 | 4.860300330661877;0.0 6.798765027297471;0.0 7.025553887288662;0.0 4.348799238149167;0.0 4.068284074020552;0.0
9 | 3.2884248667837497;0.0 6.9959964284673255;0.0 6.629188963655582;0.0 4.797642603465407;0.0 4.01509317529307;0.0
10 | 4.671644447326872;0.0 7.441044458093627;0.0 7.279938943887681;0.0 5.11678953131751;0.0 4.208616381436355;0.0
11 | 5.144100986163165;0.0 6.547007673563245;0.0 6.86198230805097;0.0 4.776602403455008;0.0 4.06209725294547;0.0
12 | 4.58367612940105;0.0 7.846312913169201;0.0 7.407739882419208;0.0 5.121063039618861;0.0 5.256032621573009;0.0
13 | 5.292704780827847;0.0 7.653964934381413;0.0 7.659294794739263;0.0 6.966752821222854;0.0 5.498758156321728;0.0
14 | 4.700633178420715;0.0 7.099634316104024;0.0 7.38288653656091;0.0 7.3019954198654435;0.0 5.402226629897381;0.0
15 | 4.525174258227085;0.0 7.300541182059515;0.0 7.100561289547351;0.0 7.936036295225162;0.0 6.204721081677099;0.0
16 | 4.457707387814221;0.0 8.438185842384677;0.0 7.500719472818781;0.0 8.601659863617371;0.0 6.8839173609140065;0.0
17 | 4.3980830850243935;0.0 7.619804403871726;0.0 6.933849305245314;0.0 8.494746135963993;0.0 6.659396104657408;0.0
18 | 5.0414725436211585;0.0 7.741719966057412;0.0 7.2563882956334504;0.0 7.786368944602921;0.0 6.630330139564522;0.0
19 | 4.3713151476771746;0.0 7.53908695162784;0.0 7.245985933764969;0.0 7.715368226204198;0.0 6.786639805546746;0.0
20 | 4.13499953884023;0.0 7.319889531053937;0.0 7.188379074262497;0.0 7.538634064793025;0.0 6.445066214786372;0.0
21 | 5.642176698089887;0.0 7.72775832449553;0.0 7.654105264106568;0.0 7.8115087433575825;0.0 6.0563905481970455;0.0
22 | 5.386518285565515;0.0 7.128240248590381;0.0 7.28405313837139;0.0 7.618766159896205;0.0 6.027370350545083;0.0
23 | 5.427958898307917;0.0 7.329337650694199;0.0 7.264791645986954;0.0 7.378997271412629;0.0 5.882746396083083;0.0
24 | 5.394825813205222;0.0 7.57806561722071;0.0 7.968605620257671;0.0 6.791408785583752;0.0 5.5841187641038434;0.0
25 | 5.0152019568793005;0.0 7.897387882024967;0.0 7.338009180935702;0.0 7.801092901803807;0.0 6.183747650381665;0.0
26 | 5.120944884529832;0.0 7.560666158678285;0.0 7.34519242827321;0.0 7.50781508576358;0.0 6.3900929796663535;0.0
27 | 5.447433791892327;0.0 7.1084199651812545;0.0 7.5017074487362105;0.0 6.741606067347509;0.0 4.91053133759194;0.0
28 | 4.801554043019741;0.0 7.50978514138145;0.0 7.407960681247454;0.0 6.224342460548788;0.0 5.748755983166041;0.0
29 | 5.703314004508957;0.0 7.178041115732183;0.0 7.257265901831777;0.0 6.221933067214386;0.0 5.848687324024604;0.0
30 | 5.445899436654853;0.0 7.530239477367607;0.0 7.499606192097204;0.0 6.037511536587302;0.0 4.953306259937116;0.0
31 | 6.168064091295019;0.0 7.988841009278768;0.0 7.051728874934016;0.0 6.070268587435559;0.0 4.958805223172471;0.0
32 | 5.563965989213099;0.0 7.885340516075465;0.0 7.8136675382196366;0.0 5.50997808689276;0.0 4.960203515004562;0.0
33 | 4.789157783543463;0.0 7.734480824884122;0.0 7.241132844707483;0.0 5.437366432358019;0.0 5.022456794261525;0.0
34 | 5.479061087344163;0.0 7.9153839520177565;0.0 7.446108503279441;0.0 5.9936359722962;0.0 4.731043999997949;0.0
35 | 5.014343861910779;0.0 7.822906860401075;0.0 8.022186482372213;0.0 6.584421834951415;0.0 5.256911482067697;0.0
36 | 5.564144935525137;0.0 7.877785078360139;0.0 7.201838833891625;0.0 6.327681622274936;0.0 4.787843696513906;0.0
37 | 5.839242691401319;0.0 7.877209452441422;0.0 7.733873694427315;0.0 5.455969570472954;0.0 4.662928826328041;0.0
38 | 4.791125839461636;0.0 7.474768324354209;0.0 7.879314603210614;0.0 5.735255534672125;0.0 4.359290509611987;0.0
39 | 5.773360794676904;0.0 7.438086474414987;0.0 7.553134198028451;0.0 4.995994767032024;0.0 4.22236936682372;0.0
40 | 6.059112926617477;0.0 7.589257209955312;0.0 7.747174982267228;0.0 5.217670592520351;0.0 4.587877946468875;0.0
41 | 6.231742816755649;0.0 7.981708587442007;0.0 7.952684232607692;0.0 5.269502530293934;0.0 4.815468387103296;0.0
42 | 6.044264110759014;0.0 7.808946216627123;0.0 7.596830348346501;0.0 5.406222088159062;0.0 4.289913174669147;0.0
43 | 5.31872657786373;0.0 7.742502234945282;0.0 8.123226491639764;0.0 4.940889142572975;0.0 4.297937649366652;0.0
44 | 5.35736930878007;0.0 8.379442042341404;0.0 7.868274993683605;0.0 5.497133219700509;0.0 4.6074121339077125;0.0
45 | 6.1240412135674145;0.0 7.938585594280625;0.0 7.379156973932324;0.0 6.044435556479438;0.0 4.4730346246757;0.0
46 | 5.574418359764192;0.0 7.96596233242172;0.0 8.229305223287742;0.0 5.843328969759122;0.0 4.370769447247605;0.0
47 | 4.1204322336990336;0.0 7.986064522535312;0.0 7.8116824659418835;0.0 5.445306372545268;0.0 4.647349561670888;0.0
48 | 5.440671889624692;0.0 7.969486350297277;0.0 8.042746223903604;0.0 5.269588913826591;0.0 4.5370546866302774;0.0
49 | 5.7610368804525995;0.0 7.767418111666131;0.0 7.86556021592944;0.0 6.022283075149573;0.0 4.493652011065447;0.0
50 | 6.0081184505384;0.0 8.460935902030036;0.0 8.020232215562414;0.0 5.619928026616511;0.0 4.18192848837478;0.0
51 | 5.072563175029488;0.0 7.719585111284312;0.0 8.163479693715502;0.0 5.734766346022306;0.0 4.44684623067439;0.0
52 | 5.538323715769871;0.0 7.9767647011201985;0.0 8.008959076668345;0.0 5.179806694185097;0.0 4.503766149336719;0.0
53 | 6.2579337068748915;0.0 7.979341152514913;0.0 8.313529932045078;0.0 5.192985018021855;0.0 4.314052376049848;0.0
54 | 6.438927329331075;0.0 7.6859190242071955;0.0 7.867612417196559;0.0 5.51423534368293;0.0 4.474903961483378;0.0
55 | 6.16555513757232;0.0 7.633557908148586;0.0 7.404911906368305;0.0 5.919884900299033;0.0 4.91004522048385;0.0
56 | 5.294452800837331;0.0 8.168171691605401;0.0 7.890033396296857;0.0 5.858835455312406;0.0 4.808861775915287;0.0
57 | 4.2257750552536555;0.0 8.079581436360225;0.0 7.961668079038223;0.0 4.976632954333913;0.0 4.6395575733559085;0.0
58 | 5.3242140688844115;0.0 8.398789744717712;0.0 8.047502083698815;0.0 5.34809417208893;0.0 4.501067374302147;0.0
59 | 5.367586888295627;0.0 8.131286566407821;0.0 8.065007279991711;0.0 4.907350700270584;0.0 4.643208262105857;0.0
60 | 5.59482435278928;0.0 8.099528556348218;0.0 7.939736354634826;0.0 5.466373578565388;0.0 5.027216349396098;0.0
61 | 4.77544070707227;0.0 8.140678076866674;0.0 8.298654156754864;0.0 6.11728596694729;0.0 4.544704432852995;0.0
62 | 5.920018419825615;0.0 8.09438812103346;0.0 7.852071632034793;0.0 5.220352260904714;0.0 4.260734820523964;0.0
63 | 6.066427948001062;0.0 8.380572797316235;0.0 8.368378565661367;0.0 4.966990258297904;0.0 4.6139716684422405;0.0
64 | 5.6626220888365255;0.0 8.4417145761326;0.0 8.312908390087149;0.0 5.892723677500426;0.0 4.5293412544483305;0.0
65 | 5.083153225612613;0.0 7.947330284839348;0.0 7.619183165995099;0.0 4.8210500124704225;0.0 4.323204276091597;0.0
66 | 6.035207956203637;0.0 8.181623363309091;0.0 8.223081840794176;0.0 5.369059503204916;0.0 4.30359922164702;0.0
67 | 6.334178818105119;0.0 7.510758333872122;0.0 8.542335328236014;0.0 5.877482235590818;0.0 4.546452601237421;0.0
68 | 6.2461761133860145;0.0 7.718885225750756;0.0 7.866561317542348;0.0 6.286126789589992;0.0 4.883105158357901;0.0
69 | 5.623225897017065;0.0 8.1447820653701;0.0 8.267632880837347;0.0 5.973344995718606;0.0 4.395450504530874;0.0
70 | 6.161964543811772;0.0 8.067945379809428;0.0 8.294738909242925;0.0 5.361514610756271;0.0 4.684067811396412;0.0
71 | 5.519200353376343;0.0 8.659182132348297;0.0 8.289218667187628;0.0 5.33933180411738;0.0 4.390517675344435;0.0
72 | 6.244709008472202;0.0 8.598492374220102;0.0 8.37487906610197;0.0 5.4096411090341245;0.0 4.518365434717848;0.0
73 | 6.061348284986639;0.0 8.50953856797316;0.0 8.366129245050374;0.0 6.14433836557163;0.0 5.115350740524321;0.0
74 | 6.246814250508737;0.0 8.253538699621998;0.0 8.093693100857221;0.0 5.6126222230507405;0.0 4.702817789938298;0.0
75 | 6.271355331788738;0.0 8.588161824452632;0.0 7.593179704481303;0.0 5.699435772828351;0.0 4.7778709446662315;0.0
76 | 6.571504899064607;0.0 8.041743225243835;0.0 8.019863892225903;0.0 5.745093323097985;0.0 4.572434582448224;0.0
77 | 5.1746082053979;0.0 8.286981455963796;0.0 8.321078140228437;0.0 5.605419018747799;0.0 4.432846537378244;0.0
78 | 4.647709061609053;0.0 8.09828562857721;0.0 8.44046624903426;0.0 6.077586996441194;0.0 4.602108426837393;0.0
79 | 6.336964532568635;0.0 8.603723615428505;0.0 8.192816385966998;0.0 5.0852333111007395;0.0 4.726860932521073;0.0
80 | 6.541712092313279;0.0 8.122480187805357;0.0 8.260554291364278;0.0 5.723656125897555;0.0 4.616457537864857;0.0
81 | 5.539896826033771;0.0 8.020724363400406;0.0 8.14805723425469;0.0 5.819438769273463;0.0 4.732066516680241;0.0
82 | 5.281856571015422;0.0 8.680598830044913;0.0 8.188291378186076;0.0 5.997414074127266;0.0 4.827867938911495;0.0
83 | 6.551941242039999;0.0 8.247194608545415;0.0 8.687966779954573;0.0 4.929539359709088;0.0 4.802196335285127;0.0
84 | 6.248136435957525;0.0 8.401706660290685;0.0 8.412905926051899;0.0 5.2666349008496365;0.0 4.7631014053616765;0.0
85 | 5.464317934877797;0.0 8.099437146320888;0.0 8.05772688282765;0.0 5.22469870861661;0.0 4.979747189379354;0.0
86 | 6.082180589805589;0.0 8.367680821796835;0.0 8.452800890913922;0.0 4.8583926734752385;0.0 4.462767884861739;0.0
87 | 5.261734880251189;0.0 8.186962599480559;0.0 8.1461677918331;0.0 5.354435985422822;0.0 4.697471018628002;0.0
88 | 5.989849040551487;0.0 8.868847251401444;0.0 8.12280635371553;0.0 5.927240190870943;0.0 4.618801638102413;0.0
89 | 6.61857556114229;0.0 8.1409956411666;0.0 8.241007600904302;0.0 7.913482175559731;0.0 4.4850793085423994;0.0
90 | 6.576677214437163;0.0 7.798216980349258;0.0 7.784127683019412;0.0 7.244995516690725;0.0 5.0921910186325;0.0
91 | 5.928187085290922;0.0 8.43825082762686;0.0 8.632996973489192;0.0 7.220119499810539;0.0 8.132942225393856;0.0
92 | 5.759593661072303;0.0 8.229550154568134;0.0 8.111898025878332;0.0 7.193140127172856;0.0 8.099207764135363;0.0
93 | 6.4556651970490035;0.0 8.296700221596756;0.0 8.299206909387893;0.0 6.665677587690176;0.0 7.83201979605354;0.0
94 | 5.63857636566101;0.0 8.24135703677863;0.0 8.262752365141548;0.0 6.71983935083496;0.0 7.090034661368723;0.0
95 | 6.051243257702618;0.0 8.43979505113246;0.0 8.038868082307266;0.0 6.815407759728554;0.0 7.0237972489505;0.0
96 | 5.692316568065001;0.0 8.569256426898065;0.0 8.26461523854047;0.0 7.002398463004015;0.0 7.245357494158205;0.0
97 | 5.703333697940207;0.0 8.181083591267418;0.0 8.21650746004438;0.0 6.405195275108135;0.0 7.254170517284863;0.0
98 | 5.754384016147529;0.0 8.254468002335937;0.0 8.175420710648298;0.0 6.66985142786947;0.0 6.503660214971412;0.0
99 | 5.009935555237804;0.0 7.67426030806488;0.0 8.233277952761611;0.0 6.680667813786482;0.0 6.732120948157188;0.0
100 | 5.957321842136639;0.0 8.544674487118344;0.0 8.403979707004082;0.0 6.810142357838108;0.0 6.4911864894052895;0.0
101 | 6.3387409317195;0.0 8.380360070377199;0.0 8.257556240043515;0.0 5.5972694876986555;0.0 7.091584215638697;0.0
102 | 6.85838660758346;0.0 8.48453124126688;0.0 8.479499166560565;0.0 5.773355130886982;0.0 6.559185722987942;0.0
103 | 5.933153482646072;0.0 8.132635371191569;0.0 8.7160961421667;0.0 6.435671468932569;0.0 6.153769728481849;0.0
104 | 5.543812626059257;0.0 8.253727989155193;0.0 8.347674582705409;0.0 6.140516763360942;0.0 5.66713018496919;0.0
105 | 6.19501900918147;0.0 7.856492121383086;0.0 8.541008822550545;0.0 5.636013880521735;0.0 5.953717663013795;0.0
106 | 6.25471261415603;0.0 8.200053977898976;0.0 8.040588967711534;0.0 5.709640698254743;0.0 5.301583394305798;0.0
107 | 6.320860275022297;0.0 8.81284686555532;0.0 8.332658531233324;0.0 6.020565793835225;0.0 5.192572429591089;0.0
108 | 6.365533920279624;0.0 8.329311339212378;0.0 8.432227894025663;0.0 6.124503882722057;0.0 5.110349790480402;0.0
109 | 6.11385785039431;0.0 8.475949942164725;0.0 8.283876974791688;0.0 6.245902155477258;0.0 5.3571526972432775;0.0
110 | 6.184183620450732;0.0 8.67784836829795;0.0 8.041744061231338;0.0 6.027666025814193;0.0 5.490685370053443;0.0
111 | 5.644804175393883;0.0 8.649655804043674;0.0 8.113807895893384;0.0 4.915905959480002;0.0 6.031387586626262;0.0
112 | 5.316802174350789;0.0 7.756389663507249;0.0 8.298992254678057;0.0 5.786952590394314;0.0 5.169602013280842;0.0
113 | 6.089870059133788;0.0 8.90884887949917;0.0 8.526346803221063;0.0 5.429791922922205;0.0 4.749859492499419;0.0
114 | 4.7738560162484145;0.0 8.222898718222023;0.0 7.867945602802237;0.0 6.264639394151514;0.0 4.62639141451035;0.0
115 | 6.159785175234376;0.0 7.785420500433177;0.0 8.483407947431818;0.0 5.808842829820612;0.0 4.7736674702442885;0.0
116 | 6.563245504294392;0.0 7.979207227418111;0.0 8.533049738955224;0.0 5.846740789576317;0.0 4.32959975122768;0.0
117 | 6.300761688434203;0.0 8.264700926799321;0.0 8.291869682462538;0.0 5.888643918304917;0.0 4.719605249847651;0.0
118 | 6.325707710104866;0.0 7.835791349203371;0.0 8.042514815591066;0.0 5.923669842592389;0.0 4.657509062425532;0.0
119 | 6.207179983336128;0.0 8.526473487274227;0.0 8.559034971957422;0.0 5.740892975453069;0.0 4.435965149910472;0.0
120 | 6.664736500169389;0.0 8.901757826949432;0.0 8.363492845498701;0.0 5.60386997541103;0.0 5.209905015877635;0.0
121 | 5.856254938710556;0.0 8.454387595869818;0.0 8.288663285251065;0.0 4.890916183131066;0.0 4.823652260732615;0.0
122 | 5.54547382720244;0.0 8.475022221123991;0.0 8.363278501706233;0.0 5.568551054948714;0.0 4.552342763690559;0.0
123 | 5.464762723144246;0.0 8.54041991097044;0.0 8.273507125228027;0.0 5.000843301090709;0.0 4.460933109809542;0.0
124 | 5.682546995421604;0.0 8.286514593208496;0.0 8.172672634702295;0.0 5.912646616168619;0.0 4.446603511976999;0.0
125 | 5.951469327646378;0.0 8.288476565510024;0.0 8.54975961007456;0.0 6.476480292176832;0.0 4.916677766061253;0.0
126 | 5.582606655862442;0.0 8.745208975457812;0.0 8.407357548343455;0.0 6.1134470852794305;0.0 4.64585209250856;0.0
127 | 5.175995859481485;0.0 8.036313192259973;0.0 8.117585009983936;0.0 5.761319524863963;0.0 4.472081892770282;0.0
128 | 3.9584136470978106;0.0 7.825200290634395;0.0 8.469967107637677;0.0 5.892607699832573;0.0 4.641025148772749;0.0
129 | 4.818075927279655;0.0 8.0302912324111;0.0 7.599501972926464;0.0 6.072055726550862;0.0 4.5876643458656465;0.0
130 | 6.260529089031053;0.0 8.077717144870912;0.0 8.28666640694931;0.0 6.028679382627214;0.0 4.53283874533269;0.0
131 | 5.940781532352167;0.0 8.416726560401713;0.0 8.237489618726938;0.0 5.283535743273685;0.0 4.606649180877479;0.0
132 | 5.845886137933842;0.0 8.202278348183496;0.0 7.993688843625455;0.0 5.058112797735238;0.0 4.519874761335677;0.0
133 | 5.241786332058487;0.0 8.541875519293244;0.0 7.562032895383434;0.0 4.967352165196269;0.0 4.1732203557192245;0.0
134 | 6.189574845200824;0.0 8.67464263474137;0.0 8.06886631365028;0.0 5.474717142420248;0.0 4.518006516842553;0.0
135 | 6.21604053504652;0.0 8.605277111152615;0.0 7.645237423260006;0.0 5.2668270503124655;0.0 4.267298341930885;0.0
136 | 6.414017464556187;0.0 8.34816764477117;0.0 8.135945551374881;0.0 5.200701295479851;0.0 4.277292289039358;0.0
137 | 6.416817867012927;0.0 8.092161066261774;0.0 8.800856970337213;0.0 5.544477251062078;0.0 4.355934737116303;0.0
138 | 6.760486436987835;0.0 8.610172019705281;0.0 8.276870833883585;0.0 6.129327537731037;0.0 4.321282319090557;0.0
139 | 5.724646173812467;0.0 8.580127180711278;0.0 8.434825405207294;0.0 6.258032030663717;0.0 4.387625324730334;0.0
140 | 5.9816099481160165;0.0 8.296412371918258;0.0 8.655294155702332;0.0 5.23871896729962;0.0 4.882981414599243;0.0
141 | 6.2081257912519545;0.0 8.507435450133585;0.0 8.36904391175349;0.0 5.746220351171101;0.0 4.448282572081539;0.0
142 | 5.829682013102995;0.0 8.411247656041018;0.0 8.867340564404039;0.0 5.474488673200421;0.0 4.673439182558402;0.0
143 | 4.759668423076788;0.0 8.040765649310002;0.0 8.333342524670833;0.0 5.760514796461519;0.0 4.811277703495893;0.0
144 | 4.845488011151394;0.0 8.445983856232067;0.0 8.15992388072835;0.0 5.869907012711734;0.0 5.0316850859014;0.0
145 | 6.347782851128769;0.0 8.470778043888687;0.0 8.29158137231789;0.0 6.397575181488675;0.0 5.051183559405172;0.0
146 | 6.973275197732699;0.0 8.4022571392508;0.0 8.375536953316795;0.0 5.6223460525158995;0.0 4.619125507404;0.0
147 | 6.94802685152575;0.0 8.33402331025245;0.0 8.25683779691387;0.0 5.664649825779985;0.0 4.379478199384559;0.0
148 | 6.650654890711753;0.0 8.7539108522963;0.0 8.698038449414266;0.0 5.947410063730854;0.0 4.454832538879777;0.0
149 | 5.516125141197395;0.0 8.775996167881651;0.0 8.030865090790604;0.0 5.385232625773834;0.0 4.499198679793199;0.0
150 | 4.303981626608798;0.0 8.093966728579765;0.0 8.382871298450913;0.0 5.195544964487125;0.0 5.031124015624487;0.0
151 | 6.384693648933294;0.0 8.754712098732831;0.0 8.0243913330792;0.0 6.3426995529114345;0.0 4.905355551561107;0.0
152 | 6.528857251545034;0.0 8.24806442703848;0.0 8.565354780473612;0.0 5.8170394978974755;0.0 4.427126926259153;0.0
153 | 5.912388095902546;0.0 7.979048871198524;0.0 7.9722687966801935;0.0 5.208154685360949;0.0 4.683490919588005;0.0
154 | 5.991895951341246;0.0 8.333617868372492;0.0 8.52619826082903;0.0 5.942196861663541;0.0 4.402433822997185;0.0
155 | 5.706469342796359;0.0 8.302850550767491;0.0 8.402767001654755;0.0 5.960610270563036;0.0 4.451550191662453;0.0
156 | 6.267547326262834;0.0 7.800028083284364;0.0 8.516000439449769;0.0 5.05145351055599;0.0 4.396534533876721;0.0
157 | 5.445130028736165;0.0 8.075314330201635;0.0 8.4536467651569;0.0 5.754381607989826;0.0 4.155377486696526;0.0
158 | 5.903621350488989;0.0 8.605636523210947;0.0 8.638227933011672;0.0 4.854851923798873;0.0 4.492480157096204;0.0
159 | 6.050404344716856;0.0 8.617213062425186;0.0 8.27746532968639;0.0 6.074238840778855;0.0 4.468152392203249;0.0
160 | 5.244082655634547;0.0 8.62770810264768;0.0 8.43363888520692;0.0 6.019983473769552;0.0 4.383748547775007;0.0
161 | 6.314967210083786;0.0 8.39020422634239;0.0 8.432478087015419;0.0 5.517030631002603;0.0 4.485769981712587;0.0
162 | 5.9074808869416415;0.0 8.248278843975454;0.0 8.617416506311315;0.0 6.0646144880668444;0.0 4.52353293269217;0.0
163 | 5.850435013565329;0.0 8.416190865513343;0.0 8.32037618235627;0.0 5.679465645345254;0.0 4.450043271328489;0.0
164 | 5.5522561271041075;0.0 8.582502887768914;0.0 8.619487376482239;0.0 5.738642255884316;0.0 4.568615345471704;0.0
165 | 5.036331319562897;0.0 8.427045636468195;0.0 8.109345720000466;0.0 5.802942006580016;0.0 4.481775245482028;0.0
166 | 5.778506956387423;0.0 7.971345343491298;0.0 8.504724059358086;0.0 5.69248950121884;0.0 4.364083061619192;0.0
167 | 5.9316405393632285;0.0 8.156507977883287;0.0 7.934013414665693;0.0 5.388145386811028;0.0 4.40153696015925;0.0
168 | 6.039309917528708;0.0 7.804658426620361;0.0 8.117983160974738;0.0 5.1392059352611765;0.0 4.801751219127372;0.0
169 | 6.170699469547329;0.0 8.166662571594841;0.0 8.187049991366427;0.0 5.014114282247064;0.0 4.3751397036434305;0.0
170 | 6.522748103260685;0.0 8.181027429199968;0.0 8.126767805217593;0.0 5.501025669831553;0.0 4.057420791421391;0.0
171 | 6.170855728568853;0.0 8.507102401098539;0.0 8.34386270526472;0.0 4.952270954013661;0.0 4.248503641312122;0.0
172 | 5.521585990792665;0.0 8.467054568916035;0.0 8.183870169247225;0.0 5.90756208499452;0.0 4.1525402251389965;0.0
173 | 5.377689691352174;0.0 8.531179496169845;0.0 7.8729320959002465;0.0 5.883848003249053;0.0 4.147986837176234;0.0
174 | 4.448464426447295;0.0 8.473740869120556;0.0 8.312404727835153;0.0 5.193086087006907;0.0 4.116946137936601;0.0
175 | 5.503102482276618;0.0 7.67030173852593;0.0 8.496758001682185;0.0 5.469283550053858;0.0 4.365598509348475;0.0
176 | 6.011071782351261;0.0 8.71043119876478;0.0 8.143652358103521;0.0 5.177411744693957;0.0 4.314187859973814;0.0
177 | 6.0820648213071005;0.0 8.21947265941712;0.0 8.407812249720887;0.0 5.208425293509405;0.0 4.672655458369537;0.0
178 | 5.538784862626747;0.0 8.318690770971918;0.0 8.330316647069889;0.0 5.253897201837469;0.0 4.5031854221532965;0.0
179 | 5.712362745231777;0.0 8.16053519104992;0.0 8.271917542712785;0.0 5.749253610552796;0.0 4.581871604431159;0.0
180 | 5.904089270057046;0.0 8.139325719306951;0.0 7.778947113579367;0.0 5.676492345271865;0.0 4.500119679508153;0.0
181 | 4.615050446958616;0.0 7.719130516953383;0.0 8.281467962721857;0.0 5.088848831349739;0.0 5.064971611876151;0.0
182 | 5.883096985602169;0.0 8.078062097018105;0.0 8.356146077444128;0.0 5.843014754224962;0.0 5.005806494902836;0.0
183 | 5.48832344226718;0.0 8.724375497203852;0.0 8.239953310460157;0.0 5.70335501800308;0.0 5.502736753975782;0.0
184 | 5.8306445896884345;0.0 8.09928734348494;0.0 8.433864612644026;0.0 6.813441293314625;0.0 6.1461270423317504;0.0
185 | 4.930041776658224;0.0 8.227296077197742;0.0 7.871006035411134;0.0 5.883294139253053;0.0 4.755460667779073;0.0
186 | 6.157013365229819;0.0 8.014082887478004;0.0 7.662615752313453;0.0 5.609084800775377;0.0 4.74338062986556;0.0
187 | 6.7294327330184345;0.0 8.737987033683405;0.0 8.562916653029758;0.0 6.958776842386571;0.0 7.237650932702939;0.0
188 | 5.021397105065915;0.0 7.73065648234161;0.0 7.701687039123202;0.0 6.028560666575201;0.0 5.7488826480133355;0.0
189 | 5.781884415905817;0.0 8.819928061332076;0.0 8.299592835540228;0.0 6.040807582380932;0.0 5.761557653436427;0.0
190 | 5.981771756458309;0.0 8.078373851281814;0.0 8.022634025473934;0.0 5.624214891877459;0.0 6.517688242017894;0.0
191 | 5.789419267148446;0.0 8.381053710022728;0.0 8.402599966763809;0.0 5.2884611554783545;0.0 6.963565121591992;0.0
192 | 6.019048894273215;0.0 8.329489655960115;0.0 8.200922948591053;0.0 6.6253639978810055;0.0 7.059289271884949;0.0
193 | 5.688424650449101;0.0 8.019457453109505;0.0 8.202740960540115;0.0 6.630280798983155;0.0 5.504866638456423;0.0
194 | 4.972263420237305;0.0 8.059333862247323;0.0 7.552991660688852;0.0 6.310650616466008;0.0 4.846957668650053;0.0
195 | 6.5686776532185505;0.0 7.927232142534629;0.0 8.33565227557325;0.0 6.5976709847151;0.0 5.529784111580169;0.0
196 | 4.696641644620746;0.0 8.298029098917107;0.0 8.602883423035422;0.0 6.812782868702886;0.0 5.90006042914919;0.0
197 | 6.753817341390347;0.0 8.241394124961102;0.0 8.030782937266746;0.0 5.600154793392144;0.0 4.954678583881357;0.0
198 | 6.014621074670694;0.0 7.946690110308632;0.0 8.147741787137107;0.0 5.206848535088143;0.0 4.621915670009193;0.0
199 | 6.466594337523593;0.0 8.166913255534675;0.0 8.085823937860345;0.0 7.088822120313121;0.0 6.671064468573995;0.0
200 | 7.004319371964096;0.0 8.333536393780005;0.0 7.941193144923181;0.0 5.806832265720349;0.0 5.262822741277913;0.0
201 | 6.700657610441313;0.0 8.415243522920779;0.0 8.745605657654371;0.0 6.817488173566696;0.0 5.156028725175612;0.0
202 | 6.448747682317837;0.0 8.463989303565219;0.0 8.191493355995275;0.0 5.605972942052687;0.0 6.521988194656517;0.0
203 | 5.200613908583162;0.0 8.33007133148412;0.0 7.6371518653538315;0.0 5.71008036963858;0.0 7.156573503924501;0.0
204 | 6.184344802636733;0.0 8.111420137433422;0.0 8.247725396443165;0.0 7.5358197166247045;0.0 7.173090966151385;0.0
205 | 5.43710476561659;0.0 8.321316118020208;0.0 7.884240067670407;0.0 7.522783292138743;0.0 5.917353164422336;0.0
206 | 5.477137883710393;0.0 8.146455636624838;0.0 8.003065412414042;0.0 6.074402777663413;0.0 5.279877543790289;0.0
207 | 5.515907541573396;0.0 8.205315346907982;0.0 8.235461584800037;0.0 5.998875319052474;0.0 4.971837531279488;0.0
208 | 6.193841300446987;0.0 8.247756181129898;0.0 7.635868249264561;0.0 6.194795736902253;0.0 5.307760989942205;0.0
209 | 5.927446034851227;0.0 8.38266160743442;0.0 8.380975656102496;0.0 6.117270007331506;0.0 5.2992836429605354;0.0
210 | 5.786793936210037;0.0 8.584918466727189;0.0 8.748455885270145;0.0 5.2462784054309335;0.0 5.971471632973264;0.0
211 | 6.426646552100709;0.0 8.616602442543071;0.0 8.183890688270006;0.0 5.879317290852897;0.0 5.649564586342327;0.0
212 | 6.354793643235332;0.0 8.127308333408529;0.0 8.576714338378514;0.0 7.769886704284761;0.0 7.7260317909056315;0.0
213 | 4.09950179635173;0.0 8.46942488077457;0.0 8.568094490422771;0.0 8.416561941143858;0.0 6.647026913359418;0.0
214 | 6.2406843982748965;0.0 8.459501482121729;0.0 7.808460318286083;0.0 8.699118540464804;0.0 6.4776009259851985;0.0
215 | 7.1575736728639;0.0 8.10023446191008;0.0 8.193903883710238;0.0 8.030598048359144;0.0 6.437117079401015;0.0
216 | 5.216966467064887;0.0 8.121775230968662;0.0 8.461506935879136;0.0 7.914943937387404;0.0 6.137203092094755;0.0
217 | 6.35983843487706;0.0 8.204433375613089;0.0 8.7988993300629;0.0 7.971102679614343;0.0 7.653385054025205;0.0
218 | 5.783495741109008;0.0 8.265815528372883;0.0 9.003955588389662;0.0 7.064759169720704;0.0 7.652924983484916;0.0
219 | 6.490319372471953;0.0 7.999540369573685;0.0 8.207039661362405;0.0 7.37687364727434;0.0 7.545508375764035;0.0
220 | 5.241558046433703;0.0 8.39513119170725;0.0 8.066153921356594;0.0 7.256202515082821;0.0 7.181689927146401;0.0
221 | 4.534286667548788;0.0 8.890470519332126;0.0 8.627502254016417;0.0 6.921864289414523;0.0 6.6391666752532235;0.0
222 | 5.026564421620763;0.0 8.118671684544358;0.0 8.126864000576234;0.0 7.146456846917884;0.0 6.11037568207994;0.0
223 | 5.101177361327671;0.0 8.33160354480917;0.0 8.31962021621415;0.0 7.594686225018605;0.0 5.966266414034341;0.0
224 | 5.631859471469901;0.0 8.274433511125451;0.0 8.235395322586072;0.0 7.370589457746957;0.0 5.485278809243314;0.0
225 | 5.0553294024727915;0.0 8.22537335989146;0.0 8.154263134783866;0.0 6.794378437216705;0.0 5.241188008044741;0.0
226 | 4.758924313531498;0.0 8.074868711147557;0.0 8.072853823420425;0.0 6.282891082874685;0.0 4.662638298709869;0.0
227 | 4.714393812430216;0.0 8.630627663228577;0.0 8.202713128549393;0.0 6.111100837771921;0.0 5.082549957180467;0.0
228 | 4.401355507338546;0.0 8.168951163670842;0.0 8.140347402951527;0.0 5.84173477315503;0.0 4.8049372845747005;0.0
229 | 4.483396541080817;0.0 7.8802899796250845;0.0 8.234829191566579;0.0 5.8471427957037365;0.0 4.505141825644688;0.0
230 | 4.964878294158919;0.0 8.140904979629099;0.0 8.096907854851029;0.0 6.264148113644292;0.0 4.629251848852354;0.0
231 | 5.354204712528305;0.0 8.065647791141973;0.0 8.448676344301829;0.0 6.212698953162688;0.0 4.5321012518542485;0.0
232 | 5.113066604947712;0.0 7.882011725419603;0.0 7.72161280051396;0.0 6.280571503721213;0.0 4.5627362767268185;0.0
233 | 4.9705865788614485;0.0 8.097099580082116;0.0 8.338409066955785;0.0 5.955509744907529;0.0 4.98871186728811;0.0
234 | 6.249872999324205;0.0 8.132291483251164;0.0 8.203279983643569;0.0 5.909396867014083;0.0 4.5026943184245045;0.0
235 | 5.679479802583985;0.0 9.03246917815084;0.0 9.20020215365682;0.0 5.779967821210187;0.0 6.929032716722192;0.0
236 | 8.539673957197959;0.0 9.003627149639199;0.0 9.46478577464417;0.0 8.93897861643799;0.0 8.441790391558126;0.0
237 | 7.339401862476689;0.0 9.091461292421675;0.0 8.666574599173563;0.0 7.5829029835539465;0.0 6.356773171977835;0.0
238 | 6.179614304221195;0.0 8.756063830204186;0.0 8.407832800882654;0.0 6.449822862552805;0.0 4.99257066989339;0.0
239 | 6.117160699146181;0.0 8.465748512906021;0.0 7.9419758038122925;0.0 5.717337265134019;0.0 5.01550360757608;0.0
240 | 6.1918796357706185;0.0 8.517484525518753;0.0 8.440037008835882;0.0 5.434156607711338;0.0 4.6746407944503625;0.0
241 | 8.107311562619438;0.0 9.054512316917954;0.0 9.373527540180053;0.0 9.081542350834829;0.0 8.340412636796115;0.0
242 | 6.8192800585857025;0.0 8.176596655917207;0.0 8.3731132241923;0.0 7.137961094205004;0.0 6.951769552874486;0.0
243 | 5.679399768389249;0.0 8.305449857927064;0.0 8.36377413337518;0.0 5.503877808024116;0.0 5.695596553870491;0.0
244 | 4.764788071903808;0.0 7.614878405415259;0.0 8.419724433573842;0.0 5.972772739979598;0.0 5.222156069196278;0.0
245 | 7.423171987005323;0.0 7.945967582211525;0.0 8.168631545465429;0.0 6.727648298512323;0.0 6.218630887669414;0.0
246 | 6.8525633103330374;0.0 8.361153362891768;0.0 8.238479511033082;0.0 7.530753409308909;0.0 6.8941860461505025;0.0
247 | 8.09714463952834;0.0 8.74742472289483;0.0 7.781960708499761;0.0 6.592884949805617;0.0 7.375184326715807;0.0
248 | 8.014447859959695;0.0 9.680613030632282;0.0 8.142197689209306;0.0 6.300342062447666;0.0 6.704531363855435;0.0
249 | 6.63738772118296;0.0 10.049670677510568;0.0 9.338995066151584;0.0 8.091006866415173;0.0 6.7106940005265505;0.0
250 | 8.106129593495272;0.0 9.506064186351043;0.0 9.21882743252612;0.0 6.328550147704135;0.0 6.846662920086543;0.0
251 |
--------------------------------------------------------------------------------
/src/model/Complex.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | /*************************************************************************
4 | * Compilation: javac Complex.java Execution: java Complex
5 | *
6 | * Data type for complex numbers.
7 | *
8 | * The data type is "immutable" so once you create and initialize a Complex
9 | * object, you cannot change it. The "final" keyword when declaring re and im
10 | * enforces this rule, making it a compile-time error to change the .re or .im
11 | * fields after they've been initialized.
12 | *
13 | * % java Complex a = 5.0 + 6.0i b = -3.0 + 4.0i Re(a) = 5.0 Im(a) = 6.0 b + a =
14 | * 2.0 + 10.0i a - b = 8.0 + 2.0i a * b = -39.0 + 2.0i b * a = -39.0 + 2.0i a /
15 | * b = 0.36 - 1.52i (a / b) * b = 5.0 + 6.0i conj(a) = 5.0 - 6.0i |a| =
16 | * 7.810249675906654 tan(a) = -6.685231390246571E-6 + 1.0000103108981198i
17 | *
18 | *************************************************************************/
19 |
20 | public class Complex {
21 | private final double re; // the real part
22 | private final double im; // the imaginary part
23 |
24 | // create a new object with the given real and imaginary parts
25 | public Complex(double real, double imag) {
26 | re = real;
27 | im = imag;
28 | }
29 |
30 | // return a string representation of the invoking Complex object
31 | public String toString() {
32 | if (im == 0)
33 | return re + "";
34 | if (re == 0)
35 | return im + "i";
36 | if (im < 0)
37 | return re + " - " + (-im) + "i";
38 | return re + " + " + im + "i";
39 | }
40 |
41 | // return abs/modulus/magnitude and angle/phase/argument
42 | public double abs() {
43 | return Math.hypot(re, im);
44 | } // Math.sqrt(re*re + im*im)
45 |
46 | public double phase() {
47 | return Math.atan2(im, re);
48 | } // between -pi and pi
49 |
50 | // return a new Complex object whose value is (this + b)
51 | public Complex plus(Complex b) {
52 | Complex a = this; // invoking object
53 | double real = a.re + b.re;
54 | double imag = a.im + b.im;
55 | return new Complex(real, imag);
56 | }
57 |
58 | // return a new Complex object whose value is (this - b)
59 | public Complex minus(Complex b) {
60 | Complex a = this;
61 | double real = a.re - b.re;
62 | double imag = a.im - b.im;
63 | return new Complex(real, imag);
64 | }
65 |
66 | // return a new Complex object whose value is (this * b)
67 | public Complex times(Complex b) {
68 | Complex a = this;
69 | double real = a.re * b.re - a.im * b.im;
70 | double imag = a.re * b.im + a.im * b.re;
71 | return new Complex(real, imag);
72 | }
73 |
74 | // scalar multiplication
75 | // return a new object whose value is (this * alpha)
76 | public Complex times(double alpha) {
77 | return new Complex(alpha * re, alpha * im);
78 | }
79 |
80 | // return a new Complex object whose value is the conjugate of this
81 | public Complex conjugate() {
82 | return new Complex(re, -im);
83 | }
84 |
85 | // return a new Complex object whose value is the reciprocal of this
86 | public Complex reciprocal() {
87 | double scale = re * re + im * im;
88 | return new Complex(re / scale, -im / scale);
89 | }
90 |
91 | // return the real or imaginary part
92 | public double re() {
93 | return re;
94 | }
95 |
96 | public double im() {
97 | return im;
98 | }
99 |
100 | // return a / b
101 | public Complex divides(Complex b) {
102 | Complex a = this;
103 | return a.times(b.reciprocal());
104 | }
105 |
106 | // return a new Complex object whose value is the complex exponential of
107 | // this
108 | public Complex exp() {
109 | return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re)
110 | * Math.sin(im));
111 | }
112 |
113 | // return a new Complex object whose value is the complex sine of this
114 | public Complex sin() {
115 | return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re)
116 | * Math.sinh(im));
117 | }
118 |
119 | // return a new Complex object whose value is the complex cosine of this
120 | public Complex cos() {
121 | return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re)
122 | * Math.sinh(im));
123 | }
124 |
125 | // return a new Complex object whose value is the complex tangent of this
126 | public Complex tan() {
127 | return sin().divides(cos());
128 | }
129 |
130 | // a static version of plus
131 | public static Complex plus(Complex a, Complex b) {
132 | double real = a.re + b.re;
133 | double imag = a.im + b.im;
134 | Complex sum = new Complex(real, imag);
135 | return sum;
136 | }
137 |
138 | // sample client for testing
139 | // public static void main(String[] args) {
140 | // Complex a = new Complex(5.0, 6.0);
141 | // Complex b = new Complex(-3.0, 4.0);
142 | //
143 | // System.out.println("a = " + a);
144 | // System.out.println("b = " + b);
145 | // System.out.println("Re(a) = " + a.re());
146 | // System.out.println("Im(a) = " + a.im());
147 | // System.out.println("b + a = " + b.plus(a));
148 | // System.out.println("a - b = " + a.minus(b));
149 | // System.out.println("a * b = " + a.times(b));
150 | // System.out.println("b * a = " + b.times(a));
151 | // System.out.println("a / b = " + a.divides(b));
152 | // System.out.println("(a / b) * b = " + a.divides(b).times(b));
153 | // System.out.println("conj(a) = " + a.conjugate());
154 | // System.out.println("|a| = " + a.abs());
155 | // System.out.println("tan(a) = " + a.tan());
156 | // }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/src/model/DataPoint.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | public class DataPoint {
4 |
5 | private int time;
6 | private int songId;
7 |
8 | public DataPoint(int songId, int time) {
9 | this.songId = songId;
10 | this.time = time;
11 | }
12 |
13 | public int getTime() {
14 | return time;
15 | }
16 |
17 | public int getSongId() {
18 | return songId;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/model/FFT.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 |
4 | /*************************************************************************
5 | * Compilation: javac FFT.java Execution: java FFT N Dependencies: Complex.java
6 | *
7 | * Compute the FFT and inverse FFT of a length N complex sequence. Bare bones
8 | * implementation that runs in O(N log N) time. Our goal is to optimize the
9 | * clarity of the code, rather than performance.
10 | *
11 | * Limitations ----------- - assumes N is a power of 2
12 | *
13 | * - not the most memory efficient algorithm (because it uses an object type for
14 | * representing complex numbers and because it re-allocates memory for the
15 | * subarray, instead of doing in-place or reusing a single temporary array)
16 | *
17 | *************************************************************************/
18 |
19 | public class FFT {
20 |
21 | // compute the FFT of x[], assuming its length is a power of 2
22 | public static Complex[] fft(Complex[] x) {
23 | int N = x.length;
24 |
25 | // base case
26 | if (N == 1)
27 | return new Complex[] { x[0] };
28 |
29 | // radix 2 Cooley-Tukey FFT
30 | if (N % 2 != 0) {
31 | throw new RuntimeException("N is not a power of 2");
32 | }
33 |
34 | // fft of even terms
35 | Complex[] even = new Complex[N / 2];
36 | for (int k = 0; k < N / 2; k++) {
37 | even[k] = x[2 * k];
38 | }
39 | Complex[] q = fft(even);
40 |
41 | // fft of odd terms
42 | Complex[] odd = even; // reuse the array
43 | for (int k = 0; k < N / 2; k++) {
44 | odd[k] = x[2 * k + 1];
45 | }
46 | Complex[] r = fft(odd);
47 |
48 | // combine
49 | Complex[] y = new Complex[N];
50 | for (int k = 0; k < N / 2; k++) {
51 | double kth = -2 * k * Math.PI / N;
52 | Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
53 | y[k] = q[k].plus(wk.times(r[k]));
54 | y[k + N / 2] = q[k].minus(wk.times(r[k]));
55 | }
56 | return y;
57 | }
58 |
59 | // compute the inverse FFT of x[], assuming its length is a power of 2
60 | public static Complex[] ifft(Complex[] x) {
61 | int N = x.length;
62 | Complex[] y = new Complex[N];
63 |
64 | // take conjugate
65 | for (int i = 0; i < N; i++) {
66 | y[i] = x[i].conjugate();
67 | }
68 |
69 | // compute forward FFT
70 | y = fft(y);
71 |
72 | // take conjugate again
73 | for (int i = 0; i < N; i++) {
74 | y[i] = y[i].conjugate();
75 | }
76 |
77 | // divide by N
78 | for (int i = 0; i < N; i++) {
79 | y[i] = y[i].times(1.0 / N);
80 | }
81 |
82 | return y;
83 |
84 | }
85 |
86 | // compute the circular convolution of x and y
87 | public static Complex[] cconvolve(Complex[] x, Complex[] y) {
88 |
89 | // should probably pad x and y with 0s so that they have same length
90 | // and are powers of 2
91 | if (x.length != y.length) {
92 | throw new RuntimeException("Dimensions don't agree");
93 | }
94 |
95 | int N = x.length;
96 |
97 | // compute FFT of each sequence
98 | Complex[] a = fft(x);
99 | Complex[] b = fft(y);
100 |
101 | // point-wise multiply
102 | Complex[] c = new Complex[N];
103 | for (int i = 0; i < N; i++) {
104 | c[i] = a[i].times(b[i]);
105 | }
106 |
107 | // compute inverse FFT
108 | return ifft(c);
109 | }
110 |
111 | // compute the linear convolution of x and y
112 | public static Complex[] convolve(Complex[] x, Complex[] y) {
113 | Complex ZERO = new Complex(0, 0);
114 |
115 | Complex[] a = new Complex[2 * x.length];
116 | for (int i = 0; i < x.length; i++)
117 | a[i] = x[i];
118 | for (int i = x.length; i < 2 * x.length; i++)
119 | a[i] = ZERO;
120 |
121 | Complex[] b = new Complex[2 * y.length];
122 | for (int i = 0; i < y.length; i++)
123 | b[i] = y[i];
124 | for (int i = y.length; i < 2 * y.length; i++)
125 | b[i] = ZERO;
126 |
127 | return cconvolve(a, b);
128 | }
129 |
130 | // display an array of Complex numbers to standard output
131 | public static void show(Complex[] x, String title) {
132 | System.out.println(title);
133 | System.out.println("-------------------");
134 | for (int i = 0; i < x.length; i++) {
135 | System.out.println(x[i]);
136 | }
137 | System.out.println();
138 | }
139 |
140 | /*********************************************************************
141 | * Test client and sample execution
142 | *
143 | * % java FFT 4 x ------------------- -0.03480425839330703
144 | * 0.07910192950176387 0.7233322451735928 0.1659819820667019
145 | *
146 | * y = fft(x) ------------------- 0.9336118983487516 -0.7581365035668999 +
147 | * 0.08688005256493803i 0.44344407521182005 -0.7581365035668999 -
148 | * 0.08688005256493803i
149 | *
150 | * z = ifft(y) ------------------- -0.03480425839330703 0.07910192950176387
151 | * + 2.6599344570851287E-18i 0.7233322451735928 0.1659819820667019 -
152 | * 2.6599344570851287E-18i
153 | *
154 | * c = cconvolve(x, x) ------------------- 0.5506798633981853
155 | * 0.23461407150576394 - 4.033186818023279E-18i -0.016542951108772352
156 | * 0.10288019294318276 + 4.033186818023279E-18i
157 | *
158 | * d = convolve(x, x) ------------------- 0.001211336402308083 -
159 | * 3.122502256758253E-17i -0.005506167987577068 - 5.058885073636224E-17i
160 | * -0.044092969479563274 + 2.1934338938072244E-18i 0.10288019294318276 -
161 | * 3.6147323062478115E-17i 0.5494685269958772 + 3.122502256758253E-17i
162 | * 0.240120239493341 + 4.655566391833896E-17i 0.02755001837079092 -
163 | * 2.1934338938072244E-18i 4.01805098805014E-17i
164 | *
165 | *********************************************************************/
166 |
167 | }
--------------------------------------------------------------------------------
/src/view/AudioRecognizerWindow.java:
--------------------------------------------------------------------------------
1 | package view;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Button;
5 | import java.awt.Color;
6 | import java.awt.Dimension;
7 | import java.awt.FlowLayout;
8 | import java.awt.Graphics;
9 | import java.awt.Graphics2D;
10 | import java.awt.event.ActionEvent;
11 | import java.awt.event.ActionListener;
12 | import java.io.BufferedWriter;
13 | import java.io.ByteArrayOutputStream;
14 | import java.io.File;
15 | import java.io.FileWriter;
16 | import java.io.IOException;
17 | import java.io.OutputStream;
18 | import java.net.URL;
19 | import java.util.ArrayList;
20 | import java.util.Comparator;
21 | import java.util.HashMap;
22 | import java.util.Iterator;
23 | import java.util.List;
24 | import java.util.Map;
25 | import java.util.Map.Entry;
26 |
27 | import javax.sound.sampled.AudioFormat;
28 | import javax.sound.sampled.AudioInputStream;
29 | import javax.sound.sampled.AudioSystem;
30 | import javax.sound.sampled.DataLine;
31 | import javax.sound.sampled.LineUnavailableException;
32 | import javax.sound.sampled.SourceDataLine;
33 | import javax.sound.sampled.TargetDataLine;
34 | import javax.sound.sampled.UnsupportedAudioFileException;
35 | import javax.swing.JFrame;
36 | import javax.swing.JLabel;
37 | import javax.swing.JTextField;
38 | import javax.swing.SwingConstants;
39 |
40 | import model.Complex;
41 | import model.DataPoint;
42 | import model.FFT;
43 |
44 | import org.tritonus.sampled.convert.PCM2PCMConversionProvider;
45 | import org.tritonus.share.sampled.convert.*;
46 |
47 | public class AudioRecognizerWindow extends JFrame {
48 |
49 | boolean running = false;
50 | double highscores[][];
51 | double recordPoints[][];
52 | long points[][];
53 | Map> hashMap;
54 | Map> matchMap; // Map>
56 | long nrSong = 0;
57 | JTextField fileTextField = null;
58 |
59 | private AudioFormat getFormat() {
60 | float sampleRate = 44100;
61 | int sampleSizeInBits = 8;
62 | int channels = 1; // mono
63 | boolean signed = true;
64 | boolean bigEndian = true;
65 | return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
66 | bigEndian);
67 | }
68 |
69 | private synchronized SourceDataLine getLine(AudioFormat audioFormat)
70 | throws LineUnavailableException {
71 | SourceDataLine res = null;
72 | DataLine.Info info = new DataLine.Info(SourceDataLine.class,
73 | audioFormat);
74 | res = (SourceDataLine) AudioSystem.getLine(info);
75 | res.open(audioFormat);
76 | return res;
77 | }
78 |
79 | private synchronized void rawplay(AudioFormat targetFormat,
80 | AudioInputStream din) throws IOException, LineUnavailableException {
81 | byte[] data = new byte[4096];
82 | SourceDataLine line = getLine(targetFormat);
83 | if (line != null) {
84 | // Start
85 | line.start();
86 | int nBytesRead = 0, nBytesWritten = 0;
87 | while (nBytesRead != -1) {
88 | nBytesRead = din.read(data, 0, data.length);
89 | if (nBytesRead != -1) {
90 | nBytesWritten = line.write(data, 0, nBytesRead);
91 | }
92 |
93 | }
94 | // Stop
95 | line.drain();
96 | line.stop();
97 | line.close();
98 | din.close();
99 | }
100 |
101 | }
102 |
103 | private void listenSound(long songId, boolean isMatching)
104 | throws LineUnavailableException, IOException,
105 | UnsupportedAudioFileException {
106 |
107 | AudioFormat formatTmp = null;
108 | TargetDataLine lineTmp = null;
109 | String filePath = fileTextField.getText();
110 | AudioInputStream din = null;
111 | AudioInputStream outDin = null;
112 | PCM2PCMConversionProvider conversionProvider = new PCM2PCMConversionProvider();
113 | boolean isMicrophone = false;
114 |
115 | if (filePath == null || filePath.equals("") || isMatching) {
116 |
117 | formatTmp = getFormat(); // Fill AudioFormat with the wanted
118 | // settings
119 | DataLine.Info info = new DataLine.Info(TargetDataLine.class,
120 | formatTmp);
121 | lineTmp = (TargetDataLine) AudioSystem.getLine(info);
122 | isMicrophone = true;
123 | } else {
124 | AudioInputStream in;
125 |
126 | if (filePath.contains("http")) {
127 | URL url = new URL(filePath);
128 | in = AudioSystem.getAudioInputStream(url);
129 | } else {
130 | File file = new File(filePath);
131 | in = AudioSystem.getAudioInputStream(file);
132 | }
133 |
134 | AudioFormat baseFormat = in.getFormat();
135 |
136 | System.out.println(baseFormat.toString());
137 |
138 | AudioFormat decodedFormat = new AudioFormat(
139 | AudioFormat.Encoding.PCM_SIGNED,
140 | baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
141 | baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
142 | false);
143 |
144 | din = AudioSystem.getAudioInputStream(decodedFormat, in);
145 |
146 | if (!conversionProvider.isConversionSupported(getFormat(),
147 | decodedFormat)) {
148 | System.out.println("Conversion is not supported");
149 | }
150 |
151 | System.out.println(decodedFormat.toString());
152 |
153 | outDin = conversionProvider.getAudioInputStream(getFormat(), din);
154 | formatTmp = decodedFormat;
155 |
156 | DataLine.Info info = new DataLine.Info(TargetDataLine.class,
157 | formatTmp);
158 | lineTmp = (TargetDataLine) AudioSystem.getLine(info);
159 | }
160 |
161 | final AudioFormat format = formatTmp;
162 | final TargetDataLine line = lineTmp;
163 | final boolean isMicro = isMicrophone;
164 | final AudioInputStream outDinSound = outDin;
165 |
166 | if (isMicro) {
167 | try {
168 | line.open(format);
169 | line.start();
170 | } catch (LineUnavailableException e) {
171 | e.printStackTrace();
172 | }
173 | }
174 |
175 | final long sId = songId;
176 | final boolean isMatch = isMatching;
177 |
178 | Thread listeningThread = new Thread(new Runnable() {
179 | public void run() {
180 | ByteArrayOutputStream out = new ByteArrayOutputStream();
181 | running = true;
182 | int n = 0;
183 | byte[] buffer = new byte[(int) 1024];
184 |
185 | try {
186 | while (running) {
187 | n++;
188 | if (n > 1000)
189 | break;
190 |
191 | int count = 0;
192 | if (isMicro) {
193 | count = line.read(buffer, 0, 1024);
194 | } else {
195 | count = outDinSound.read(buffer, 0, 1024);
196 | }
197 | if (count > 0) {
198 | out.write(buffer, 0, count);
199 | }
200 | }
201 |
202 | byte b[] = out.toByteArray();
203 | for (int i = 0; i < b.length; i++) {
204 | System.out.println(b[i]);
205 | }
206 |
207 | try {
208 | makeSpectrum(out, sId, isMatch);
209 |
210 | FileWriter fstream = new FileWriter("out.txt");
211 | BufferedWriter outFile = new BufferedWriter(fstream);
212 |
213 | byte bytes[] = out.toByteArray();
214 | for (int i = 0; i < b.length; i++) {
215 | outFile.write("" + b[i] + ";");
216 | }
217 | outFile.close();
218 |
219 | } catch (Exception e) {
220 | System.err.println("Error: " + e.getMessage());
221 | }
222 |
223 | out.close();
224 | line.close();
225 | } catch (IOException e) {
226 | System.err.println("I/O problems: " + e);
227 | System.exit(-1);
228 | }
229 |
230 | }
231 |
232 | });
233 |
234 | listeningThread.start();
235 | }
236 |
237 | void makeSpectrum(ByteArrayOutputStream out, long songId, boolean isMatching) {
238 | byte audio[] = out.toByteArray();
239 |
240 | final int totalSize = audio.length;
241 |
242 | int amountPossible = totalSize / 4096;
243 |
244 | // When turning into frequency domain we'll need complex numbers:
245 | Complex[][] results = new Complex[amountPossible][];
246 |
247 | // For all the chunks:
248 | for (int times = 0; times < amountPossible; times++) {
249 | Complex[] complex = new Complex[4096];
250 | for (int i = 0; i < 4096; i++) {
251 | // Put the time domain data into a complex number with imaginary
252 | // part as 0:
253 | complex[i] = new Complex(audio[(times * 4096) + i], 0);
254 | }
255 | // Perform FFT analysis on the chunk:
256 | results[times] = FFT.fft(complex);
257 | }
258 | determineKeyPoints(results, songId, isMatching);
259 | JFrame spectrumView = new SpectrumView(results, 4096, highscores,
260 | recordPoints);
261 | spectrumView.setVisible(true);
262 | }
263 |
264 | public final int UPPER_LIMIT = 300;
265 | public final int LOWER_LIMIT = 40;
266 |
267 | public final int[] RANGE = new int[] { 40, 80, 120, 180, UPPER_LIMIT + 1 };
268 |
269 | // Find out in which range
270 | public int getIndex(int freq) {
271 | int i = 0;
272 | while (RANGE[i] < freq)
273 | i++;
274 | return i;
275 | }
276 |
277 | void determineKeyPoints(Complex[][] results, long songId, boolean isMatching) {
278 | this.matchMap = new HashMap>();
279 |
280 | FileWriter fstream = null;
281 | try {
282 | fstream = new FileWriter("result.txt");
283 | } catch (IOException e1) {
284 | e1.printStackTrace();
285 | }
286 | BufferedWriter outFile = new BufferedWriter(fstream);
287 |
288 | highscores = new double[results.length][5];
289 | for (int i = 0; i < results.length; i++) {
290 | for (int j = 0; j < 5; j++) {
291 | highscores[i][j] = 0;
292 | }
293 | }
294 |
295 | recordPoints = new double[results.length][UPPER_LIMIT];
296 | for (int i = 0; i < results.length; i++) {
297 | for (int j = 0; j < UPPER_LIMIT; j++) {
298 | recordPoints[i][j] = 0;
299 | }
300 | }
301 |
302 | points = new long[results.length][5];
303 | for (int i = 0; i < results.length; i++) {
304 | for (int j = 0; j < 5; j++) {
305 | points[i][j] = 0;
306 | }
307 | }
308 |
309 | for (int t = 0; t < results.length; t++) {
310 | for (int freq = LOWER_LIMIT; freq < UPPER_LIMIT - 1; freq++) {
311 | // Get the magnitude:
312 | double mag = Math.log(results[t][freq].abs() + 1);
313 |
314 | // Find out which range we are in:
315 | int index = getIndex(freq);
316 |
317 | // Save the highest magnitude and corresponding frequency:
318 | if (mag > highscores[t][index]) {
319 | highscores[t][index] = mag;
320 | recordPoints[t][freq] = 1;
321 | points[t][index] = freq;
322 | }
323 | }
324 |
325 | try {
326 | for (int k = 0; k < 5; k++) {
327 | outFile.write("" + highscores[t][k] + ";"
328 | + recordPoints[t][k] + "\t");
329 | }
330 | outFile.write("\n");
331 |
332 | } catch (IOException e) {
333 | e.printStackTrace();
334 | }
335 |
336 | long h = hash(points[t][0], points[t][1], points[t][2],
337 | points[t][3]);
338 |
339 | if (isMatching) {
340 | List listPoints;
341 |
342 | if ((listPoints = hashMap.get(h)) != null) {
343 | for (DataPoint dP : listPoints) {
344 | int offset = Math.abs(dP.getTime() - t);
345 | Map tmpMap = null;
346 | if ((tmpMap = this.matchMap.get(dP.getSongId())) == null) {
347 | tmpMap = new HashMap();
348 | tmpMap.put(offset, 1);
349 | matchMap.put(dP.getSongId(), tmpMap);
350 | } else {
351 | Integer count = tmpMap.get(offset);
352 | if (count == null) {
353 | tmpMap.put(offset, new Integer(1));
354 | } else {
355 | tmpMap.put(offset, new Integer(count + 1));
356 | }
357 | }
358 | }
359 | }
360 | } else {
361 | List listPoints = null;
362 | if ((listPoints = hashMap.get(h)) == null) {
363 | listPoints = new ArrayList();
364 | DataPoint point = new DataPoint((int) songId, t);
365 | listPoints.add(point);
366 | hashMap.put(h, listPoints);
367 | } else {
368 | DataPoint point = new DataPoint((int) songId, t);
369 | listPoints.add(point);
370 | }
371 | }
372 | }
373 | try {
374 | outFile.close();
375 | } catch (IOException e) {
376 | e.printStackTrace();
377 | }
378 | }
379 |
380 | AudioRecognizerWindow(String windowName) {
381 | super(windowName);
382 | }
383 |
384 | private static final int FUZ_FACTOR = 2;
385 |
386 | private long hash(long p1, long p2, long p3, long p4) {
387 | return (p4 - (p4 % FUZ_FACTOR)) * 100000000 + (p3 - (p3 % FUZ_FACTOR))
388 | * 100000 + (p2 - (p2 % FUZ_FACTOR)) * 100
389 | + (p1 - (p1 % FUZ_FACTOR));
390 | }
391 |
392 | public void createWindow() {
393 |
394 | this.hashMap = new HashMap>();
395 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
396 | Button buttonStart = new Button("Start");
397 | Button buttonStop = new Button("Stop");
398 | Button buttonMatch = new Button("Match");
399 | Button buttonStartMatch = new Button("Start Match");
400 | Button buttonStopMatch = new Button("Stop Match");
401 | fileTextField = new JTextField(20);
402 |
403 | fileTextField.setText("/home/wiktor/audio/billy.mp3");
404 |
405 | buttonStart.addActionListener(new ActionListener() {
406 | public void actionPerformed(ActionEvent e) {
407 | try {
408 | try {
409 | listenSound(nrSong, false);
410 | } catch (IOException e1) {
411 | e1.printStackTrace();
412 | } catch (UnsupportedAudioFileException e1) {
413 | e1.printStackTrace();
414 | }
415 | nrSong++;
416 | } catch (LineUnavailableException ex) {
417 | ex.printStackTrace();
418 | }
419 | }
420 | });
421 |
422 | buttonStop.addActionListener(new ActionListener() {
423 | public void actionPerformed(ActionEvent e) {
424 | running = false;
425 | }
426 | });
427 |
428 | buttonStartMatch.addActionListener(new ActionListener() {
429 | public void actionPerformed(ActionEvent e) {
430 | try {
431 | try {
432 | listenSound(nrSong, true);
433 | } catch (IOException e1) {
434 | e1.printStackTrace();
435 | } catch (UnsupportedAudioFileException e1) {
436 | e1.printStackTrace();
437 | }
438 | } catch (LineUnavailableException ex) {
439 | ex.printStackTrace();
440 | }
441 | }
442 | });
443 |
444 | buttonStopMatch.addActionListener(new ActionListener() {
445 | public void actionPerformed(ActionEvent e) {
446 | running = false;
447 | }
448 | });
449 |
450 | buttonMatch.addActionListener(new ActionListener() {
451 | public void actionPerformed(ActionEvent e) {
452 | List listPoints;
453 | int bestCount = 0;
454 | int bestSong = -1;
455 |
456 | for (int id = 0; id < nrSong; id++) {
457 |
458 | System.out.println("For song id: " + id);
459 | Map tmpMap = matchMap.get(id);
460 | int bestCountForSong = 0;
461 |
462 | for (Map.Entry entry : tmpMap.entrySet()) {
463 | if (entry.getValue() > bestCountForSong) {
464 | bestCountForSong = entry.getValue();
465 | }
466 | System.out.println("Time offset = " + entry.getKey()
467 | + ", Count = " + entry.getValue());
468 | }
469 |
470 | if (bestCountForSong > bestCount) {
471 | bestCount = bestCountForSong;
472 | bestSong = id;
473 | }
474 | }
475 |
476 | System.out.println("Best song id: " + bestSong);
477 | }
478 | });
479 |
480 | this.add(buttonStart);
481 | this.add(buttonStop);
482 | this.add(buttonStartMatch);
483 | this.add(buttonStopMatch);
484 | this.add(buttonMatch);
485 | this.add(fileTextField);
486 | this.setLayout(new FlowLayout());
487 | this.setSize(300, 100);
488 | this.setVisible(true);
489 | }
490 | }
491 |
--------------------------------------------------------------------------------
/src/view/MainView.java:
--------------------------------------------------------------------------------
1 | package view;
2 |
3 | import java.awt.*;
4 | import javax.swing.*;
5 |
6 | public class MainView {
7 | /**
8 | * @param args
9 | */
10 | public static void main(String[] args) {
11 | AudioRecognizerWindow audioWindow = new AudioRecognizerWindow(
12 | "Audio Recognizer");
13 | audioWindow.createWindow();
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/view/SpectrumView.java:
--------------------------------------------------------------------------------
1 | package view;
2 |
3 | import java.awt.Color;
4 | import java.awt.FlowLayout;
5 | import java.awt.Graphics;
6 | import java.awt.Graphics2D;
7 |
8 | import model.Complex;
9 |
10 | public class SpectrumView extends javax.swing.JFrame {
11 |
12 | Complex[][] results = null;
13 | int size;
14 | double highscores[][];
15 | double recordPoints[][];
16 |
17 | /**
18 | * Creates a new instance of Java2DFrame
19 | */
20 | public SpectrumView(Complex[][] results, int size, double highscores[][],
21 | double recordPoints[][]) {
22 | this.results = results;
23 | this.size = size;
24 | this.highscores = highscores;
25 | this.recordPoints = recordPoints;
26 | this.setLayout(new FlowLayout());
27 | this.setSize(400, 800);
28 | }
29 |
30 | /**
31 | * This is the method where the String is drawn.
32 | *
33 | * @param g
34 | * The graphics object
35 | */
36 | public void paint(Graphics g) {
37 | Graphics2D g2d = (Graphics2D) g;
38 |
39 | int blockSizeX = 2;
40 | int blockSizeY = 3;
41 | size = 500;
42 | for (int i = 0; i < results.length; i++) {
43 | int freq = 1;
44 | for (int line = 1; line < size; line++) {
45 | // To get the magnitude of the sound at a given frequency slice
46 | // get the abs() from the complex number.
47 | // In this case I use Math.log to get a more managable number
48 | // (used for color)
49 | double magnitude = Math.log(results[i][freq].abs() + 1);
50 | // The more blue in the color the more intensity for a given
51 | // frequency point:
52 | g2d.setColor(new Color(0, (int) magnitude * 10,
53 | (int) magnitude * 20));
54 |
55 | // if (freq < 300 /* && recordPoints[i][freq] == 1 */) {
56 | // g2d.setColor(Color.RED);
57 | // }
58 |
59 | // Fill:
60 | g2d.fillRect(i * blockSizeX, (size - line) * blockSizeY,
61 | blockSizeX, blockSizeY);
62 |
63 | // I used a improviced logarithmic scale and normal scale:
64 | if (/* logModeEnabled */false && (Math.log10(line) * Math
65 | .log10(line)) > 1) {
66 | freq += (int) (Math.log10(line) * Math.log10(line));
67 | } else {
68 | freq++;
69 | }
70 | }
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------