Beispiel #1
0
int restoreVolume(BOOL normalVolume) {
	int ret;
	
	if (normalVolume)
		ret = adjustVolume(NORMAL_VOLUME,FALSE,FALSE);
	else
		ret = adjustVolume(oldVolume,FALSE,FALSE);
	return ret;
}
Beispiel #2
0
void MusicPlayer::playSong(unsigned int songIndex)
{
  vs1053.softReset();
  if(!newsd.openFile(songIndex)){//open music file
    return;
  }
  Serial.print("Song ");
  Serial.print(spl.currentSongNum);
  Serial.println(" opened");
  _currentSongIndex = songIndex;
  int readLen = 0;
  byte readBuf[READ_BUF_LEN];
  while(1){
    readLen = newsd.readFile(readBuf,READ_BUF_LEN);  
    vs1053.writeData(readBuf,readLen);
    if(readLen < READ_BUF_LEN)
    {
      vs1053.writeRegister(SPI_MODE,0,SM_OUTOFWAV);
      vs1053.sendZerosToVS10xx();
      break;
    }
    while(!vs1053.readDREQ())
    {
      while(1){
        AvailableProcessorTime();
        if((playingState == PS_STOP)||(playingState == PS_NEXT_SONG)||(playingState == PS_PREVIOUS_SONG))
        {
          if(file.close() == 0)//close file
             error("close file failed");
          return;
        }
        else 
        {
          switch(playingState)
          {
            case PS_PLAY:       playOrPause = 1;break;
            case PS_PAUSE:      playOrPause = 0;break;
            case PS_VOLUME_UP:  adjustVolume(VOLUME_UP);break;
            case PS_VOLUME_DOWN:adjustVolume(VOLUME_DOWN);break;
            default:break;
          }
        }
        if(playOrPause == 1)break;
      }
    }
  }
  Serial.println("played over\r\n");
  if(file.close() == 0)//close file
  {
    error("close file failed");
  }
}
void YSE::CHANNEL::implementationObject::dsp() {
  // if no sounds or other channels are linked, we skip this channel
  if (children.empty() && sounds.empty()) return;

  // clear channel buffer
  clearBuffers();

  // calculate child channels if there are any
  for (auto i = children.begin(); i != children.end(); ++i) {
    INTERNAL::Global().addFastJob(*i);
  }

  // calculate sounds in this channel
  for (auto i = sounds.begin(); i != sounds.end(); ++i) {
    if ((*i)->dsp()) {
      (*i)->toChannels();
    }
  }

  adjustVolume();

  REVERB::Manager().process(this);

  if (INTERNAL::UnderWaterEffect().channel() == this) {
    INTERNAL::UnderWaterEffect().apply(out);
  }
}
Beispiel #4
0
void
EmbedSoundInst::decodeNextBlock()
{
    assert(!decodingCompleted());

    // this value is arbitrary, things would also work
    // with a smaller value, but 2^16 seems fast enough
    // to decode not to bother further streamlining it
    // See https://savannah.gnu.org/bugs/?25456 for a testcase
    // showing the benefit of chunked decoding.
    const std::uint32_t chunkSize = 65535;

    std::uint32_t inputSize = _soundDef.size() - decodingPosition;
    if ( inputSize > chunkSize ) inputSize = chunkSize;

#ifdef GNASH_DEBUG_SOUNDS_DECODING
    log_debug("  decoding %d bytes", inputSize);
#endif

    assert(inputSize);
    const std::uint8_t* input = _soundDef.data(decodingPosition);

    std::uint32_t consumed = 0;
    std::uint32_t decodedDataSize = 0;
    std::uint8_t* decodedData = decoder().decode(input, inputSize,
            decodedDataSize, consumed);

    decodingPosition += consumed;

    assert(!(decodedDataSize%2));

    // @todo I hope there are no alignment issues in this cast from int8_t* to int16_t* !
    std::int16_t* samples = reinterpret_cast<std::int16_t*>(decodedData);
    unsigned int nSamples = decodedDataSize/2;

#ifdef GNASH_DEBUG_MIXING
    log_debug("  applying volume/envelope to %d bytes (%d samples)"
            "of decoded data", decodedDataSize, nSamples);
#endif

    // Adjust volume
    if (_soundDef.volume != 100) {
        adjustVolume(samples, samples + nSamples, _soundDef.volume/100.0);
    }

    /// @todo is use of envelopes really mutually exclusive with
    ///       setting the volume ??
    else if (envelopes) {
        unsigned int firstSample = playbackPosition() / 2;
        applyEnvelopes(samples, nSamples, firstSample, *envelopes);
    }

#ifdef GNASH_DEBUG_MIXING
    log_debug("  appending %d bytes to decoded buffer", decodedDataSize);
#endif


    // decodedData ownership transferred here
    appendDecodedData(SimpleBuffer(decodedDataSize, decodedData));
}
void QOpenSLESAudioOutput::setVolume(qreal vol)
{
    m_volume = qBound(qreal(0.0), vol, qreal(1.0));
    const SLmillibel newVolume = adjustVolume(m_volume);
    if (m_volumeItf && SL_RESULT_SUCCESS != (*m_volumeItf)->SetVolumeLevel(m_volumeItf, newVolume))
        qWarning() << "Unable to change volume";
}
Beispiel #6
0
void Resampler::read(signed channel[]) {
    adjustVolume();

    for(unsigned c = 0; c < settings.channels; c++) {
        channel[c] = sclamp( settings.precision, output.read(c) * settings.intensity );
    }
    output.rdoffset++;
}
void EzxVolumeService::decreaseVolume(int decrement)
{
    decrement *= -1;

    adjustVolume(decrement, decrement, Relative);
    m_d->sendCurrentVolume();

}
Beispiel #8
0
void Music::onTxtMsg(const std::string& text)
{
    if(text=="stop")
    {
        stop();
    } else if(text=="replay")
    {
        replay();
    } else if(text=="+")
    {
        adjustVolume(+0.1);
    } else if(text=="-")
    {
        adjustVolume(-0.1);
    } else if(text == "status")
    {
        std::ostringstream strs;
        strs << volume *100;
        std::string msg = "Dolanik status: <br />";
        msg += "Current volume = " + strs.str() + "%<br />";
        if(playback)
            msg += "I'm currently playing song : "+ currentSong->getTitle() 
              + "(Length:" /*"+ Anal::toStr(getCurrentSongLength()) +" */ "s ) <br />"; //FIXME
        mc->SendTextMessage("music",msg);
    } else if(text == "playlist")
    {
      mc->SendTextMessage("music", genPlaylistString());
    } else if(text.substr(0, 2) == "eq") {
        int band = -1;
        double amp = -1;

        if(text.substr(3, 5) == "reset") {
            resetEqualizer();
            return;
        }

        std::stringstream ss;
        ss << text.substr(2);
        ss >> band;
        ss >> amp;

        setEqualizer(band,amp);
    } else if(text == "help")
Beispiel #9
0
void AudioMixer::stop(int channel, int time) {
	Common::StackLock lock(_mutex);

	if (_channels[channel].isPresent) {
		if (time) {
			adjustVolume(channel, 0, time);
		} else {
			_channels[channel].isPresent = false;
			_vm->_mixer->stopHandle(_channels[channel].handle);
			if (_channels[channel].endCallback != nullptr) {
				_channels[channel].endCallback(channel, _channels[channel].callbackData);
			}
		}
	}
}
Beispiel #10
0
void
StreamingSound::decodeNextBlock()
{
    assert(!decodingCompleted());

    // Get the current block of sound data.
    const SimpleBuffer& block = _soundDef.getBlock(_currentBlock);

    // If we didn't decode all of a block, do so now. Not sure if this
    // can happen.
    const std::uint32_t inputSize = block.size() - _positionInBlock;

    std::uint32_t consumed = 0;

    // Empty blocks serve to synchronize, so don't decode but carry on.
    if (inputSize) {
        std::uint32_t decodedDataSize = 0;
        const std::uint8_t* input = block.data() + _positionInBlock;
        std::uint8_t* decodedData = decoder().decode(input, inputSize,
                decodedDataSize, consumed);

        assert(!(decodedDataSize % 2));

        std::int16_t* samples =
            reinterpret_cast<std::int16_t*>(decodedData);
        unsigned int nSamples = decodedDataSize / 2;

        if (_soundDef.volume != 100) {
            adjustVolume(samples, samples + nSamples, _soundDef.volume/100.0);
        }

        // decodedData ownership transferred here
        appendDecodedData(decodedData, decodedDataSize);
    }

    // Check if the entire block was consumed.
    if (consumed == block.size()) {
        // Go to next block
        ++_currentBlock;
        _positionInBlock = 0;
    }
    else _positionInBlock += consumed;

}
void YSE::CHANNEL::implementationObject::buffersToParent() {
  join();

  // call this recursively on all child channels 
  for (auto i = children.begin(); i != children.end(); ++i) {
    (*i)->buffersToParent();
  }

  // apply channel volume
  adjustVolume();

  // if this is the main channel, we're done here
  if (parent == nullptr) return;
  if (children.empty() && sounds.empty()) return;

  // if not the main channel, add output to parent channel
  for (UInt i = 0; i < out.size(); ++i) {
    // parent size is not checked but should be ok because it's adjusted before calling this
    parent->out[i] += out[i];
  }
}
void EzxVolumeService::increaseVolume(int increment)
{
    adjustVolume(increment, increment, Relative);
    m_d->sendCurrentVolume();
}
void EzxVolumeService::setVolume(int leftChannel, int rightChannel)
{
    adjustVolume(leftChannel, rightChannel, Absolute);
}
//public slots:
void EzxVolumeService::setVolume(int volume)
{
    adjustVolume(volume, volume, Absolute);
}
void C3200VolumeService::decreaseVolume(int decrement)
{
    decrement *= -1;

    adjustVolume(decrement, decrement, Relative);
}
Beispiel #16
0
static void takeAction (Action *action, EnumAction actionCode) {
	unsigned int newTime, oldTime; 
	unsigned long longNewTime, longOldTime;
	int newIdxTimeframe, tempTime;
	CtnrFile *newFile;
	CtnrBlock *newBlock, *soundInsertBlock;
	int newIdxAction;
	EnumAction newActionCode;
	EnumBorderCrossing direction;
	signed long l;	
	int destination, aux, i, ret;
	int status;
	BOOL reposition = FALSE;
	BOOL isTooFar = FALSE;
	ListItem *list, *tempList;
	char filename[PATH_LENGTH];
	char *cursor, *cursor2;
	CtnrFile *replayFile;
		
	replayFile = NULL;
	list = NULL;
	oldTime = compressTime(Snd_A1800_GetCurrentTime(),context.package->timePrecision);
	newFile = 0;
	newTime = -1;
	newBlock = 0;
		
	if (actionCode == -1)
		actionCode = getActionCode(action);
	if (action) {
		aux = action->aux;
		destination = action->destination;
	}
		
	switch (actionCode) {
		case JUMP_LIST:
			stop();
			list = &context.package->lists[destination];
			context.idxActiveList = destination;
			switch (getListRotation(aux)) {
				case 0:
				    cursor = getCurrentList(list);
				    strcpy(filename,cursor);
					break;
				case 1:
				    strcpy(filename,getNextList(list,TRUE));
					break;
				case -1:
				    strcpy(filename,getPreviousList(list));
					break;
			}
			if (!filename[0]) { 
				// empty list
				insertSound(&pkgSystem.files[EMPTY_LIST_FILE_IDX],NULL,FALSE);
				// empty list of packages; redirect to current point in list of lists
				list = &context.package->lists[0];
				context.idxActiveList = 0;
			    cursor = getCurrentList(list);
			    strcpy(filename,cursor);
			} 
			if (list->listType == LIST_OF_PACKAGES) {
				// load package
				switch (filename[0]) {
					case SYS_PKG_CHAR:
						context.queuedPackageType = PKG_SYS;
						destination = replaceStack(filename+1,&pkgSystem);
						break;
					case APP_PKG_CHAR:
						context.queuedPackageType = PKG_APP;
						destination = replaceStack(filename+1,&pkgSystem);
						break;
					default:
						context.queuedPackageType = PKG_MSG;
						destination = replaceStack(filename,&pkgSystem);
						break;
				}
				context.queuedPackageNameIndex = destination;
			} else { // list->listType != LIST_OF_PACKAGES
				// play sound of subject
				newFile = getListFile(filename);
				newTime = 0;
				reposition = TRUE;
			}
			break;
		
		case JUMP_PACKAGE:
			if (aux == PKG_VARIABLE) {
				strcpy(filename,getCurrentList(&pkgSystem.lists[destination]));
				switch (filename[0]) {
					case SYS_PKG_CHAR:
						aux = PKG_SYS;
						destination = replaceStack(filename+1,&pkgSystem);
						break;
					case APP_PKG_CHAR:
						aux = PKG_APP;
						destination = replaceStack(filename+1,&pkgSystem);
						break;
					default:
						aux = PKG_MSG;
						destination = replaceStack(filename,&pkgSystem);
						break;
				}
			}
			context.queuedPackageType = aux;
			context.queuedPackageNameIndex = destination;
			break;  // sets up main loop to handle this, rather than building up a stack overflow

		case COPY:
			stop();
			tempList = &context.package->lists[destination];
			getListFilename(filename,destination,FALSE);
			cursor = getCurrentList(tempList);
			if (PRE_COPY_FILE_IDX)
				insertSound(&pkgSystem.files[PRE_COPY_FILE_IDX],NULL,TRUE);  
			ret = d2dCopy((const char *)filename,(const char *)cursor);
			if (ret == 0 && POST_COPY_FILE_IDX) 
				insertSound(&pkgSystem.files[POST_COPY_FILE_IDX],NULL,TRUE); 
//			newBlock = &context.package->blocks[aux];
//			newTime = newBlock->startTime;
//			reposition = TRUE;
			break;		

		case DELETE:
			stop();
			tempList = &context.package->lists[destination];
			getListFilename(filename,destination,TRUE);
			cursor = getCurrentList(tempList);			
			ret = findDeleteStringFromFile(LIST_PATH,filename,cursor,TRUE);
			tempList->currentFilePosition = -1; // forces next list action to reload
			if (ret != -1)
				ret = deletePackage(cursor);
			else
				logException(29,cursor,0);

			list = &context.package->lists[aux];
			context.idxActiveList = aux;
			newFile = getListFile(getCurrentList(list));
			newTime = 0;
			reposition = TRUE;

//			newBlock = &context.package->blocks[aux];
//			newTime = newBlock->startTime;
//			reposition = TRUE;
			break;
			
		case TRIM:
			stop();
			tempList = &context.package->lists[destination];
			cursor = getCurrentList(tempList);
			strcpy(filename,USER_PATH);
			strcat(filename,cursor);  //todo: address application packages
			strcat(filename,AUDIO_FILE_EXT);
			edit(filename);
			context.queuedPackageType = PKG_MSG;
			destination = replaceStack(cursor,context.package);
			context.queuedPackageNameIndex = destination;
			break;
			
		case SPEED_UP:
			adjustSpeed(SPEED_INCREMENT,TRUE);
			break;

		case SPEED_DOWN:
			adjustSpeed(-SPEED_INCREMENT,TRUE);
			break;

		case SPEED_NORMAL:
			adjustSpeed(NORMAL_SPEED,FALSE);
			break;

		case VOLUME_UP:
			adjustVolume(VOLUME_INCREMENT,TRUE,FALSE);
			break;

		case VOLUME_DOWN:
			adjustVolume(-VOLUME_INCREMENT,TRUE,FALSE);
			break;

		case VOLUME_NORMAL:
			adjustVolume(NORMAL_VOLUME,FALSE,FALSE);
			break;

		case LED_RED_ON:
			setLED(LED_RED,TRUE);
			break;	
			
		case LED_RED_OFF:
			setLED(LED_RED,FALSE);
			break;	

		case LED_GREEN_ON:
			setLED(LED_GREEN,TRUE);
			break;
			
		case LED_GREEN_OFF:	
			setLED(LED_GREEN,FALSE);
			break;

		case LED_ALL_ON:
			setLED(LED_ALL,TRUE);	
			break;	

		case LED_ALL_OFF:
			setLED(LED_ALL,TRUE);
			break;
			
		case USB_DEVICE_ON:
			setUSBDevice(TRUE);
			newBlock = &context.package->blocks[destination];
			newTime = newBlock->startTime;
			reposition = TRUE;
			break;	
					
		case USB_HOST_ON:
/*			stop();
			setUSBDevice(TRUE);
			newBlock = &context.package->blocks[destination];
			newTime = newBlock->startTime;
			reposition = TRUE;
*/			break;	
					
		case STOP:
			stop();
			enterOrExitAllBlocks(context.idxTimeframe,EXITING);
			break;

		case PLAY_PAUSE:
			status = SACM_Status();
			switch (status) {
				case 0:
//					if (context.package->pkg_type != PKG_SYS)
						markStartPlay(Snd_A1800_GetCurrentTime(),context.package->strHeapStack+context.package->idxName);
					if (context.idxActiveList == -1) {
						enterOrExitAllBlocks(context.idxTimeframe,ENTERING);
						i = getStartingBlockIdxFromTimeline(context.idxTimeframe);
						if (i != -1) 
							processStartBlock(i);
						play(context.file,getCurrentTimeframeStart());
					} else
						play(context.file,0);
					break;
				case C_SACM_RECORD:
				case C_SACM_PLAY:
					context.isPaused = TRUE;
					pause();
					break;
				case C_SACM_PAUSE:
					context.isPaused = FALSE;
					resume();	
					break;
				default:
					if (context.isPaused) {
						context.isPaused = FALSE;
						resume();	
					} else {
						context.isPaused = TRUE;
						pause();
					}		
					break;
			}
			break;
			
		case PAUSE:
			pause();
			context.isPaused = TRUE;
			break;
			
		case RECORD_TITLE: // deprecated
		case RECORD_MSG:
			stop();
/*			// Not currently allowing sound inserts before record commands since aux is used for recording from another headphone jack
			// Although the SPINS part of the headphone jack thing isn't currently working.
			if (action && hasSoundInsert(action)) {
				soundInsertBlock = &pkgSystem.blocks[getSoundInsertIdxFromAux(aux)];
				insertSound(getFileFromBlock(soundInsertBlock),soundInsertBlock,TRUE);
				wait(500);
			}
*/
			if(vCur_1 < V_MIN_RECORD_VOLTAGE) {
				refuse_lowvoltage(0);
				break;
			}
			
			cursor = getCurrentList(&pkgSystem.lists[context.package->idxMasterList]);
			do {
				strcpy(filename,USER_PATH);
				getPkgNumber(filename+strlen(USER_PATH),TRUE);
				strcat(filename,(const char *)CATEGORY_DELIM_STR);
				strcat(filename,cursor); // adds current listname to new recording name
				cursor2 = filename + strlen(filename);
				strcat(filename,AUDIO_FILE_EXT);
				ret = fileExists((LPSTR)filename); // this causes approx 1 sec delay!
			} while (ret);
			*cursor2 = 0; // remove extension
			strcpy(filename,filename+strlen(USER_PATH)); //remove path
			
			ret = createRecording(filename,aux,cursor);
			if (ret != -1) {
				destination = replaceStack(filename,context.package);
				context.queuedPackageNameIndex = destination;
				context.queuedPackageType = PKG_MSG;
			} else
				logException(28,"recording failed",RESET); //todo: add voice error msg?
			break;	

		case CALL_BLOCK:
			// TODO: handle error (return of -1) if stack is full
			stackPush(context.package,context.file,oldTime - getRewind(aux)); // times are compressed
			// this is designed to fall through
			
		case JUMP_BLOCK:
			newBlock = &context.package->blocks[destination];
			newTime = newBlock->startTime;
			reposition = TRUE;
			break;
	
		case RETURN:
			if (stackPop(&context.package,&newFile,&newTime))  // times are compressed 
				reposition = TRUE;
			break;

		case FWD:
			newActionCode = getStartEndCodeFromTimeframe(context.idxTimeframe,FORWARD_JUMPING, &newTime, &newIdxAction);
			switch (newActionCode) {
				case NOP:
				case PAUSE:
					break;
				case STOP:
					//rewind to give context before stopping
					newTime -= compressTime(BLOCK_END_LEADER,context.package->timePrecision);
					break;
				case JUMP_BLOCK:
					//follow this link
					newBlock = &context.package->blocks[context.package->actions[newIdxAction].destination];
					newTime = newBlock->startTime;
					break;
				case RETURN:
					stackPop(&context.package,&newFile,&newTime); //todo: double verify there was something on stack (shouldn't have gotten RETURN if not) 
					break;
				default:
					//no action needed
					break;
			}
			reposition = TRUE;
			break;
			
		case BACK:
			// test whether within the start leader to determine whether to go to last start or to previous start before that
			if ((oldTime - getCurrentTimeframeStart()) > compressTime(BLOCK_START_LEADER, context.package->timePrecision)) {
				// just move to start time of same timeframe 
				newTime = getCurrentTimeframeStart(); // must make sure we call the Start event 
			} else {
				newActionCode = getStartEndCodeFromTimeframe(context.idxTimeframe,BACKWARD_JUMPING, &newTime, &newIdxAction);
				switch (newActionCode) {
					case NOP:
					case PAUSE:
					case STOP:
						break;
					case JUMP_BLOCK:
						//follow this link
						newBlock = &context.package->blocks[context.package->actions[newIdxAction].destination];
						newTime = newBlock->startTime;
						break;  
					case RETURN:
						stackPop(&context.package,&newFile,&newTime); //todo: double verify there was something on stack (shouldn't have gotten RETURN if not) 
						break;
					default:
						//no action needed
						break;						
				}
			}
			reposition = TRUE;
			break;

		case JUMP_TIME:
			// skip forward/back from relative position
			// observe block boundary when they exist, but leap beyond them
			// todo:do not leap over newFile boundaries
			// if system package action, reset context to user package for this action
			if (context.returnPackage)
				context.package = context.returnPackage;
			if (context.package != &pkgSystem) {
				longOldTime = Snd_A1800_GetCurrentTime();
				l = (signed long)extractSignedTime(destination,context.package->timePrecision); // hoping this brings back an originally negative number
				longNewTime = longOldTime + l;
				if (l >= 0) 
					direction = FORWARD_JUMPING;
				else {
					direction = BACKWARD_JUMPING;
					if (abs(l) > longOldTime)
						longNewTime = 0;
				}
				newTime = compressTime(longNewTime,context.package->timePrecision);
	
				// check for interfering block events
				newIdxTimeframe = context.idxTimeframe;
				do {
					newActionCode = getStartEndCodeFromTimeframe(newIdxTimeframe,direction, &tempTime, &newIdxAction);
					if (direction == FORWARD_JUMPING) 
						isTooFar = blockTimeline[++newIdxTimeframe].time > newTime;
					else
						isTooFar = blockTimeline[--newIdxTimeframe].time < newTime;
				} while (!isTooFar && newActionCode == NOP);
				switch (newActionCode) {
					case JUMP_BLOCK:
						newBlock = &context.package->blocks[context.package->actions[newIdxAction].destination];
						newTime = newBlock->startTime;
						newFile = getFileFromBlock(newBlock);
						break;  
					case RETURN:
						stackPop(&context.package,&newFile,&newTime); //todo: double verify there was something on stack (shouldn't have gotten RETURN if not) 
						break;
					default:
						//no action needed
						break;
				}
				playActionSound(JUMP_TIME);
				reposition = TRUE;
			} // context is not system file
			break;
		case SLEEP:
			// call sleep function
			setOperationalMode((int)P_SLEEP); 
			break;
		case HALT:
			// call sleep function
			setOperationalMode((int)P_HALT); 
			break;
		case NOP:
			// no operation
			break;
		default:
			//nothing should default here
			logException(1,0,USB_MODE);
			break;
	}
		
	if (reposition) {
		//todo: am i catching every possible change in file?		
		if (newBlock && !newFile) 
			newFile = getFileFromBlock(newBlock);
		if (newFile && newFile != context.file) {
			enterOrExitAllBlocks(context.idxTimeframe,EXITING);
			context.file = newFile;
			if (!list)
				buildBlockTimelines(newFile);
			context.idxTimeframe = -1; // to signal it hasn't been set yet
			context.timeNextTimeframe = -1; // resets this -- necessary for lists that dont go to processTimelineJump
		}
		if (!list) {
			context.idxActiveList = -1;
			newIdxTimeframe = getIdxTimeline(newTime);
			if (newIdxTimeframe != context.idxTimeframe) 
				processTimelineJump(context.idxTimeframe, newIdxTimeframe);  // this resets context.idxTimeframe and context.timeNextTimeframe
		}
	}
	
	// now that context.idxTimeframe has been set for repositions, we can insert sounds
	if (action && hasSoundInsert(action)) {
		if (reposition) 
			stop();  // stop currently playing audio first or insertSound() will return to it
		if (actionCode == JUMP_TIME) {
			if (context.returnPackage)
				context.package = &pkgSystem;
			soundInsertBlock = &context.package->blocks[getSoundInsertIdxFromAux(aux)];
			insertSound(getFileFromBlock(soundInsertBlock),soundInsertBlock,TRUE);
		}
		else {
			soundInsertBlock = &context.package->blocks[getSoundInsertIdxFromAux(aux)];
			insertSound(getFileFromBlock(soundInsertBlock),soundInsertBlock,FALSE);
		}
	}
	// process start block action if landing on the start of a new block
	if (reposition && newBlock && newTime == newBlock->startTime)
		processStartBlock(newBlock - context.package->blocks);
	if (list) {
		soundInsertBlock = getStartInsert(list->actionStartEnd, list->idxFirstAction);
		if (soundInsertBlock)
			insertSound(getFileFromBlock(soundInsertBlock),soundInsertBlock,FALSE);
	}		
	if (actionCode == JUMP_TIME && context.returnPackage) {  // returning to user package after possibly inserting a system sound above
		context.package = context.returnPackage;
		context.returnPackage = NULL;
	}
	if (actionCode == SPEED_UP || actionCode == SPEED_DOWN) {
		context.isPaused = FALSE;
		resume();	
	}
	if (reposition)
		play(context.file,newTime); //todo: chg to seek if same file
	//todo: maybe for JUMP_BLOCK (not CALL_BLOCK) , allow offsets within a block (stored in first 13 bits of aux)
}
// update updates the current Camera and HUD objects, the lights and the sounds
//
void Coordinator::update() {

	
	if(console && userInput->pressed(CONSOLE_DISPLAY)){
			lastConsoleToggle = now; //probably useless
			console->toogle();
	}
	
	if(console->isOn()){
		console->update();
	}
	else{

		// toggle and update the current camera
		if (camera.size() && userInput->pressed(CAMERA_SELECT) && 
			now - lastCameraToggle > KEY_LATENCY) {
			lastCameraToggle = now;
			currentCam++;
			if (currentCam == camera.size())
				currentCam = 0;
		}
		if (camera.size() && camera[currentCam])
			camera[currentCam]->update();

		// toggle and update the current hud
		if (hud.size() && userInput->pressed(HUD_SELECT) &&
			now - lastHUDToggle > KEY_LATENCY) {
			lastHUDToggle = now;
			currentHUD++;
			if (currentHUD == hud.size())
				currentHUD = 0;
		}
		if (hud.size() && hud[currentHUD] && userInput->pressed(HUD_DISPLAY))
			hud[currentHUD]->toggle();
		if (hud.size() && hud[currentHUD]) 
			hud[currentHUD]->update();

		// update the volume and the frequency
		if (now - lastUpdate > KEY_LATENCY) {

			if (userInput->pressed(AUD_VOLUME_DEC))
				adjustVolume(-1);
			if (userInput->pressed(AUD_VOLUME_INC))
				adjustVolume(1);

			if (userInput->pressed(AUD_FREQ_DEC))
				adjustFrequency(-1);
			else if (userInput->pressed(AUD_FREQ_INC))
				adjustFrequency(1);
		}	

		// update the sound sources
		for (unsigned i = 0; i < sound.size(); i++)
			if (sound[i]) 
				sound[i]->update();

		// update the light sources
		for (unsigned i = 0; i < light.size(); i++)
			if (light[i])
				light[i]->update();
	}

}
Beispiel #18
0
unsigned int
checkVoltage() {	
	int v;
	unsigned long currentTimeInSec;
	unsigned int tripRate;
	APP_IRAM static unsigned long timeStartedFalling;
	APP_IRAM static unsigned int voltageStartedFalling;
	APP_IRAM static unsigned long timePaused = 0;
	APP_IRAM static unsigned int voltagePaused;
	APP_IRAM static unsigned int voltageAvgPaused;
	APP_IRAM static unsigned int readingsPaused = 0;
	char log[80];
	int isPlaying;

	v = getCurVoltageSample();
	isPlaying = (SACM_Status() && !context.isPaused);
	currentTimeInSec = getRTCinSeconds();

	if (v < V_MIN_RUN_VOLTAGE_TRANS) {
		forceflushLog();  // to ensure the log msg below is not beyond buffer
		strcpy(log,"SHUTTING DOWN - v < V_MIN_RUN (");
		longToDecimalString(v,log+strlen(log),3);
		strcat(log," < ");
		longToDecimalString(V_MIN_RUN_VOLTAGE_TRANS,log+strlen(log),3);		
		strcat(log,")");
		logString(log, BUFFER, LOG_ALWAYS);
		voltageShutdown();
	}
	
	if (isPlaying && timePaused)
		timePaused = 0;
	else if (!isPlaying && !timePaused) {
		timePaused = currentTimeInSec;
		voltageAvgPaused = voltagePaused = v;
		readingsPaused = 1;
	} else if (!isPlaying && timePaused) {
		readingsPaused++;
		if (readingsPaused >= 50 && ((v+10) < voltageAvgPaused)) {
			forceflushLog();  // to ensure the log msg below is not beyond buffer
			strcpy(log,(char *)"SHUTTING DOWN - Paused v:");
			longToDecimalString(v,log+strlen(log),3);
			strcat(log,(char *)" Avg:");
			longToDecimalString(voltageAvgPaused,log+strlen(log),3);
			strcat(log,(char *)" R:");
			longToDecimalString(readingsPaused,log+strlen(log),5);
			logString(log , BUFFER, LOG_ALWAYS);
			voltageShutdown();
		} 
		voltageAvgPaused = ((long)voltageAvgPaused * (long)(readingsPaused-1) + v) / readingsPaused;
		voltagePaused = v;
	}
	
	if (v > v_high)
		v_high = v;
	if (v < v_low)
		v_low = v;
	if(v < vCur_1) {	// if voltage < vCur_1 set a bit in vThresh_1
		vThresh_1++;
	} else {
		// remember v & t for short-term voltage rate calculation when threshold is reached
		voltageStartedFalling = v;
		timeStartedFalling = currentTimeInSec;
		if (v > vCur_1)
			vThresh_1 = 0;
	}
	if((isPlaying && vThresh_1 == 8) || (!isPlaying && vThresh_1 == 2)) { //low samples when playing or paused
		unsigned int delta_voltage = vCur_1 - v;
//		unsigned int delta_voltage_trans = voltageStartedFalling - v;
		unsigned int voltageDropRateStatic = 0;
//		unsigned int voltageDropRateTrans = 0;
		unsigned int voltageDropTime = currentTimeInSec - tCur_1;
//		unsigned int voltageDropTimeTrans = currentTimeInSec - timeStartedFalling;
		
		if (delta_voltage >= 2)
			voltageDropRateStatic = (delta_voltage * 10) / (voltageDropTime?voltageDropTime:1);// don't divide by 0
/*		if (delta_voltage_trans >= 2)
			voltageDropRateTrans = (delta_voltage_trans * 10) / (voltageDropTimeTrans?voltageDropTimeTrans:1);// don't divide by 0
*/		vCur_1 = v;
		vThresh_1 = 0;	// reset threshold bits

		if (vCur_1 < V_MIN_RUN_VOLTAGE) {
			forceflushLog();  // to ensure the log msg below is not beyond buffer
			logString("SHUTTING DOWN - vCur_1 < V_MIN_RUN_VOLTAGE" , BUFFER, LOG_ALWAYS);
			voltageShutdown();
		}
		
		if (delta_voltage >= 2 /*|| delta_voltage_trans >= 2*/) {
			if (isPlaying)
				strcpy(log,(char *)"PLAYING ");
			else
				strcpy(log,(char *)"PAUSED ");
			strcat(log, (char *) "VOLTAGE DROP: 0."); 
			longToDecimalString((long)delta_voltage,log+strlen(log),2);
/*			strcat(log,(char *)"v/0.");
			longToDecimalString((long)delta_voltage_trans,log+strlen(log),2);
*/			strcat(log,(char *) "v in ");
			longToDecimalString((long)voltageDropTime,log+strlen(log),4);
/*			strcat(log, (char *) " sec/");
			longToDecimalString((long)voltageDropTimeTrans,log+strlen(log),4);
*/			strcat(log, (char *) " sec");
			logString(log,BUFFER, LOG_ALWAYS);		
						
			strcpy(log, (char *) "VOLTAGE DROP RATE: "); 
			longToDecimalString((long)voltageDropRateStatic, log+strlen(log), 3);
/*			strcat(log, (char *) "/"); 
			longToDecimalString((long)voltageDropRateTrans, log+strlen(log), 3);
*/			logString(log,BUFFER, LOG_ALWAYS);
					
			if (isPlaying) {
				if (vCur_1 < 220) 
					tripRate = 75;
				else if (vCur_1 < 320)
					tripRate = 200;
				else 
					tripRate = 300;
			} else {
				if (vCur_1 < 220) 
					tripRate = 20;
				else if (vCur_1 < 320)
					tripRate = 75;
				else 
					tripRate = 150;
			}
						
			if (voltageDropRateStatic >= tripRate && v < 350) { 
				forceflushLog();  // to ensure the log msg below is not beyond buffer
				logString("SHUTTING DOWN - Static voltage dropping fast" , BUFFER, LOG_ALWAYS);
				voltageShutdown();
			} else if (voltageDropRateStatic >= tripRate * 0.8) {
				adjustVolume(-1,TRUE,FALSE);  // getting too close; lower volume
				playBip();
			} else			
				set_voltmaxvolume(FALSE);				
		}		
		tCur_1 = currentTimeInSec;
	}
	return v;
}
Beispiel #19
0
int RadioManagerOld::openRadio(int frequencySection,int channel,int volumeArg)
{

	printf("++++++++++++++++++++++++++++++ RadioManagerOld::openRadio++++++++++++++++++++++++++++\n");
	int  searchFlag =0;
	if(channel ==0)
	{
		searchFlag =1;
		
		if(m_voiceSwithFunction !=NULL)
		{
			m_voiceSwithFunction(RM_VOICE_SWITCH_OFF,m_voiceSwithUserData);
			m_voiceStatus =RM_VOICE_SWITCH_OFF;
		}

		if(frequencySection==RM_FREQ_SECTION_FM)
		{
			channel =RM_FM_FREQ_MIN;
		}
		else
		{
			frequencySection =RM_FREQ_SECTION_AM;
			channel     	 =RM_AM_FREQ_MIN;
		}
	}
	else
	{
		if(frequencySection == RM_FREQ_SECTION_FM)
		{
			if(channel<RM_FM_FREQ_MIN || channel>RM_FM_FREQ_MAX)
				return RM_R_ERROR_RANGE;
		}
		else
		{
			if(channel<RM_AM_FREQ_MIN || channel>RM_AM_FREQ_MAX)
				return RM_R_ERROR_RANGE;

			frequencySection =RM_FREQ_SECTION_AM;
		}
			
	}
	

	int result =openRadioAtChannel(frequencySection,channel,searchFlag);

	if(result !=RM_R_OK)
		return result;

	adjustVolume(volumeArg,RM_VOLUME_SET);

	if(searchFlag!=0)
	{
		status =RM_STATUS_SEARCH;

		listenedChannel =0;
		lastSearchChannel     =0;
		currentSearchChannel =channel;

		channelMeter 	=0;
		searchedChannel =0;
		meterIsUping	=0;

		if(frequencySection == RM_FREQ_SECTION_FM)
			timeId =startTimer(RM_FM_SEARCH_INTERVAL);
		else
			timeId =startTimer(RM_AM_SEARCH_INTERVAL);

		emit searchChannelChanged(lastSearchChannel,currentSearchChannel);
	}
	else
	{
		listenedChannel =channel;
		status =RM_STATUS_LISTEN;
	}

	return RM_R_OK;
}
void C3200VolumeService::increaseVolume(int increment)
{
    adjustVolume(increment, increment, Relative);
}
Beispiel #21
0
void startUp(void) {
	char buffer[200];
	char strCounts[20];
	int key;
	
	SetSystemClockRate(MAX_CLOCK_SPEED); // to speed up initial startup -- set CLOCK_RATE later

	setDefaults();
	setLED(LED_RED,FALSE);  // red light can be left on after reprog restart
	setLED(LED_GREEN,TRUE);  // red light can be left on after reprog restart
	
	//to stop user from wondering if power is on and possibly cycling too quickly,
	playDing();  // it is important to play a sound immediately 
	
	key = keyCheck(1);  // long keycheck 
	
	// voltage checks in SystemIntoUSB.c
	if (key == KEY_STAR || key == KEY_MINUS) {
		// allows USB device mode no matter what is on memory card
		Snd_Stop();
		SystemIntoUDisk(1);	
		loadConfigFile();
		processInbox();
		resetSystem();
	} else if (key == KEY_PLUS) {
		// outbox mode: copy outbox files to connecting device
		loadConfigFile();
		copyOutbox();
		resetSystem();
	}	
	
	// check for new firmware first, but don't flash if voltage is low
	if(V_MIN_SDWRITE_VOLTAGE <= vCur_1) {
		check_new_sd_flash();
	}
	
	if (loadConfigFile() == -1) // config.txt file not found
		testPCB();	
	if (!SNexists())
		logException(32,(const char *)"no serial number",SHUT_DOWN);		

	SysDisableWaitMode(WAITMODE_CHANNEL_A);
	adjustVolume(NORMAL_VOLUME,FALSE,FALSE);
	adjustSpeed(NORMAL_SPEED,FALSE);
	loadDefaultPackage();
	if (MACRO_FILE)	
		loadMacro();
	loadSystemCounts();
	systemCounts.powerUpNumber++;
	if (systemCounts.powerUpNumber - systemCounts.lastLogErase > MAX_PWR_CYCLES_IN_LOG) {
		systemCounts.lastLogErase = systemCounts.powerUpNumber;
		clearStaleLog();	
	}
#ifndef TB_CAN_WAKE
	resetRTC();  //  reset before saving anything to disk and running macros
#endif	
	saveSystemCounts();
	
	strcpy(buffer,"\x0d\x0a" "---------------------------------------------------\x0d\x0a");
	strcat(buffer,getDeviceSN(1));
	strcpy(strCounts,(char *)" counts:S");
	longToDecimalString(systemCounts.powerUpNumber, strCounts+9, 4); 
	strcat(strCounts,(char *)"P");
	longToDecimalString(systemCounts.packageNumber, strCounts+14, 4); 
	strcat(strCounts,(char *)"R");
	longToDecimalString(systemCounts.revdPkgNumber, strCounts+19, 4);
	strcat(buffer,strCounts); 
	strcat(buffer,"\x0d\x0a" "CYCLE "); //cycle number
	longToDecimalString(systemCounts.powerUpNumber,(char *)(buffer+strlen(buffer)),4);
	strcat(buffer,(const char *)" - version " VERSION);
	logString(buffer,BUFFER);
#ifdef TB_CAN_WAKE
	logRTC();  
#endif
	loadPackage(PKG_SYS,BOOT_PACKAGE);	
	SetSystemClockRate(CLOCK_RATE); // either set in config file or the default 48 MHz set at beginning of startUp()
	mainLoop();
}
Beispiel #22
0
static void processBlockEnterExit (CtnrBlock *block, EnumEnterOrExit enteringOrExiting) {
	unsigned int code, LEDhyperlink, speedChange, volumeChange;
	BOOL red, green, onoff, fliponoff;
	APP_IRAM static unsigned int enteringVolume;

	code = block->actionEnterExit;
	if (enteringOrExiting == ENTERING) {
		code &= 0x00FF;
		enteringVolume = getVolume();
	}
	else {
		if (context.isHyperlinked && ((code & 0x00FF) == 0x04)) { // checks if enter action was hyperlink
			context.isHyperlinked = FALSE;
			setLED(LED_RED,FALSE);
		}
		code >>= 8;
	}

	if (code) {
		LEDhyperlink = code & 0x0F; // bits 0-3
		speedChange  = (code & 0x30) >> 4;  // bits 4-5
		volumeChange = (code & 0xC0) >> 6; // bits 6-7
	
		switch (speedChange) {
			case 0x01:
				adjustSpeed(3,TRUE);
				break;
			case 0x02:
				adjustSpeed(-3,TRUE);
				break;
			case 0x03:
				adjustSpeed(NORMAL_SPEED,FALSE);
				break;
		}
		switch (volumeChange) {
			case 0x01:
				adjustVolume(3,TRUE,TRUE);
				break;
			case 0x02:
				adjustVolume(-3,TRUE,TRUE);
				break;
			case 0x03:
				//return to user selected volume
				restoreVolume(FALSE);
				break;
		}  // switch
		if (LEDhyperlink == 0x04) {
			if (enteringOrExiting == ENTERING) {
				context.isHyperlinked = TRUE;
				context.USB = FALSE;
				setLED(LED_RED,TRUE);
				insertSound(&pkgSystem.files[HYPERLINK_SOUND_FILE_IDX],NULL,TRUE);
			}
			else {
				context.isHyperlinked = FALSE;
				setLED(LED_RED,FALSE);
			}
		}
		else {
			if (LEDhyperlink == 0x08) { 
				context.USB = TRUE;
				stop();
				setUSBDevice(TRUE);
			}
			else {
				green = LEDhyperlink & 0x01;
				red = LEDhyperlink & 0x02;
				onoff = LEDhyperlink & 0x04;
				fliponoff = LEDhyperlink & 0x08;
				
				if ((green && onoff) || (green && fliponoff))	
					setLED(LED_GREEN,TRUE);
				else if ((green && !onoff) || (!green && fliponoff))	
					setLED(LED_GREEN,FALSE);
				if ((red && onoff) || (red && fliponoff))
					setLED(LED_RED,TRUE);
				else if ((red && !onoff) || (!red && fliponoff))	
					setLED(LED_RED,FALSE);
			}
		}			
	}  //	if (code)
}