コード例 #1
0
ファイル: chordid~.cpp プロジェクト: scblakely/chordid
	// default signal processing method is called 'perform'
	void perform(double **ins, long numins, double **outs, long numouts, long sampleframes) {
		// 
		char *this_chordname;
		std::vector<double> chroma;
		chroma.resize(12);
		double rms, rms_tot;
		int q;
		rms = 0;
		rms_tot = 0;
		for (long channel = 0; channel < numouts; channel++) {
			double * in = ins[channel];
			double * out = outs[channel];
			for (long i=0; i < sampleframes; i++) {
				out[i] = in[i];
				// we only want to process on channel 0
				if (channel == 0) {
					if (currentsamples < frameSize - 1) {
						frame[currentsamples] = in[i];
						currentsamples++;
					}
					else {
						currentsamples = 0;
						for (q = 0; q < frameSize; q++) {
							rms_tot += pow(frame[q],2);
						}
						rms = rms_tot / frameSize;
						if (rms > rms_cutoff){
							c.processAudioFrame(frame);
							outlet_int(m_outlets[3], 1);
						}
						else {
							outlet_int(m_outlets[3], 0);
						}
						if (c.isReady()) {
							std::vector<double> chroma = c.getChromagram();
							chordspotter.detectChord(chroma);
							currentchord = 10000 * chordspotter.rootNote + chordspotter.chord_num;
							chord_name = chordspotter.chord_name;
							const char *this_chordname = chord_name.c_str();
							if (currentchord != lastchord) {
								outlet_anything(m_outlets[0], gensym(this_chordname), 0, NULL);
								outlet_int(m_outlets[1], currentchord);
								midilist(chordspotter.rootNote, chordspotter.chord_num);
							}
							lastchord = currentchord;
						}
					}
				}

			}
		}
	}
コード例 #2
0
const double PitchDetector::detectChord(SamplesNode * pSamplesNode)
{
    int frameSize = pSamplesNode->sampleSize;
    int sampleRate = 44100;
    
    _chromagram.setInputAudioFrameSize(frameSize);
    _chromagram.setSamplingFrequency(sampleRate);
    _chromagram.processAudioFrame (pSamplesNode->samples);
    if (_chromagram.isReady())
    {
        std::vector<double> chroma = _chromagram.getChromagram();
        
        // do something with the chromagram here
        ChordDetector chordDetector;
        chordDetector.detectChord (chroma);
        chordDetector.rootNote;
        chordDetector.quality;
        chordDetector.intervals;
    }
    
    return 0;
}