/***************************************************************************************
 * Pushbutton - Interrupt Service Routine                                
 *                                                                          
 * This ISR checks which KEY has been pressed. If KEY1, then it enables audio-in
 * interrupts (recording). If KEY2, it enables audio-out interrupts (playback).
****************************************************************************************/
void pushbutton_ISR(struct alt_up_dev *up_dev, unsigned int id)
{
	alt_up_audio_dev *audio_dev;
	audio_dev = up_dev->audio_dev;
	
	int KEY_value;

	/* read the pushbutton interrupt register */
	KEY_value = alt_up_parallel_port_read_edge_capture (up_dev->KEY_dev);
	alt_up_parallel_port_clear_edge_capture (up_dev->KEY_dev);	// clear the interrupt

	if (KEY_value == 0x2)										// check KEY1
	{
		// reset the buffer index for recording
		buf_index_record = 0;
		// clear audio FIFOs
		alt_up_audio_reset_audio_core (audio_dev);
		// enable audio-in interrupts
		alt_up_audio_enable_read_interrupt (audio_dev);
	}
	else if (KEY_value == 0x4)									// check KEY2
	{
		// reset counter to start playback
		buf_index_play = 0;
		// clear audio FIFOs
		alt_up_audio_reset_audio_core (audio_dev);
		// enable audio-out interrupts
		alt_up_audio_enable_write_interrupt (audio_dev);
	}
	return;
}
Beispiel #2
0
void disableSound()
{
	printf("disable\n");
	sound_data_counter = 0;
	alt_up_audio_disable_write_interrupt(audio_dev);
	alt_up_audio_reset_audio_core(audio_dev);
}
Beispiel #3
0
/* 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);
}
Beispiel #4
0
void game_reset(master* m) {
	alt_up_audio_disable_write_interrupt(m->ab->audio_dev);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_1_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_2_BASE, 4, 1 << 3);


	sd_fclose(m->ab->wav);
	reset_audio_buffer(m->ab);
	alt_up_audio_reset_audio_core(m->ab->audio_dev);
}
Beispiel #5
0
void av_config_setup(){
	printf("Configuring audio and video.\n");
	alt_up_av_config_dev * av_config = alt_up_av_config_open_dev("/dev/audio_and_video_config_0");
	while (!alt_up_av_config_read_ready(av_config));

	printf("Opening audio device.\n");

	audio = alt_up_audio_open_dev("/dev/audio_0");

	alt_up_audio_reset_audio_core(audio);
}
Beispiel #6
0
//Initializes audio & video core, will not return until succuessful
void av_config_setup() {
	bool once = true;
	alt_up_av_config_dev * av_config = alt_up_av_config_open_dev(AV_CONFIG);
	while(!alt_up_av_config_read_ready(av_config)) {
		if(once) {
			printf("Error, audio not configured.\n");
			once = false;
		}
	}
	audio = alt_up_audio_open_dev(AUDIO_DEV);
	alt_up_audio_reset_audio_core(audio);
}
Beispiel #7
0
int initAudioCore(alt_up_audio_dev* audio) {

	alt_up_audio_reset_audio_core(audio);

	if (audio == NULL) {
		return AUDIO_ERROR;
	}


	alt_up_audio_enable_write_interrupt(audio);

	return 0;
}
/**
 * Initializes the AudioController
 */
struct AudioController* initAudioController() {
	av_config_setup();

	struct AudioController* this = (struct AudioController*)malloc(sizeof(struct AudioController));

	this->buffer_length = 0;
	this->num_sounds = 0;
	this->audio = alt_up_audio_open_dev(AUDIO_NAME);
	this->clear_required = false;
	this->start_dirty_index = 0;
	this->end_dirty_index = 0;
	this->buffer = NULL;
//	alt_irq_register(AUDIO_IRQ, this, (void*) audio_ISR);
//	alt_irq_enable(AUDIO_IRQ);
	alt_up_audio_reset_audio_core(this->audio);

	return this;
}
Beispiel #9
0
void play_wav (unsigned int **arr)
{
	alt_up_audio_reset_audio_core(audio);
	unsigned int * input;
	int k = 0;
	input = arr[k];
	while (1) {
		if (alt_up_audio_write_interrupt_pending(audio) == 1)
		{
			alt_up_audio_write_fifo(audio, input, 100, ALT_UP_AUDIO_LEFT);
			alt_up_audio_write_fifo(audio, input, 100, ALT_UP_AUDIO_RIGHT);
			k++;
			input = arr[k];
		}
		if (k >= 4377)
			break;
	}

}
Beispiel #10
0
//initializes audio buffer
int initAudio(char* fname) {
	alt_up_sd_card_dev *device_reference = NULL;
	device_reference = alt_up_sd_card_open_dev(SD_CARD_NAME);

	open_sd();

	av_config_setup();
	init_audio_buff(ab);

	ab->audio = alt_up_audio_open_dev(AUDIO_0_NAME);
	alt_up_audio_reset_audio_core(ab->audio);

	file_handle = alt_up_sd_card_fopen(fname, 0);
	offset(file_handle, ab);

	fill_buff(file_handle, ab);

	return file_handle;
}
Beispiel #11
0
void resetAudio(void)
{
	alt_up_audio_reset_audio_core(audio);
}
Beispiel #12
0
void init_wav(unsigned int *arr[])
{
	printf("Initializing wav file\n");
	int i,j,k;
	int size_of_wav = 0;
	int location = 0;
	unsigned int buffer[100] = {0};
	unsigned int * soundbuf;
	soundbuf = (unsigned int*) malloc(sizeof(char) * size_of_wav);

	audio = alt_up_audio_open_dev(AUDIO_DEV);
	alt_up_audio_reset_audio_core(audio);
	//alt_up_audio_enable_write_interrupt(audio);
	/*
		sound_file = alt_up_sd_card_fopen("WAV2.WAV", false);
		//printf("Soundfile: %d\n", sound_file);
		if (sound_file != -1) {
			printf("File opened.\n");
			while(alt_up_sd_card_read(sound_file) != -1) {
				size_of_wav++;
			}
			printf("Size of wav: %d\n", size_of_wav);

			if(alt_up_sd_card_fclose(sound_file))
				printf("File closed.\n");
			else
				printf("Error closing file.\n");
		}
	 */
	size_of_wav = 875484;
	size_of_sound = (int) size_of_wav/200;
	//printf("Size of sound: %d\n", size_of_sound);
	//printf("Size of wav: %d\n", size_of_wav);
	sound_file = alt_up_sd_card_fopen("wav2.wav", false);

	if (sound_file != -1) {
		//printf("File opened.\n");
		for(i = 0; i<size_of_wav; i++){
			soundbuf[i] = alt_up_sd_card_read(sound_file);
		}
		/*
		 * debugging WAV header
		 *
			printf("ChunkSize: 0x%02x%02x%02x%02x\n", soundbuf[7], soundbuf[6], soundbuf[5], soundbuf[4]);
			printf("SubChunkSize: 0x%02x%02x%02x%02x\n", soundbuf[19], soundbuf[18], soundbuf[17], soundbuf[16]);
			printf("Audio Format: 0x%02x%02x\n", soundbuf[21], soundbuf[20]);
			printf("Channels : 0x%02x%02x\n", soundbuf[23], soundbuf[22]);
			printf("Samplerate: 0x%02x%02x%02x%02x\n", soundbuf[27], soundbuf[26], soundbuf[25], soundbuf[24]);
			printf("Bitrate: 0x%02x%02x%02x%02x\n", soundbuf[31], soundbuf[30], soundbuf[29], soundbuf[28]);
			printf("Blockalign: 0x%02x%02x\n", soundbuf[33], soundbuf[32]);
			printf("BitsPerSample: 0x%02x%02x\n", soundbuf[35], soundbuf[34]);
			printf("Data mark: %c%c%c%c\n", soundbuf[210], soundbuf[211], soundbuf[212], soundbuf[213]);
			printf("Subchunksize2: 0x%02x%02x%02x%02x\n", soundbuf[217], soundbuf[216], soundbuf[215], soundbuf[214]);
			datasize = soundbuf[217] * pow(16,6) + soundbuf[216] * pow(16,4) + soundbuf[215] * pow(16,2) + soundbuf[214];
			printf("Datasize: %d\n", datasize);
			printf("Chunks:");
			for (i = 218; i < 318; i++) {
				printf(" %02x", soundbuf[i]);
			}
			printf("\n");
		 */
		for(i = 0; i<size_of_wav; i++){
			if (soundbuf[i] == 'd') {
				if (soundbuf[i+1] == 'a'){
					if (soundbuf[i+2] == 't'){
						if (soundbuf[i+3] == 'a') {
							location = i;
							break;
						}
					}

				}
			}
		}
		i = location;
		for (k = 0; k<size_of_sound; k++) {
			for (j = 0; j<100; j++){
				buffer[j] = convert(soundbuf[i+1], soundbuf[i]);
				i = i + 2;
			}
			arr[k] = (unsigned int*)malloc(sizeof(buffer));
			memcpy((void*)arr[k], (void*)buffer, sizeof(buffer));
		}

	}
	free(soundbuf);
}
Beispiel #13
0
euint8 open_wav(SDfile fileinfo)
{
	euint8 buff[600];
	euint32 buff2[512];
	euint32 right[512];
	euint32 left[512];
	euint8 leftovers[512];
	euint8 leftoverCount=0;
	euint32 count = 0;
	euint32 i,zz;
	euint32 tempright;
	euint32 temp[5];
	euint32 overflow_amount = 0;
	euint32 LoopC = 0;
	euint32 stuff_to_write = 0;
	euint32 ints_to_send = 0;
	euint32 sample_rate = 0;
	euint32 bitdepth = 0;
	euint32 channels = 0;
	euint32 formatcode = 0;
	euint32 blocksize = 0;
	euint32 header_size = 0;
	euint32 next_address = 0;
	euint32 clust_address = 0;
	euint32 FAT_address = 0;
	euint32 filesize = 0;
	euint32 end_offset = 0;
	euint32 bytes_read = 0;
	euint8 end_of_file = 0;

	alt_up_audio_dev*  audio_dev = alt_up_audio_open_dev(AUDIO_NAME);
	alt_up_audio_reset_audio_core(audio_dev);

	filesize = fileinfo.file_size;

	FAT_address = (euint32)fileinfo.startL | ((euint32)fileinfo.startH)<<16;

	clust_address = (FAT_address-2)*Part_Boot.sec_per_clust + clust_start;

	sd_readSector(clust_address,buff);		//read in wav header info
	bytes_read += 512;

	//address = next_sect_address(address);

	header_size = get_wav_header(buff,&sample_rate,&bitdepth,&channels,&formatcode,&blocksize); //psuedo code for reading in wav details, returns wav info

	if(formatcode != 1)
	{
		UART_write("Error: incorrect wav format type, please use PCM\n\r");
		return(1);
	}
	if(channels != 2)
	{
		UART_write("Error, number of channels must be 2\n\r");
		return(1);
	}
	if((bitdepth != 32)&&(bitdepth != 16)&&(bitdepth != 24)&&(bitdepth != 8))
	{
		UART_write("Error, bitdepth is incorrect\n\r");
		return(1);
	}
	if(sample_rate != 8000)
		{
			UART_write("Error, sample rate is incorrect\n\r");
			return(1);
		}
	switch(sample_rate)
		{
		  case 8000:  AUDIO_SetSampleRate(RATE_ADC8K_DAC8K_USB); break;
		  case 32000: AUDIO_SetSampleRate(RATE_ADC32K_DAC32K_USB); break;
		  case 44100: AUDIO_SetSampleRate(RATE_ADC44K_DAC44K_USB); break;
		  case 48000: AUDIO_SetSampleRate(RATE_ADC48K_DAC48K_USB); break;
		  case 96000: AUDIO_SetSampleRate(RATE_ADC96K_DAC96K_USB); break;
		  default:  printf("Non-standard sampling rate\n"); return -1;
	   }
	count = count + header_size;
	while(end_of_file == 0)	//start reading bytes from offset position, if  there are bytes to be read, continue
	{
		//convert char buffer into 32 bit buffer
		while(LoopC < Part_Boot.sec_per_clust)
		{
			if(bitdepth == 32)
			{
				for(i=0;i<128;i++)
				{
					*((unsigned char*)&buff2[i]+0) = buff[count+0];
					*((unsigned char*)&buff2[i]+1) = buff[count+1];
					*((unsigned char*)&buff2[i]+2) = buff[count+2];
					*((unsigned char*)&buff2[i]+3) = buff[count+3];
					count += 4;
					if(count > 512)
					{
						ints_to_send = i+1;
						break;
					}
					if(i==127) ints_to_send = i+1;
				}
				count = 0;
			}
			if(bitdepth == 24)
			{
				for(i=0;i<170;i++)		// PROBLEM HERE PROBS SINCE 512/3 ISNT WHOLE NUMBER
				{
					*((unsigned char*)&buff2[i]+0) = 0;
					*((unsigned char*)&buff2[i]+1) = buff[count+0];
					*((unsigned char*)&buff2[i]+2) = buff[count+1];
					*((unsigned char*)&buff2[i]+3) = buff[count+2];
					count += 3;
					if(count >= 512)
					{
						count = (count-512)+3;
						ints_to_send = i+1;
						break;
					}
				}
			}
			if(bitdepth == 16)
			{
				for(i=0;i<256;i++)
				{
					*((unsigned char*)&buff2[i]+0) = 0;
					*((unsigned char*)&buff2[i]+1) = 0;
					*((unsigned char*)&buff2[i]+2) = buff[count+0];
					*((unsigned char*)&buff2[i]+3) = buff[count+1];
					count += 2;

					if(count > 512)
					{
						ints_to_send = i+1;
						break;
					}
					if(i==255) ints_to_send = i+1;
				}
				count = 0;
			}
			if(bitdepth == 8)
			{
				for(i=0;i<512;i++)
				{
					*((unsigned char*)&buff2[i]+0) = 0;
					*((unsigned char*)&buff2[i]+1) = 0;
					*((unsigned char*)&buff2[i]+2) = 0;
					*((unsigned char*)&buff2[i]+3) = buff[count+0];
					count++;

					if(count > 512)
					{
						ints_to_send = i+1;
						break;
					}
					if(i==511) ints_to_send = i+1;
				}
				count = 0;
			}
			// pass to left and right channels
			for(i=0;i<256;i++)
			{
				left[i] = buff2[i*2];
				right[i] = buff2[i*2+1];
			}

			if(end_offset != 0)
			{
				stuff_to_write = end_offset/(1024/ints_to_send);
				end_of_file = 1;
				end_offset = 0;
			}
			else
			{
				stuff_to_write = ints_to_send/2;
			}
			//is there space in the fifo?
			while(alt_up_audio_write_fifo_space(audio_dev,0) < stuff_to_write);
			//send to audio channels
			alt_up_audio_write_fifo(audio_dev,right,stuff_to_write,ALT_UP_AUDIO_RIGHT);
			alt_up_audio_write_fifo(audio_dev,left,stuff_to_write,ALT_UP_AUDIO_LEFT);
			clust_address++;
			sd_readSector(clust_address,buff);
			bytes_read += 512;
			LoopC++;
			if(bytes_read >= filesize)
			{
				end_of_file = 1;
				//end_offset = 512 - (bytes_read-filesize);
			}
		}
		LoopC = 0;
		clust_address = next_sect_address(FAT_address,&next_address);
		FAT_address = next_address;
		if(bytes_read >= filesize)
		{
			end_of_file = 1;
			//end_offset = 512 - (bytes_read-filesize);
		}
	}
	return(0);
}