Example #1
0
void SoundEngine::init(int timerChannel)
{
    soundOn();
    streaming = false;
    edgeState = 0;
    initStreaming(timerChannel);
}
Example #2
0
uint8_t SaberDB::volume4() const
{
  if (!soundOn() || dataHeader.volume == 0) {
    return 0;
  }
  if (dataHeader.volume == VOLUME_4) return 4;
  if (dataHeader.volume >= VOLUME_3) return 3;
  if (dataHeader.volume >= VOLUME_2) return 2;
  return 1;
}
Example #3
0
void printSound(){
	
	if(toSound[buff] != 0){
		if(toSound[buff] > 0){
			soundOn();
			toSound[buff] = toSound - 1;
		}else{
			soundOf();
			toSound[buff] = toSound + 1;
		}	
	}else{
		if(buff < MAX_MORSE - 1 && toSound[buff + 1] != 0){
			buff++;
		}else{
			buff = 0;
			toSound[buff] = 0;
			toSound[buff + 1] = 0;			
		}	
	}
}
Example #4
0
uint32_t ReflowOven::timerService (uint32_t currentTime) {
    unsigned long ms = millis (); // using millis because currentTime rolls over every ~107secs and millis rolls over every 50 days
    
    if (ms - ms1000 >= 1000) {
        ms1000 = ms;
        
        double cjt;
        bool open, sGnd, sVcc;
        double lastTemp = temp;
        bool fault = tc.readMAX31855 (&temp, &cjt, &open, &sGnd, &sVcc, false);
        
        if (fault) {
            if (faultCount == 1000) {
                turnOvenOff ();
                soundOn ();
                if (open)
                    ovenGraph.showInfo ("TC Not Connected");
                else if (sGnd)
                    ovenGraph.showInfo ("TC Grounded");
                else if (sVcc)
                    ovenGraph.showInfo ("TC Shorted to Vcc");
            } else {
                ++faultCount;
                temp = lastTemp;
            }
        } else
            faultCount = 0;
        
        if (myBui.isCurrentScreen (OVEN_GRAPH))
            ovenGraph.update ((float)temp, runtime);
        
        if (ovenOn) {
            ++runtime;
        
            if ((temp > TEMP_ALARM) || (temp > (setpoint + MAX_OVER_SETPOINT))) {
                if (reflowState != COOLDOWN) {
                    turnOvenOff ();
                    soundOn ();
                    ovenGraph.showInfo ("Oven Overheat");
                }
            }

            switch (reflowState) {
                case PREHEAT:
                    setpoint += reflowVars.preheatRamp;
                    if (setpoint >= reflowVars.soakTemp) {
                        setpoint = reflowVars.soakTemp;
                        ovenGraph.updateStage ("Soak");
                        reflowState = SOAK;
                    }
                    break;
                case SOAK:
                    setpoint += (reflowVars.soakTempIncrease / reflowVars.soakTime);
                    if (runtime >= (reflowVars.preheatTime + reflowVars.soakTime)) {
                        reflowState = RAMP;
                        ovenGraph.updateStage ("Ramp");
                    }
                    break;
                case RAMP:
                    setpoint += reflowVars.ramp;
                    if (setpoint >= reflowVars.peakTemp) {
                        setpoint = reflowVars.peakTemp;
                        reflowState = PEAK;
                        ovenGraph.updateStage ("Peak");
                    }
                    break;
                case PEAK:
                    if (runtime >= (reflowVars.preheatTime + reflowVars.soakTime + reflowVars.rampTime + reflowVars.peakTime)) {
                        soundOn ();
                        ovenGraph.showInfo ("Reflow Complete");
                        reflowState = COOLDOWN;
                        ovenGraph.updateStage ("Cooldown");
                    }
                    break;
                case COOLDOWN:
                    setpoint -= reflowVars.cooldownRamp;
                    if (runtime >= reflowVars.totalTime) {
                        turnOvenOff ();
                        reflowState = PREHEAT;
                        ovenGraph.updateButtons ();
                    }
                default:
                    break;
            }
        }
    }
    
    if (ovenOn) {
        if (temp > (startingTemp + 10)) {
            if (ms - msPTerm >= pidVars.sampleTime) {
                msPTerm = ms;
                
                ovenGraph.updateSetpoint (setpoint);
                
                float pv = (float)temp / MAX_TEMPERATURE;
                float sp = setpoint / MAX_TEMPERATURE;
                //Serial.print ("Present value: ");
                //Serial.println (pv);
                //Serial.print ("Setpoint: ");
                //Serial.println (sp);
                
                float dutyCycle = pid_run (pid, pv, sp);
                elementOffTime = pidVars.sampleTime * dutyCycle + ms;
                if (dutyCycle != 0.0f)
                    turnElementOn ();
                
                //Serial.print ("Current time: ");
                //Serial.println (ms);
                //Serial.print ("Duty cycle: ");
                //Serial.println (dutyCycle);
                
                //Serial.print ("Element off time: ");
                //Serial.println (elementOffTime);
                //Serial.println ();
                
            }
            
            // this needs to be after the new elementOffTime is calculated because a duty cycle of 1.0 was getting turned off
            if (elementOn) {
                if (ms >= elementOffTime) {
                    turnElementOff ();
                }
            }
            
            if (pidVars.iTime != 0) {
                if (ms - msITerm >= pidVars.iTime) {
                    msITerm = ms;
                    pid_calcI (pid);
                }
            }
            
            if (pidVars.dTime != 0) {
                if (ms - msDTerm >= pidVars.dTime) {
                    msDTerm = ms;
                    pid_calcD (pid);
                }
            }
        }
    }
    
    return (currentTime + CORE_TICK_RATE); // CORE_TICK_RATE is the number of ticks in 1msec
}
Example #5
0
void sayNoise(const char* sounds,const int8_t* modifier){

	// phonemes has list of sound bytes
	uint8_t
		phonemeIn,				// offset into text
		byte2,
		modifierIn;				// offset into stuff in modifier
	int8_t	punctuationPitchDelta;	// change in pitch due to fullstop or question mark
	SOUND_ACTION action;
	char phoneme;
	const SOUND_INDEX* soundIndex;
	uint8_t sound1Num;			// Sound data for the current phoneme
	uint8_t sound2Num;			// Sound data for the next phoneme
	uint8_t sound2Stop;			// Where the second sound should stop
	int8_t pitch1;			// pitch for the first sound
	int8_t pitch2;			// pitch for the second sound
	short i;
	uint8_t sound1Duration;		// the duration for sound 1. 0 to 255.

	#ifdef _LOG_
	{
		int p=0;
		loggerP(PSTR("Data:"));
		logger(sounds);
		loggerCRLF();
		loggerP(PSTR("Modifier:"));
		while(sounds[p]){
			uint8_t m = modifier[p];
			uint8_t h;
			h = m>>4;
			loggerc( (char)((h<=9) ? (h+'0') : (h-10+'A')) );	// hex char
			h=m & 15;
			loggerc( (char)((h<=9) ? (h+'0') : (h-10+'A')) );	// hex char
			loggerc(',');

			m = modifier[p+1];
			h = m>>4;
			loggerc( (char)((h<=9) ? (h+'0') : (h-10+'A')) );	// hex char
			h=m & 15;
			loggerc( (char)((h<=9) ? (h+'0') : (h-10+'A')) );	// hex char
			loggerc(',');
			p+=2;
		}
		loggerCRLF();
	}
#endif

	soundOn();

	// _630C
//		action=ACTION_NO_ACTION;
	punctuationPitchDelta=0;

	//Q19
	for(phonemeIn=0,modifierIn=0;sounds[phonemeIn]!=0; phonemeIn+=2, modifierIn+=2){
		uint8_t	duration;	// duration from text line
		uint8_t SoundPos;	// offset into sound data
		uint8_t fadeSpeed=0; // Fade speed between the two sounds. 0 to 255
		action=ACTION_NO_ACTION;

		phoneme=sounds[phonemeIn];
		if(phoneme=='z'){
			delay(15);
			goto nextPhoneme;
		}else if(phoneme=='#'){
			goto nextPhoneme;
		}else{

			// Collect info on sound 1
			soundIndex = &SoundIndex[phoneme - 'A'];
			sound1Num = pgm_read_byte(&soundIndex->SoundNumber);
			action = pgm_read_byte(&soundIndex->action);
			byte2 = pgm_read_byte(&soundIndex->byte2);

			duration = sounds[phonemeIn+1] - '0';	// Get duration from the input line
			if(duration!=1){
				duration<<=1;
			}
			duration += 6;							// scaled duration from the input line (at least 6)

			sound2Stop = 0x40 / 2;


			pitch1 = modifier[modifierIn];
			if(modifier[modifierIn + 1]==0 || pitch1==-1){
				pitch1 = 10;
				duration -= 6;
			}else if(modifier[modifierIn + 1]=='0' || duration==6){
				duration -= 6;
			}


			//q8
			pitch2 = modifier[modifierIn+2];
			if(modifier[modifierIn + 3]==0 || pitch2 == -1){
				pitch2 = 10;
			}


			if(action<ACTION_NO_ACTION){
				//sound1Num = 0;
				random();
				sound2Stop=(0x40 / 2)+2;
			}else if(action==ACTION_FADE_IN){
				uint8_t volume;					// volume mask
#ifdef _LOG_
//					loggerP(PSTR("\nA *******"));
//					logger_uint8(duration);
//					loggerCRLF();
#endif
				volume = (duration==6) ? 15 : 1;  /// volume mask
				for(duration <<= 2; duration>0; duration--){
					playTone(sound1Num,random(),8,12,17, volume);
					// Increase the volume
					if(++volume==16){
						volume = 15;	// full volume from now on
					}
				}
				goto nextPhoneme;

			}else if(action == ACTION_PAUSE){
				delay(25);
			}
		}


		// 6186
		pitch1 = pitch1 + default_pitch + punctuationPitchDelta;
		if(pitch1<1){
			pitch1=1;
		}

		pitch2 = pitch2 + default_pitch + punctuationPitchDelta;
		if(pitch2<1){
			pitch2=1;
		}

		// get next phoneme
		phoneme=sounds[phonemeIn + 2];

		if(phoneme==0 || phoneme=='z'){
			if(duration==1){
				delay(60);
			}
			phoneme='a';	// change to a pause
		}else{
			// s6
			if(byte2 != 1){
				// Get the average of byte2 for the two phonemes
				byte2 = (byte2 + pgm_read_byte(&SoundIndex[phoneme-'A'].byte2))>>1;
			}

			if(action < ACTION_NO_ACTION || pgm_read_byte(&SoundIndex[phoneme-'A'].action) != ACTION_NO_ACTION){
				phoneme ='a'; // change to a pause
			}
		}

		// S10 - 61e5
		sound2Num = pgm_read_byte(&SoundIndex[phoneme-'A'].SoundNumber);

		sound1Duration = 0x80;			// play half of sound 1
		if(sound2Num==sound1Num){
			byte2 = duration;
		}

		// S11
		if( (byte2>>1) == 0 ){
			sound1Duration = 0xff;				// play all of sound 1
		}else{