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; }
int main() { init_platform(); // Initialize the GPIO peripherals. 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); interrupts_init(); print("made it past interrupts_init\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); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_MasterVol, AC97_VOL_MAX); XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCMOutVol, AC97_VOL_MAX); while (1); cleanup_platform(); return 0; }
/* Audio Codec Intialization \param[in] Xuint32 ac97 */ void audio_init_ac97(Xuint32 ac97) { XAC97_HardReset(ac97); XAC97_WriteReg(ac97, AC97_MasterVol, AC97_VOL_ATTN_9_0_DB); XAC97_WriteReg(ac97, AC97_AuxOutVol, AC97_VOL_ATTN_9_0_DB); XAC97_WriteReg(ac97, AC97_PCMOutVol, AC97_VOL_ATTN_9_0_DB); XAC97_WriteReg(ac97, AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA); XAC97_WriteReg(ac97, AC97_PCM_DAC_Rate, AC97_PCM_RATE_48000_HZ); }
// 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); }
void sound_setVolume(int volume) { if(volume > MAX_VOLUME) volume = MAX_VOLUME; if(volume < MIN_VOLUME) volume = MIN_VOLUME; volumeLevel = volume; XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCMOutVol, sound_getAC97Attn(volume)); }
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; }
/* Ac97 Volume Volume has been divided into 8 levels to correspond to 8 leds \param[in] Xuint32 volume */ void audio_set_volume(Xuint32 address, int volume) { Xuint32 v = 0; #define VOL(val, def) case val: v = def; break; switch(volume) { VOL(0, AC97_VOL_ATTN_44_5_DB); VOL(1, AC97_VOL_ATTN_41_5_DB); VOL(2, AC97_VOL_ATTN_35_5_DB); VOL(3, AC97_VOL_ATTN_29_5_DB); VOL(4, AC97_VOL_ATTN_23_5_DB); VOL(5, AC97_VOL_ATTN_17_5_DB); VOL(6, AC97_VOL_ATTN_11_5_DB); VOL(7, AC97_VOL_ATTN_6_0_DB); VOL(8, AC97_VOL_ATTN_0_DB); default: break; } XAC97_WriteReg(address, AC97_PCMOutVol, v); XAC97_WriteReg(address, AC97_MasterVol, AC97_VOL_MAX ); XAC97_WriteReg(address, AC97_AuxOutVol, AC97_VOL_MAX); XAC97_WriteReg(address, AC97_MasterVolMono, AC97_VOL_MAX); }
void audio_mute(Xuint32 address) { XAC97_WriteReg(address, AC97_MasterVol, AC97_VOL_MUTE ); XAC97_WriteReg(address, AC97_MasterVol, AC97_VOL_MUTE ); XAC97_WriteReg(address, AC97_AuxOutVol, AC97_VOL_MUTE); XAC97_WriteReg(address, AC97_MasterVolMono, AC97_VOL_MUTE); }
void audio_set_sampling(Xuint32 address, Xuint32 freq) { XAC97_WriteReg(address, AC97_PCM_DAC_Rate, freq); }
void volume_up(){ vol_level = (vol_level==0) ? vol_level : --vol_level; // don't dec if maxed out uint32_t vol = AC97_VOL_MAX + volumes[vol_level]; XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCMOutVol, vol); }
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; }