Пример #1
0
    //------------------------------------------------------------------------------------
    void startRecording()
    {
        if (bOpeningRecorder)
            finishRecording();
        
        ///add directory select
        SkeletonMap &map = skeleton::SkeletonManager::getInstance().getSkeletons();

        if (map.empty()) {
            ofLogNotice("Recorder") << "No skeleton avairable";
            return;
        }

        for (SkeletonMap::iterator it = map.begin(); it!=map.end(); ++it) {
            SkeletonPtr skeleton = it->second;
            const string name = skeleton->getName();
            //string filePath = ret.getPath();
            string filePath = ofToDataPath("motion/mot/"+ram::getDefaultRecordingDataFileName());
            const string escape = "__WILDCARD_ESCAPE__";
            ofStringReplace(filePath, "\\*", escape);
            ofStringReplace(filePath, "*", name);
            ofStringReplace(filePath, escape, "*");
            skeleton->prepareRecording(filePath);
            skeleton->startRecording();
        }
    
        bOpeningRecorder = true;
    }
Пример #2
0
void ofxGSTT::audioIn(float * buffer,int bufferSize, int nChannels, int deviceId){
	int deviceIdx=0;
	for(int i=0;i<(int)deviceIds.size();++i){
		if(deviceIds[i]==deviceId){
			deviceIdx=i;
			break;
		}
	}

	if(bRecordingBlocked[deviceIdx]){
		return;
	}

	float curVol = 0.0;

	// samples are "interleaved"
	int numCounted = 0;

	//lets go through each sample and calculate the root mean square which is a rough way to calculate volume
	vector<float> left;
	vector<float> right;
	left.assign(bufferSize, 0.0);
	right.assign(bufferSize, 0.0);
	for(int i = 0; i < bufferSize; i++){
		if(nChannels == 1){
			curVol += buffer[i] * buffer[i];
			numCounted += 1;
		}else if(nChannels == 2){
			left[i] = buffer[i * 2];
			right[i] = buffer[i * 2 + 1];

			curVol += left[i] * left[i];
			curVol += right[i] * right[i];
			numCounted += 2;
		}
	}

	//this is how we get the mean of rms :)
	curVol /= (float) numCounted;

	// this is how we get the root of rms :)
	curVol = sqrt(curVol);

	smoothedVolume[deviceIdx] *= 0.9; //TODO settings for this ratio needed
	smoothedVolume[deviceIdx] += 0.1 * curVol;

	//lets scale the vol up to a 0-1 range
	//float scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);//TODO set by settings!
//	float scaledCurVolume = ofMap(curVol, 0.0, 0.17, 0.0, 1.0, true);

	bool bActiveVolume = curVol > volumeThreshold;

	//TODO revisit: should be in an extra update function?!
	unsigned long long tNow = ofGetElapsedTimeMillis();
	if(bListen || (bActiveVolume && bAutoListen)){
		tLastUpdate[deviceIdx] = tNow;
		bRecording[deviceIdx] = true;
	}
	if(bRecording[deviceIdx]){
		if(tNow - tLastUpdate[deviceIdx] > 500){ //TODO magic number, hard coded
			bRecording[deviceIdx] = false;
			finishRecording(deviceIdx);
			prepareRecording(deviceIdx);
		}else{
			sf_write_float(outfiles[deviceIdx], buffer, bufferSize * nChannels);
		}
	}
}
Пример #3
0
void ofxGSTT::audioIn(float * buffer,int bufferSize, int nChannels, int deviceId){
	int deviceIdx=0;
	for(int i=0;i<deviceIds.size();++i){
		if(deviceIds[i]==deviceId){
			deviceIdx=i;
			break;
		}
	}

	if(bRecordingBlocked[deviceIdx]){//TODO ARRAY
		return;
	}

	float curVol = 0.0;

	// samples are "interleaved"
	int numCounted = 0;

	//lets go through each sample and calculate the root mean square which is a rough way to calculate volume
	for(int i = 0; i < bufferSize; i++){
		left[i] = buffer[i * 2];
		right[i] = buffer[i * 2 + 1];

		curVol += left[i] * left[i];
		curVol += right[i] * right[i];
		numCounted += 2;
	}//TODO mehrfachverwendung von left & right - problem

	//this is how we get the mean of rms :)
	curVol /= (float) numCounted;

	// this is how we get the root of rms :)
	curVol = sqrt(curVol);

	smoothedVolume[deviceIdx] *= 0.9; //TODO settings for this ratio needed
	smoothedVolume[deviceIdx] += 0.1 * curVol;

	//lets scale the vol up to a 0-1 range
	//float scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);//TODO set by settings!
	float scaledCurVolume = ofMap(curVol, 0.0, 0.17, 0.0, 1.0, true);

	bool bActiveVolume = scaledCurVolume > volumeThreshold;

	//TODO revisit: should be in an extra update function?!
	if(bActiveVolume){
		timer[deviceIdx]->reset();
		timer[deviceIdx]->startTimer();
		bRecording[deviceIdx] = true;
	}
	if(bRecording[deviceIdx]){
		if(timer[deviceIdx]->isTimerFinished()){
			bRecording[deviceIdx] = false;
			finishRecording(deviceIdx);
			prepareRecording(deviceIdx);
		}else{
			sf_write_float(outfiles[deviceIdx], buffer, bufferSize * 2);
		}
	}
//
//	if(deviceId>10){
//		delete[] buffer;
//	}
}