Example #1
0
void pcmRF::play(char* filename, byte device){
  stop();
  rfPlaying = 1;

	if(device == 255){
		radi.openWritingPipe(addresses[1]);
	}else{
		radi.openWritingPipe(addresses[device+2]);
	}


	#if !defined(SDFAT)
		if(!txFile){ txFile = SD.open(filename);}
		if(txFile){
		txFile.seek(24); //skip the header info
	#else
		if(!txFile.isOpen()){ txFile.open(filename);}
		if(txFile.isOpen()){
		txFile.seekSet(24); //skip the header info
	#endif


    unsigned int SAMPLE_RATE = txFile.read();
    SAMPLE_RATE |= txFile.read() << 8;

    #if !defined(SDFAT)
    	txFile.seek(44);
	#else
		txFile.seekSet(44);
	#endif

	unsigned int res = (10 * (1600000/SAMPLE_RATE)) * 32;


	noInterrupts();
	ICR1 = res;
	TCCR1A = _BV(WGM11);
	TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
	TIMSK1 = ( _BV(OCIE1A) );
	interrupts();

  }else{
	  #if defined (debug)
		  Serial.println("failed to open music file");
	  #endif
  }
}



ISR(TIMER1_COMPA_vect){
	radi.writeFast(&buff,32);
	txFile.read((byte*)buff,32);
	if(txFile.available() < 32){ radi.txStandBy(); stop(); }
}