示例#1
0
//--------------------------------------------------------------
//scene notifications
// reset our scene when we appear
void JiveScreen::sceneWillAppear( ofxScene * fromScreen )
{
    ofSoundStopAll();
    ofSoundSetVolume(0.75);
    prevPlayerPos = startPlayerPos_R1;
    
    player.play();
}
//--------------------------------------------------------------
void ofApp::setup(){
    for (int i=0;i<VOICES;i++){
        voicePaused[i] = true;
        ofLogNotice() << "Loading voice" << i << endl;
        voicePlayer[i].loadSound("vox"+ofToString(i+1)+".wav");
        voicePlayer[i].setLoop(true);
        voicePlayer[i].setVolume(1);
        voicePlayer[i].play();
        voicePlayer[i].setPaused(true);
    }
    ofSoundSetVolume(0.2);
    speedBoard.loadFont("arial.ttf",20);
}
示例#3
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofEnableAlphaBlending();
    ofSoundSetVolume(1);
    viewPos = ofVec2f(0, 0);
    first = true;
    currentState = MAINMENU;
    ofSetFrameRate(60); //set framerate
    ofSeedRandom();
    mapDim = ofVec2f(60, 60);
    tileDim = ofVec2f(32, 32);
    mainSound.loadSound("Music1.mp3");
    secondSound.loadSound("Music2.mp3");
    menuSound.loadSound("Music3.mp3");
    mainSound.setLoop(false);
    menuSound.setLoop(true);
    secondSound.setLoop(false);
    soundIsPlaying == false;

}
示例#4
0
void ofApp::setup() {
//    ofSetLogLevel(OF_LOG_VERBOSE);
    ofSetLogLevel(OF_LOG_NOTICE);
//    ofSetLogLevel(OF_LOG_SILENT);

    for (int i=0; i<VOICES; i++) {
        voicePaused[i] = true;

        ofLogNotice() << "Loading voice " << i << endl;
        voicePlayer[i].load("vox"+ofToString(i+1)+".wav");
        voicePlayer[i].setLoop(true);

        //voicePlayer[i].setVolume(1);
        voicePlayer[i].play();
        voicePlayer[i].setPaused(true);
    }

    ofSoundSetVolume(0.2);
}
示例#5
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofSleepMillis(100);
	
	int newVal = lidar_read(fd);
	unsigned char  st = lidar_status(fd);
	//ver = lidar_version(fd);
	//printf("%3.0d cm \n", res);
	lidar_status_print(st);

	if (newVal < 2) {
		// Handle strange case where lidar reports 1cm when should be infinity
		newVal = 10000;
	}
	
	// increment up to max smoothing (deals with initial state)
	if (nSamplesToSmooth < maxSamplesToSmooth ) nSamplesToSmooth++; 
	// Calculate the weight of new value
	float newWeight = ((float)1)/((float)nSamplesToSmooth); 
	// Calculate the smoothed PWM value
	smoothPwm = ((float) newVal)*newWeight + smoothPwm*(1-newWeight);
	
	counter++;
	
	if (pitchBend) { // Pitch bend mode
		//cout << ofGetSystemTimeMicros() << "," << blinkTimer << endl;
		if (ofGetSystemTimeMicros() - blinkTimer >= 200000) {
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			// Play sound
			pitchSound.play();
			float soundSpeed = 1.5f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
			pitchSound.setSpeed( soundSpeed );
			//ofSoundSetVolume(ofClamp(0.5f + smoothPwm, 0, 1));
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundSpeed <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
			
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
	} else if (volBend) { // Volume bend mode
		float soundVolume = 1.f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
		
		if (ofGetSystemTimeMicros() - blinkTimer >= 1000000) {
			volSound.play();
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundVolume <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
				
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
		volSound.setVolume(soundVolume);
		ofSoundSetVolume(soundVolume);
	}
	
	// Log data to file
	if (ofGetElapsedTimeMillis() - logTimer >= 60000) {

		
		// Get the temperature
		FILE *temperatureFile;
		double T;
		temperatureFile = fopen ("/sys/class/thermal/thermal_zone0/temp", "r");
		if (temperatureFile == NULL) {
			cout << "Failed to read temp file\n";
		} else {
			fscanf (temperatureFile, "%lf", &T);
			T /= 1000;
			//printf ("The temperature is %6.3f C.\n", T);
			fclose (temperatureFile);
		}
		
		// Log the data
		logTimer = ofGetElapsedTimeMillis();
		//string logFileName = "/logs/livestream/livestream01.log";
		string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
		ofstream mFile;
		mFile.open(logFileName.c_str(), ios::out | ios::app);
		mFile << getDateTimeString() << ",TC," << T;
		for (int j=0; j<nSensors; j++) {
			float tempData = tempSensor.read(j);
			mFile << ",T" << j << "," << tempData;
		}
		mFile << ",DL," << smoothPwm << " cm" << ",LR," << ofGetFrameRate() << "Hz,";
		mFile << endl;
		mFile.close();
	}
}
示例#6
0
//--------------------------------------------------------------
void ofApp::setup(){
	ofSetVerticalSync(false);
	//ofSetFrameRate(10000)
	
	counter = 0;
	blinkTimer = ofGetSystemTimeMicros();
	logTimer = ofGetElapsedTimeMillis();
	
	// Setup GPIOs
	gpio15  = new GPIO("15");
	gpio15->export_gpio();
	gpio15->setdir_gpio("out");
	gpio15->setval_gpio("0");
	gpio15outState = false;
	
	gpio21  = new GPIO("21");
	gpio21->export_gpio();
	gpio21->setdir_gpio("out");
	gpio21->setval_gpio("0");
	gpio21outState = false;

	// PWM smoothing parameters
	nSamplesToSmooth = 0;
	maxSamplesToSmooth = 1; // determines smoothing
	smoothPwm = 0; // smoothed PWM value
	minDist = 30; //cm
	maxDist = 30*20; //cm
	
	// Sound output
	pitchSound.loadSound("sounds/INT18PIPES1.mp3");
	pitchSound.setVolume(0.3f);
	pitchSound.setMultiPlay(false);
	
	volSound.loadSound("sounds/Tp10.wav");
	volSound.setVolume(0.3f);
	volSound.setMultiPlay(true);
	
	ofSoundSetVolume(1.0f);

	volBend = true;
	pitchBend = false;
	
	// Init I2C
	fd = lidar_init(false);
	if (fd == -1) 
	{
		printf("initialization error\n");
		ofApp::exit();
	}
	
	// Get the host name
	int z;  
	char buf[32];  
	z = gethostname(buf,sizeof buf);
	if ( z != -1 ) {
		hostname = string(buf);
		//printf("host name = '%s'\n",buf); 
		cout << "host name = " 	<< hostname << endl;
	} else {
		cout << "host name unknown" << endl;
		hostname = "unknown";
	}
	
	// Write initialization to the log
	string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
	ofstream mFile;
	mFile.open(logFileName.c_str(), ios::out | ios::app);
	mFile << getDateTimeString() << ",INITILIZATION" << endl;
	mFile.close();
	
	nSensors = tempSensor.listDevices();
}