// This function writes data to the XAC97. void fifo_writer(int* array, int frameNums){ int diff; if (indexInArray == 0){ // This means that the function will begin playing a new sound pointInArray = array; // The pointInArray iterator is set to the beginning of the sound array setSwitchContext(false); // Disable the ability to assign new sound flags } if (indexInArray + XAC97_FIFO_BUFFER_SIZE >= frameNums){ // This means we've reached the end of a sound data array diff = indexInArray + XAC97_FIFO_BUFFER_SIZE - frameNums; // This is the number of array locations to the end of the array XAC97_PlayAudio(XPAR_AXI_AC97_0_BASEADDR, pointInArray, pointInArray+diff); // Play the audio pointInArray = array; // Reset the point in the array indexInArray = 0; // Reset the index in the array setSwitchContext(true); // Allow other sound flags to be set clearAllSounds(); // Clear all sounds (except for the saucerHighPitch) XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR); // Clear the FIFO of all data XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); // Re-enable interrupts } else { XAC97_PlayAudio(XPAR_AXI_AC97_0_BASEADDR, pointInArray, pointInArray+XAC97_FIFO_BUFFER_SIZE);// This means we're in the middle of a sound data array pointInArray += XAC97_FIFO_BUFFER_SIZE; // Increment the pointInArray by how much was written to FIFO indexInArray += XAC97_FIFO_BUFFER_SIZE; // Increment the indexInArray by how much was written to FIFO } }
int main() { init_platform(); print("Hello World\n\r"); // apparently we don't need to init it, just HardReset XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_ExtendedAudioStat, 1); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCM_DAC_Rate, AC97_PCM_RATE_11025_HZ); while (1) { XAC97_PlayAudio(XPAR_AXI_AC97_0_BASEADDR, tankFireSound, &tankFireSound[tankFireSoundFrames]); XAC97_Delay(1000000); } cleanup_platform(); return 0; }