예제 #1
0
/**
 * @brief Play the MP3 music file
 *
 */
void playMusic() {

	hMP3Decoder = MP3InitDecoder();
	InitializeAudio(Audio44100HzSettings);
	SetAudioVolume(0xCF);
	PlayAudioWithCallback(AudioCallback, 0);
}
예제 #2
0
int main()
{
	InitializeSystem();
	SysTick_Config(HCLKFrequency()/100);
	InitializeLEDs();

	InitializeAccelerometer();
	InitializeAnglephone();

	InitializeAudio(Audio22050HzSettings);
	SetAudioVolume(0x60);

	PlayAudioWithCallback(AudioCallback, 0);

	while(1)
	{
		SetLEDs(0x5);
		Delay(100);
		SetLEDs(0xA);
		Delay(100);
	}
}
예제 #3
0
static void play_mp3(char* filename) {
	unsigned int br, btr;
	FRESULT res;

	bytes_left = FILE_READ_BUFFER_SIZE;
	read_ptr = file_read_buffer;

	if (FR_OK == f_open(&file, filename, FA_OPEN_EXISTING | FA_READ)) {

		// Read ID3v2 Tag
		char szArtist[120];
		char szTitle[120];
		Mp3ReadId3V2Tag(&file, szArtist, sizeof(szArtist), szTitle, sizeof(szTitle));

		// Fill buffer
		f_read(&file, file_read_buffer, FILE_READ_BUFFER_SIZE, &br);

		// Play mp3
		hMP3Decoder = MP3InitDecoder();
		InitializeAudio(Audio44100HzSettings);
		SetAudioVolume(0xAF);
		PlayAudioWithCallback(AudioCallback, 0);

		for(;;) {
			/*
			 * If past half of buffer, refill...
			 *
			 * When bytes_left changes, the audio callback has just been executed. This
			 * means that there should be enough time to copy the end of the buffer
			 * to the beginning and update the pointer before the next audio callback.
			 * Getting audio callbacks while the next part of the file is read from the
			 * file system should not cause problems.
			 */
			if (bytes_left < (FILE_READ_BUFFER_SIZE / 2)) {
				// Copy rest of data to beginning of read buffer
				memcpy(file_read_buffer, read_ptr, bytes_left);

				// Update read pointer for audio sampling
				read_ptr = file_read_buffer;

				// Read next part of file
				btr = FILE_READ_BUFFER_SIZE - bytes_left;
				res = f_read(&file, file_read_buffer + bytes_left, btr, &br);

				// Update the bytes left variable
				bytes_left = FILE_READ_BUFFER_SIZE;

				// Out of data or error or user button... Stop playback!
				if (br < btr || res != FR_OK || BUTTON)
				  {
					StopAudio();

					// Re-initialize and set volume to avoid noise
					InitializeAudio(Audio44100HzSettings);
					SetAudioVolume(0);

					// Close currently open file
					f_close(&file);

					// Wait for user button release
					while(BUTTON){};

					// Return to previous function
					return;
				}
			}
		}
	}
}
예제 #4
0
파일: main.c 프로젝트: ahmedjafri/EE478
int main(void) {
	init();

        currentWriteBuffer = mp3_data;
        currentReadBuffer = mp3_data2;
        
        mySPI_Init();                           //Init SPI for comm with Pi
        
        //initialize SPI rx buffer counter
        rxIndex = 0;
        
        
        /* Enable the Rx buffer not empty interrupt */
        SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);
        
        /* send initial pulse for RPi to send data*/
        GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        //sending end of pulse
        if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_RXNE) != SET)
        {
          GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        }
        
        //wait until data buffer loaded first time (change?)
        while (!dataRxComplete) 
        {
            dataRxComplete = dataRxComplete;
        }
        
        //rxIndex = 0;                    //reset rxIndex (do in interrupt?)
        dataRxComplete = 0;
        
        flipBuffers();
        
	hMP3Decoder = MP3InitDecoder();
                
        //Send need more data GPIO signal
        
	InitializeAudio(Audio44100HzSettings);
	SetAudioVolume(0xCF);
        PlayAudioWithCallback(AudioCallback, 0);
        
        
	while(1) { 
          
//                while(!dataRxComplete) 
//                {
//                     dataRxComplete = dataRxComplete;        
//                }
//                dataRxComplete = 0;
//                
//                //flip buffers
//                char *tempBuffer = currentReadBuffer;
//                currentReadBuffer = currentWriteBuffer;
//                currentWriteBuffer = tempBuffer;
//                
//                
//                GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
//                GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
              
	}
}
예제 #5
0
static void play_mp3(char* filename) {

	bool out_of_data;
	int cc;


	// Open file
	if (FR_OK == f_open(&file, filename, FA_OPEN_EXISTING | FA_READ)) {

		// Read ID3v2 Tag
		char szArtist[120];
		char szTitle[120];
		Mp3ReadId3V2Tag(&file, szArtist, sizeof(szArtist), szTitle, sizeof(szTitle));


		///////////////////////////////////////////////////////////buffer starts getting filled for first time
		// Start Initial fill of buffer
		hMP3Decoder = MP3InitDecoder();
		for (cc = 0 ; cc < NUMBER_BUFFERS ; cc++ ) {
			out_of_data = fill_mp3_buffer(&file,cc);

			if ( out_of_data ) {
				break;
			}
		}

		// Initialize buffer counters
		buffer_read = 0;
		buffer_write = 0;

/////////////////////////////////////////////////////////////////////////////////////////
		// Play mp3
		running_player = true;
		InitializeAudio(Audio44100HzSettings);
		// InitializeAudio(Audio32000HzSettings);
		SetAudioVolume(0xAF);
		PlayAudioWithCallback(AudioCallback, 0);
//////////////////////////////////////////////////////////////////////////////////////////
		for(;;) {
			/*
			 *  If we have an unused buffer, call fill_mp3_buffer to fill it.
			 */
			if ( buffer_read != buffer_write ) {


				// Refill the MP3 buffer
				out_of_data = fill_mp3_buffer(&file,buffer_write);

				if ( !out_of_data ) {
					buffer_write = ( buffer_write + 1 ) % NUMBER_BUFFERS;
				}

				// Out of data or error or user button... Stop playback!
				if (out_of_data || (exitMp3 == 1))
				{
					StopAudio();
					running_player = false;

					// Re-initialize and set volume to avoid noise
					InitializeAudio(Audio44100HzSettings);
					SetAudioVolume(0);

					// Close currently open file
					f_close(&file);
					return;
				}


			}
			else {
				// We don't have any work to do, shut down until interrupt (DMA transfer complete)
				__asm__ volatile ("wfi");
			}
		}
	}