int main(void) { u32 stretch; u32 samp_i; /* Initialisation de plb_ac97 : */ XAC97_HardReset(PLB_AC97_BASEADDR); XAC97_InitAudio(PLB_AC97_BASEADDR, 0); XAC97_ClearFifos(PLB_AC97_BASEADDR); /* Ajustement du volume audio : */ XAC97_WriteReg(PLB_AC97_BASEADDR, AC97_MasterVol, AC97_VOL_MAX); XAC97_WriteReg(PLB_AC97_BASEADDR, AC97_AuxOutVol, AC97_VOL_ATTN_6_0_DB); XAC97_WriteReg(PLB_AC97_BASEADDR, AC97_PCMOutVol, AC97_VOL_ATTN_6_0_DB); /* Boucler : */ for (;;) { for (samp_i = 0; samp_i < NUM_SAMPLES; ++samp_i) { for (stretch = 0; stretch < STRETCH; ++stretch) { XAC97_WriteFifo(PLB_AC97_BASEADDR, g_samples[samp_i]); } } } return 0; }
// Inits the AC97. Note: you must also enable interrupts by either calling // sound_initInterupts, or create your own interrupt handler routine. void sound_initAC97() { XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR); XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA); XAC97_AwaitCodecReady(XPAR_AXI_AC97_0_BASEADDR); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCM_DAC_Rate, AC97_PCM_RATE_11025_HZ); XAC97_AwaitCodecReady(XPAR_AXI_AC97_0_BASEADDR); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XAC97_Delay(100000); }
int interruptManager (unsigned int * framePointer0) { init_platform(); // Initialize the GPIO peripherals. int success; // Used for CPU utilization. Uncomment if desired // XTmrCtr_Initialize(instPtr, 0); success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); // Enable the global GPIO interrupt for push buttons. XGpio_InterruptGlobalEnable(&gpPB); // Enable all interrupts in the push button peripheral. XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF); // Reset the XAC97 Chip XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XAC97_mSetControl(AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA); setVolLevel(AC97_VOL_MAX); clearAllSounds(); microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); // Uncomment for CPU utilization stats /*XTmrCtr Timer; XTmrCtr *instPtr = &Timer; XTmrCtr_Initialize(instPtr, 0); XTmrCtr_Start(instPtr, 0);*/ while(!isEndOfGame()); // Program never ends. // Uncomment for CPU utilization stats /*XTmrCtr_Stop(instPtr, 0); int val = (int) XTmrCtr_GetValue(instPtr, 0); xil_printf("%d\n\r", val);*/ clearAllSounds(); XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR); drawGameOver(); cleanup_platform(); return 0; }
// 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 } }
void Foliage::SoundManager::init() { // hard reset & initialization XAC97_HardReset(XPAR_AUDIO_CODEC_BASEADDR); XAC97_InitAudio(XPAR_AUDIO_CODEC_BASEADDR, AC97_ANALOG_LOOPBACK); XAC97_DisableInput(XPAR_AUDIO_CODEC_BASEADDR, AC97_MIC_INPUT); XAC97_DisableInput(XPAR_AUDIO_CODEC_BASEADDR, AC97_LINE_INPUT); XAC97_AwaitCodecReady(XPAR_AUDIO_CODEC_BASEADDR); // volume settings XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_MasterVol, AC97_VOL_MAX); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_AuxOutVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_MasterVolMono, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_PCBeepVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_PhoneInVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_MicVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_LineInVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_CDVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_VideoVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_AuxInVol, AC97_VOL_MUTE); XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_PCMOutVol, AC97_VOL_MAX); XAC97_AwaitCodecReady(XPAR_AUDIO_CODEC_BASEADDR); // VRA mode OFF XAC97_WriteReg(XPAR_AUDIO_CODEC_BASEADDR, AC97_ExtendedAudioStat, 0); // clear FIFOs XAC97_ClearFifos(XPAR_AUDIO_CODEC_BASEADDR); // interrupt XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR, XPAR_OPB_INTC_0_AUDIO_CODEC_INTERRUPT_INTR, (XInterruptHandler)Foliage::SoundManager::AC97_Callback, NULL); XAC97_mSetControl(XPAR_AUDIO_CODEC_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); std::cout << " * sound manager initialized" << std::endl; }