int main (void) { TC_init(); interrupt_init(); USART_init(); DDRA = 0b00000001; //set direction of PORTA, A0 is output for speaker sei(); // turn on interrupts while (1) { if( signal == 2 )//Once signaled that we have enough samples, we calculate the frequency { duration = total / sample; //Find average duration freq = (unsigned int)(99990ul / (unsigned long)duration); //calculate frequency //If hit was valid, take away health from player and go into method that plays appropriate sounds if(freq > 200 && freq < 260){ health -= 30; playSound(freq); } signal = 0; total = 0; sample = 0; } } return 0; }
void SPR_init(u16 cacheSize) { u16 index; u16 size; // already initialized --> end it first if (SPR_isInitialized()) SPR_end(); // alloc cache structure memory VDPSpriteCache = MEM_alloc(SPRITE_CACHE_SIZE * sizeof(VDPSprite)); size = cacheSize?cacheSize:384; // get start tile index for sprite cache (reserve VRAM area just before system font) index = TILE_FONTINDEX - size; // init tile cache engine if needed TC_init(); // and create a tile cache for the sprite TC_createCache(&tcSprite, index, size); }