//initialize irq for audio write void initialize_audio_irq() { printf("Initializing Audio IRQ...\n"); alt_up_audio_disable_read_interrupt(audio_dev); alt_up_audio_disable_write_interrupt(audio_dev); printf("Audio IRQ initialized...\n"); }
/* The audio task is responsible for continuously playing music * off the SD card. */ void audio_task(void *pdata) { int err = 0; err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x00); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_LINE_IN, 0x97); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_LINE_IN, 0x97); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_HEADPHONE_OUT, 0x79); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_HEADPHONE_OUT, 0x79); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ANALOG_AUDIO_PATH_CTRL, 0x12); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_DIGITAL_AUDIO_PATH_CTRL, 0x05); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_POWER_DOWN_CTRL, 0x07); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_AUDIO_DIGITAL_INTERFACE, 0x42); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_SAMPLING_CTRL, 0x22); err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x01); err += audio_set_headphone_volume(av_dev, DEFAULT_VOLUME); if(err < 0) printf("Audio Configuration Failed\n"); alt_up_audio_reset_audio_core(audio_dev); alt_up_audio_disable_read_interrupt(audio_dev); alt_up_audio_disable_write_interrupt(audio_dev); char fileName[10] = {"class.wav\0"}; if (file_fopen(&readFile, &efsl.myFs, fileName, 'r') != 0) printf("Error:\tCould not open file\n"); int readSize = 0; euint32 currentSize = 44; euint8 buf[AUDIO_BUF_SIZE]; int i; /* The task is suspended so that it can be played by another task. */ OSTaskSuspend(AUDIO_TASK_PRIORITY); while(1) { if (currentSize < readFile.FileSize) { int fifospace = alt_up_audio_write_fifo_space(audio_dev, ALT_UP_AUDIO_LEFT); if (fifospace > WORD_COUNT) { readSize = file_fread(&readFile, currentSize, AUDIO_BUF_SIZE, buf); currentSize += readSize; i = 0; while(i < AUDIO_BUF_SIZE) { IOWR_ALT_UP_AUDIO_LEFTDATA(audio_dev->base, (buf[i+1]<<8)|buf[i]); IOWR_ALT_UP_AUDIO_RIGHTDATA(audio_dev->base, (buf[i+3]<<8)|buf[i+2]); i+=4; } } } else { currentSize = 44; } } file_fclose(&readFile); }
int set_audio_interrupt(alt_up_audio_dev *audio, volatile int edge_capture_thing) { // Need to disable both audio interrupts before setting them up // otherwise you get stuck in them when they are setup alt_up_audio_disable_read_interrupt(audio); alt_up_audio_disable_write_interrupt(audio); void *edge_pointer = (void*)&edge_capture_thing; #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT return alt_ic_isr_register(AUDIO_CORE_IRQ_INTERRUPT_CONTROLLER_ID, AUDIO_CORE_IRQ, playMusicISR, edge_pointer, 0x0); #else return alt_irq_register(AUDIO_CORE_IRQ, edge_pointer, playMusicISR); #endif }
int main(void) { device_reference = alt_up_sd_card_open_dev("/dev/SD_Card"); if (device_reference != NULL) { while(1) { if ((connected == 0) && (alt_up_sd_card_is_Present())) { printf("Card connected.\n"); if (alt_up_sd_card_is_FAT16()) { printf("FAT16 file system detected.\n"); //Print out the list in the sd card handler = alt_up_sd_card_find_first("", buffer_name); printf("%s \n", buffer_name); //Read a file in SD card -needs to speed up(10 sec?) - needs array of int sd_fileh = alt_up_sd_card_fopen("TEST.WAV", false); if (sd_fileh < 0) printf("Problem reading file. Error %i\n", sd_fileh); else { printf("Reading file...\n"); audio_dev = alt_up_audio_open_dev (AUDIO_NAME); if ( audio_dev == NULL){ return; } av_config = alt_up_av_config_open_dev(AUDIO_AND_VIDEO_CONFIG_NAME); while(!alt_up_av_config_read_ready(av_config)); alt_up_audio_disable_read_interrupt(audio_dev); alt_up_audio_enable_write_interrupt(audio_dev); /* // Get information of number of channels //count = 0; char a, b; int d; short c; int index = 0; while (buffer_name[index] != "\0"){ a = alt_up_sd_card_read(sd_fileh); b = alt_up_sd_card_read(sd_fileh); c = ((unsigned char) a <<8) | (unsigned char) b; d = c; d = alt_up_audio_write_fifo(device_reference,d,) index++; } */ /* // printf("NumChannels "); byte1 = 0;byte2 = 0;total = 0; byte1 = alt_up_sd_card_read(sd_fileh); byte2 = alt_up_sd_card_read(sd_fileh); total = (byte1 & 0x00ff) | (byte2 << 8); NumChannels = total; // printf("%d\n",total); // printf("SampleRate "); byte1 = 0;byte2 = 0;byte3 = 0;byte4 = 0;long_total = 0; byte1 = alt_up_sd_card_read(sd_fileh); byte2 = alt_up_sd_card_read(sd_fileh); byte3 = alt_up_sd_card_read(sd_fileh); byte4 = alt_up_sd_card_read(sd_fileh); long_total = (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | ( byte1 & 0x000000ff); sampleRate = long_total; // printf("%ld\n",long_total); */ /* count = 0; while (count < 16) // 44-byte header { alt_up_sd_card_read(sd_fileh); count++; } */ } //find next file while ((handler = alt_up_sd_card_find_next(buffer_name)) != -1) printf("%s \n", buffer_name); }else{ printf("Unknown file system.\n"); } connected = 1; } else if ((connected == 1) && (alt_up_sd_card_is_Present() == false)) { printf("Card disconnected.\n"); connected = 0; } } } return 0; }