void B2dPlay::DrawHill(b2Vec2 start,b2Vec2 end,float stepWidth,int width,int peak){ int steps = width/stepWidth; float sideStepCount = steps/2; float inclinePerStep = peak/(sideStepCount); float innerHeight = peak/sideStepCount; b2Vec2 vertices[4]; b2Vec2 startPos = start; for(int i = 1;i<= steps;i++){ if(i>steps/2){ GetVertsInclineSquare(vertices,stepWidth,innerHeight,(-1*inclinePerStep)); GenSquare(vertices,world,startPos); startPos.x += vertices[1].x+(vertices[1].x); startPos.y +=-(((inclinePerStep/2))); }else{ GetVertsInclineSquare(vertices,stepWidth,innerHeight,inclinePerStep); GenSquare(vertices,world,startPos); startPos.x += vertices[2].x+(vertices[2].x); startPos.y +=(inclinePerStep/2); } } }
int main() { init_platform(); static XGpio pshBtns; static XIntc intCtrl; Xuint32 Sample_L; Xuint32 Sample_R; pAudioData = (DDR2_BASEADDR + 0x02000000); pFFTData = (pAudioData + lNumSamples); lBtnStateOld = 0x00000000; fsRunAction = 0; /* *Initialize the driver structs for the Push button and interrupt cores. *This allows the API functions to be used with these cores. */ XGpio_Initialize(&pshBtns, BTNS_DEVICE_ID); XIntc_Initialize(&intCtrl, INTC_DEVICE_ID); /* * Connect the function PushBtnHandler to the interrupt controller so that * it is called whenever the Push button GPIO core signals an interrupt. */ XIntc_Connect(&intCtrl, BTNS_IRPT_ID, PushBtnHandler, &pshBtns); /* * Enable interrupts at the interrupt controller */ XIntc_Enable(&intCtrl, BTNS_IRPT_ID); /* * Register the interrupt controller with the microblaze * processor and then start the Interrupt controller so that it begins * listening to the interrupt core for triggers. */ microblaze_register_handler(XIntc_DeviceInterruptHandler, INTC_DEVICE_ID); microblaze_enable_interrupts(); XIntc_Start(&intCtrl, XIN_REAL_MODE); /* * Enable the push button GPIO core to begin sending interrupts to the * interrupt controller in response to changes in the button states */ XGpio_InterruptEnable(&pshBtns, lBtnChannel); XGpio_InterruptGlobalEnable(&pshBtns); /* * Wait for AC97 to become ready */ while (!(AC97_Link_Is_Ready(AC97_BASEADDR))) ; /* * Set TAG to configure codec */ AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800); /* * Enable audio output and set volume */ AC97_Unmute(AC97_BASEADDR, AC97_MASTER_VOLUME_OFFSET); AC97_Unmute(AC97_BASEADDR, AC97_HEADPHONE_VOLUME_OFFSET); AC97_Unmute(AC97_BASEADDR, AC97_PCM_OUT_VOLUME_OFFSET); AC97_Set_Volume(AC97_BASEADDR, AC97_MASTER_VOLUME_OFFSET, BOTH_CHANNELS, VOLUME_MAX); AC97_Set_Volume(AC97_BASEADDR, AC97_HEADPHONE_VOLUME_OFFSET, BOTH_CHANNELS, VOLUME_MIN); AC97_Set_Volume(AC97_BASEADDR, AC97_PCM_OUT_VOLUME_OFFSET, BOTH_CHANNELS, VOLUME_MAX); while (1) { /************************** * Play recorded sample **************************/ if (sampleMax != 0) { if (fsRunAction & bitPlay) { /* * Set AC'97 codec TAG to send and receive data in the PCM slots */ AC97_Set_Tag_And_Id(AC97_BASEADDR, 0x9800); Count_Samples = 0; // Xil_Out32(LED_BASEADDR, bitPlayLED); //turn on LED int showLED = 0; while ((Count_Samples / 8) < lNumSamples) { /* * Block execution until next frame is ready */ AC97_Wait_For_New_Frame(AC97_BASEADDR); /* * Read audio data from memory */ Sample_L = XIo_In32 (pAudioData + Count_Samples); Count_Samples = Count_Samples + 4; Sample_R = XIo_In32 (pAudioData + Count_Samples); Count_Samples = Count_Samples + 4; /* our code */ /* if(Count_Samples < 100) { */ // printf("Left: %i",(int)Sample_L); // printf("Right: %i",(int)Sample_R); /* } */ if (showLED % 4000 == 0) { /* middleLeft /= 8000; middleRight /= 8000; */ // Xil_Out32(LED_BASEADDR, Sample_L & AC97_META_MASK); // printf("Left: %d",(int)Sample_L); // printf("Right: %d",(int)Sample_R); setVolumeLEDs(Sample_L & AC97_DATA_MASK, Sample_R & AC97_DATA_MASK); /* middleLeft = 0; middleRight = 0; } else { middleLeft += Sample_L; middleRight += Sample_R; */ } /* * Send audio data to codec */XIo_Out32 ((AC97_BASEADDR + AC97_PCM_OUT_L_OFFSET), Sample_L); XIo_Out32 ((AC97_BASEADDR + AC97_PCM_OUT_R_OFFSET), Sample_R); showLED++; } Xil_Out32(LED_BASEADDR, 0); //Turn off LED fsRunAction = 0; //Forget any button presses that occurred } } /************************** * Output a square wave **************************/ if (fsRunAction & bitGenWave) { //generate square on left, right and then both channels GenSquare(AC97_BASEADDR, LEFT_CHANNEL, 1000, 500); GenSquare(AC97_BASEADDR, RIGHT_CHANNEL, 1000, 500); GenSquare(AC97_BASEADDR, BOTH_CHANNELS, 1000, 500); fsRunAction = 0; } /************************** * LEDTest **************************/ if (fsRunAction & bitLEDTest) { /* Xil_Out32(LED_BASEADDR, volumeLED0); sleepTimer(1000); Xil_Out32(LED_BASEADDR, volumeLED1); sleepTimer(1000); Xil_Out32(LED_BASEADDR, volumeLED2); sleepTimer(1000); Xil_Out32(LED_BASEADDR, volumeLED3); sleepTimer(1000); Xil_Out32(LED_BASEADDR, volumeLED4); sleepTimer(5000); Xil_Out32(LED_BASEADDR, volumeLED5); sleepTimer(5000); Xil_Out32(LED_BASEADDR, volumeLED6); sleepTimer(5000); Xil_Out32(LED_BASEADDR, volumeLED7); sleepTimer(5000); Xil_Out32(LED_BASEADDR, 0); Xil_Out32(LED_BASEADDR, allLEDs); sleepTimer(5000); Xil_Out32(LED_BASEADDR, 0); fsRunAction = 0;*/ Xil_Out32(LED_BASEADDR, volumeLED7); fftSample(pAudioData, lNumSamples, 0); Xil_Out32(LED_BASEADDR, 0); // fftSample(pFFTData, pAudioData, lNumSamples, 1); // addOriginMeta(); // if (compareValues(pAudioData, pFFTData)) { // Xil_Out32(LED_BASEADDR, allLEDs); // sleepTimer(5000); // Xil_Out32(LED_BASEADDR, 0); // Xil_Out32(LED_BASEADDR, allLEDs); // sleepTimer(5000); // Xil_Out32(LED_BASEADDR, 0); // } else { // Xil_Out32(LED_BASEADDR, volumeLED0); // sleepTimer(1000); // Xil_Out32(LED_BASEADDR, volumeLED1); // sleepTimer(1000); // Xil_Out32(LED_BASEADDR, volumeLED2); // sleepTimer(1000); // Xil_Out32(LED_BASEADDR, volumeLED3); // sleepTimer(1000); // Xil_Out32(LED_BASEADDR, volumeLED4); // } fsRunAction = 0; } /************************** * Record audio from input **************************/ if (fsRunAction & bitRec) { AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800); //Set to configure /* * Select input source, enable it, and then set the volume */ if (Xil_In32(SW_BASEADDR) & bitSw0) { AC97_Select_Input(AC97_BASEADDR, BOTH_CHANNELS, AC97_LINE_IN_SELECT); AC97_Unmute(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET); AC97_Set_Volume(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET, BOTH_CHANNELS, VOLUME_MAX); } else { AC97_Select_Input(AC97_BASEADDR, BOTH_CHANNELS, AC97_MIC_SELECT); AC97_Unmute(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET); AC97_Set_Volume(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET, BOTH_CHANNELS, VOLUME_MID); } //set record gain AC97_Set_Volume(AC97_BASEADDR, AC97_RECORD_GAIN_OFFSET, BOTH_CHANNELS, 0x00); AC97_Set_Tag_And_Id(AC97_BASEADDR, 0x9800); //Set to Send/Receive data Count_Samples = 0; Xil_Out32(LED_BASEADDR, bitRecLED); //Turn on LED middle = 0; sampleMax = MIN_UINT; countSamples = 0; sampleMin = MAX_UINT; while ((Count_Samples / 8) < lNumSamples) { AC97_Wait_For_New_Frame(AC97_BASEADDR); /* * Read audio data from codec */ Sample_L = XIo_In32(AC97_BASEADDR + AC97_PCM_IN_L_OFFSET); Sample_R = XIo_In32(AC97_BASEADDR + AC97_PCM_IN_R_OFFSET); /* * our code */ captureSampleReference(Sample_L & AC97_DATA_MASK, Sample_R & AC97_DATA_MASK); /* * Write audio data to memory */ XIo_Out32 (pAudioData + Count_Samples, Sample_L); Count_Samples = Count_Samples + 4; XIo_Out32 (pAudioData + Count_Samples, Sample_R); Count_Samples = Count_Samples + 4; } //Set Tag and ID to configure the codec AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800); /* * Disable the input source */ if (Xil_In32(SW_BASEADDR) & bitSw0) { AC97_Mute(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET); } else { AC97_Mute(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET); } middle = middle / countSamples; Xil_Out32(LED_BASEADDR, 0); //Turn off LED fsRunAction = 0; } } cleanup_platform(); return 0; }