Esempio n. 1
0
void ofxGSTT::addDevice(int deviceId){
	deviceIds.push_back(deviceId);
	outfiles.push_back(NULL);
	smoothedVolume.push_back(0.f);
	tLastUpdate.push_back(0);
	bRecording.push_back(false);
	bRecordingBlocked.push_back(false);
	deviceTanscriber.push_back(NULL);

	ofDirectory dir;
	if(!dir.doesDirectoryExist("tmpAudio/device"+ofToString(deviceId)+"/")){
		dir.createDirectory("tmpAudio/device"+ofToString(deviceId));
	}

	prepareRecording(deviceIds.size()-1);
}
Esempio n. 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);
		}
	}
}
Esempio n. 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;
//	}
}