1 // Copyright 2004 "Gilles Degottex"
3 // This file is part of "Music"
5 // "Music" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
10 // "Music" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ScoreGenerator.h"
28 #include <CppAddons/Math.h>
29 //#include <CppAddons/String.h>
30 //using namespace String;
31 #include <CppAddons/Random.h>
38 void GenerateScore( vector<double>& buffer, // the score's wav
39 vector< vector<int> >& score, // the score
40 double lenght, // lenght of the score in seconds : R+*
41 int dataBySecond, // number of data by second : ~{11000, 22000, 44100}
42 double AFreq, // frequency of A : ~440.0
43 int minHT, // minimum halftone : Z // TODO <0
44 int maxHT, // maximum halftone : Z
45 int nbNotes, // number of notes in lenght : N*
46 int nbVoice) // number of voices : N*
50 int size = int(lenght*dataBySecond);
51 int nbHT = maxHT-minHT+1;
52 int note_size = size / nbNotes;
53 cout << "AFreq=" << AFreq << " dataBySecond=" << dataBySecond << endl;
54 cout << "nbNotes=" << nbNotes << " lenght=" << lenght << " minHT=" << minHT << " maxHT=" << maxHT << endl;
55 cout << "size=" << size << " nbHT=" << nbHT << " nbVoice=" << nbVoice << endl;
57 cout << "make score ... \t\t" << flush;
59 for(int i=0; i<nbNotes; i++)
61 vector<int> hs(nbVoice);
62 for(size_t v=0; v<hs.size(); v++)
63 hs[v] = minHT+rdm.nextInt(maxHT-minHT+1);
65 // cout << "halftone selected=" << h << " freq=" << freq << endl;
66 for(int j=0; j<note_size; j++)
69 for(size_t v=0; v<hs.size(); v++)
70 buff += sin( ((2.0*Math::Pi)/dataBySecond)*h2f(hs[v], AFreq)*double(j) );
72 // int index = i*note_size+j;
73 // add data index and wav value
75 buffer.push_back(buff);
76 // add score halftones (solution)
77 vector<int> score_at(nbHT);
78 for(int vh=0; vh<nbHT; vh++)
81 for(size_t v=0; v<hs.size(); v++)
86 score.push_back(score_at);
87 // n = undoable_out_percent(cout, 100.0f*index/size, n);
90 // undoable_out_clear(cout, n);
91 cout << "done " << endl;