Beispiel #1
0
void mp3_pause(int pause)
{
	if (mp3_thread >= 0)
	{
		if (mp3_running)
		{
			if (pause)
			{
				if (mp3_status == MP3_PLAY)
				{
					mp3_status = MP3_PAUSE;
					sceKernelSuspendThread(mp3_thread);
					memset(mp3_out[0], 0, MP3_BUFFER_SIZE);
					memset(mp3_out[1], 0, MP3_BUFFER_SIZE);
					sceAudioOutputPannedBlocking(mp3_handle, 0, 0, mp3_out[0]);
				}
			}
			else
			{
				if (mp3_status == MP3_PAUSE)
				{
					mp3_status = MP3_PLAY;
					sceKernelResumeThread(mp3_thread);
				}
				else if (mp3_status == MP3_SLEEP)
				{
					mp3_status = MP3_PLAY;
					sceKernelWakeupThread(mp3_thread);
				}
			}
		}
	}
}
int pspAudioOutBlocking(unsigned int channel, unsigned int vol1, unsigned int vol2, void *buf)
{
	if (!audio_ready) return -1;
	if (channel>=PSP_NUM_AUDIO_CHANNELS) return -1;
	if (vol1>PSP_VOLUME_MAX) vol1=PSP_VOLUME_MAX;
	if (vol2>PSP_VOLUME_MAX) vol2=PSP_VOLUME_MAX;
	return sceAudioOutputPannedBlocking(AudioStatus[channel].handle,vol1,vol2,buf);
}
Beispiel #3
0
int audio_OutputPannedBlocking(unsigned int channel, unsigned int vol1, unsigned int vol2, void *buf)
{
	if(!audio_ready) return -1;
	if(channel >= CHANNELS) return -1;
	if(vol1 > MAXVOLUME) vol1=MAXVOLUME;
	if(vol2 > MAXVOLUME) vol2=MAXVOLUME;
	return sceAudioOutputPannedBlocking(audio_handles[channel], vol1, vol2, buf);
}
Beispiel #4
0
int OSPC_PlayThread (SceSize ,void *) {
	for (;;) {			   	
		ospc->run(-1,(int16*)snd_buffer,(int)(1024*4));    			
		sceAudioOutputPannedBlocking( OSPC_sound_fd, OSPC_volume, OSPC_volume, (char*)snd_buffer);
				
		if (OSPC_exit) break;
  }
}
Beispiel #5
0
static void PSPAUDIO_PlayDevice(_THIS)
{
    Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];

    if (this->spec.channels == 1) {
        sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
    } else {
        sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
    }

    this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
}
Beispiel #6
0
// Don't do it with blocking
inline bool PspAudio::playBuffer() {
	DEBUG_ENTER_FUNC();
	int ret;
	if (_numOfChannels == 1)
		ret = sceAudioOutputBlocking(_pspChannel, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]);
	else
		ret = sceAudioOutputPannedBlocking(_pspChannel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]);

	if (ret < 0) {
		PSP_ERROR("failed to output audio. Error[%d]\n", ret);
		return false;
	}
	return true;
}
Beispiel #7
0
/* psp_audio_channel_thread:
 *  This PSP thread manages the audio playing.
 */
static int psp_audio_channel_thread()
{
   while (psp_audio_on) {
      void *bufptr = &sound_buffer[curr_buffer];
      /* Asks to the Allegro mixer to fill the buffer */
      _mix_some_samples((uintptr_t)bufptr, 0, IS_SIGNED);
      /* Send mixed buffer to sound card */
      sceAudioOutputPannedBlocking(hw_channel, PSP_AUDIO_VOLUME_MAX,
         PSP_AUDIO_VOLUME_MAX, bufptr);
      curr_buffer = !curr_buffer;
   }

   sceKernelExitThread(0);

   return 0;
}
Beispiel #8
0
void
psp_audio_thread(int args, void *argp)
{
  int buff_id = 0;
  char* snd_buff = 0;
	while (psp_audio_term == 0) {
    if (psp_audio_sleep || (! HUGO.hugo_snd_enable)) {
      snd_buff = psp_audio_empty;
    } else {
      snd_buff = psp_audio_buffer[buff_id];
      MixSound( snd_buff, 1024 );
      buff_id = ! buff_id;
    }
    sceAudioOutputPannedBlocking(psp_audio_chid, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, snd_buff);
	}
	sceKernelExitThread(0);
}
Beispiel #9
0
void
psp_cdaudio_thread(int args, void *argp)
{
  char* snd_buff = 0;
  int buff_id = 0;
	while (psp_audio_term == 0) {
    if (psp_audio_sleep || (! HUGO.hugo_snd_enable) || (! HUGO.hugo_cdaudio_enable)) {
      myPowerSetClockFrequency(HUGO.psp_cpu_clock);
      snd_buff = psp_audio_empty;
    } else {
      snd_buff = psp_cdaudio_buffer[buff_id];
      if (! MP3Callback(snd_buff, 1024, NULL)) {
        snd_buff = psp_audio_empty;
      } else {
        myPowerSetClockFrequency(HUGO.psp_cpu_cdclock);
        buff_id = ! buff_id;
      }
    }
    sceAudioOutputPannedBlocking(psp_cdaudio_chid, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, snd_buff);
	}
	sceKernelExitThread(0);
}
Beispiel #10
0
static int MP3OutputThread(SceSize args, void *argp){
	while(mp3_play) {
		if (mp3_pause) {
			sceKernelDelayThread(1000);
			continue;
		}
		if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) {
			mp3_play = 0;
			continue;
		}
		if ( mp3_header_buffer[0] == 'T' && mp3_header_buffer[1] == 'A' && mp3_header_buffer[2] == 'G' ) {
			mp3_play = 0;
			continue;
		}
		unsigned int mp3_header = mp3_header_buffer[0];
		mp3_header = (mp3_header<<8) | mp3_header_buffer[1];
		mp3_header = (mp3_header<<8) | mp3_header_buffer[2];
		mp3_header = (mp3_header<<8) | mp3_header_buffer[3];
		
		if ( (mp3_header & 0xFFFE0000) != 0xFFFA0000) {
			sceIoLseek32(mp3_file_handle, -3, PSP_SEEK_CUR);
			continue;
		}
		
		int bitrate = (mp3_header & 0xf000) >> 12;
		int padding = (mp3_header & 0x200) >> 9;
		
		int frame_size = 144000*mp3_bitrates[bitrate]/mp3_samplerate + padding;
		
		if ( mp3_data_buffer )
			free(mp3_data_buffer);
		mp3_data_buffer = (unsigned char*)memalign(64, frame_size);
		if ( !mp3_data_buffer ) {
			sceIoLseek32(mp3_file_handle, -4, PSP_SEEK_CUR);
			continue;
		}
		sceIoLseek32(mp3_file_handle, -4, PSP_SEEK_CUR);
		if ( sceIoRead( mp3_file_handle, mp3_data_buffer, frame_size ) != frame_size ) {
			mp3_play = 0;
			continue;
		}
		memset(mp3_output_buffer[mp3_output_buffers], 0, MP3_SAMPLE_COUNT * 4);
		mp3_codec_buffer[6] = (unsigned long)mp3_data_buffer;
		mp3_codec_buffer[8] = (unsigned long)mp3_output_buffer[mp3_output_buffers];
		
		mp3_codec_buffer[7] = mp3_codec_buffer[10] = frame_size;
		mp3_codec_buffer[9] = MP3_SAMPLE_COUNT * 4;
	
		sceAudiocodecDecode(mp3_codec_buffer, 0x1002);
		
		sceAudioOutputPannedBlocking(mp3_audio_channel, mp3_volume, mp3_volume,mp3_output_buffer[mp3_output_buffers]);
		
		mp3_output_buffers = (mp3_output_buffers+1)%2;
		
	}
	if ( mp3_data_buffer ){
		free(mp3_data_buffer);
		mp3_data_buffer = 0;
	}
	sceKernelExitThread(0);
	return 0;
}
Beispiel #11
0
static void MP3Update(void)
{
	int flip;
	UINT8 *GuardPtr;
	INT16 *OutputPtr, *OutputEnd;
	struct mad_stream Stream;
	struct mad_frame Frame;
	struct mad_synth Synth;
	mad_timer_t Timer;

	mad_stream_init(&Stream);
	mad_frame_init(&Frame);
	mad_synth_init(&Synth);
	mad_timer_reset(&Timer);

	OutputPtr = (INT16 *)mp3_out[0];
	OutputEnd = (INT16 *)(mp3_out[0] + MP3_BUFFER_SIZE);
	GuardPtr = NULL;

	mp3_filepos = 0;
	mp3_frame = 0;
	flip = 0;
	cdda_command_ack = 1;

	while (mp3_active && mp3_status != MP3_STOP)
	{
		if (Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
		{
			UINT32 ReadSize, Remaining;
			UINT8 *ReadStart;

			if (Stream.next_frame != NULL)
			{
				Remaining = Stream.bufend - Stream.next_frame;
				ReadStart = mp3_in + Remaining;
				ReadSize  = (2 * MP3_BUFFER_SIZE) - Remaining;
				memmove(mp3_in, Stream.next_frame, Remaining);
			}
			else
			{
				ReadSize  = 2 * MP3_BUFFER_SIZE;
				ReadStart = mp3_in;
				Remaining = 0;
			}

			if (MP3SleepCheck()) break;

			ReadSize = sceIoRead(mp3_fd, ReadStart, ReadSize);
			mp3_filepos += ReadSize;
			if (mp3_filepos == mp3_fsize)
			{
				if (cdda_autoloop)
				{
					mp3_filepos = 0;
					sceIoLseek(mp3_fd, 0, PSP_SEEK_SET);
				}
				else
				{
					cdda_playing = CDDA_STOP;
					mp3_status = MP3_STOP;
				}
			}

			if (mp3_filepos == mp3_fsize)
			{
				GuardPtr = ReadStart + ReadSize;
				memset(GuardPtr, 0, MAD_BUFFER_GUARD);
				ReadSize += MAD_BUFFER_GUARD;
			}

			mad_stream_buffer(&Stream, mp3_in, ReadSize + Remaining);

			Stream.error = 0;
		}

		if (mad_frame_decode(&Frame, &Stream))
		{
			if (MAD_RECOVERABLE(Stream.error))
			{
//				if (Stream.error != MAD_ERROR_LOSTSYNC || Stream.this_frame != GuardPtr)
				continue;
			}
			else if (Stream.error == MAD_ERROR_BUFLEN)
			{
				continue;
			}
			else
			{
				ui_popup(TEXT(MP3_DECODE_ERROR));
				mp3_status = MP3_STOP;
				break;
			}
		}

		mp3_frame++;
		mad_timer_add(&Timer, Frame.header.duration);
		mad_synth_frame(&Synth, &Frame);

		if (mp3_status == MP3_PLAY)
		{
			int i;

			for (i = 0; i < Synth.pcm.length; i++)
			{
				if (MAD_NCHANNELS(&Frame.header) == 2)
				{
					*OutputPtr++ = MP3Limit(Synth.pcm.samples[0][i]);
					*OutputPtr++ = MP3Limit(Synth.pcm.samples[1][i]);
				}
				else
				{
					INT16 data = MP3Limit(Synth.pcm.samples[0][i]);

					*OutputPtr++ = data;
					*OutputPtr++ = data;
				}

				if (OutputPtr == OutputEnd)
				{
					sceAudioOutputPannedBlocking(mp3_handle, mp3_volume, mp3_volume, mp3_out[flip]);
					flip ^= 1;
					OutputPtr = (INT16 *)mp3_out[flip];
					OutputEnd = (INT16 *)(mp3_out[flip] + MP3_BUFFER_SIZE);
				}
			}
		}
		else if (mp3_status == MP3_SEEK)
		{
			if (mp3_frame >= mp3_start_frame)
			{
				mp3_start_frame = 0;
				mp3_status = MP3_SLEEP;
				sceKernelSleepThread();
			}
		}
	}

	mad_synth_finish(&Synth);
	mad_frame_finish(&Frame);
	mad_stream_finish(&Stream);

	if (mp3_fd >= 0)
	{
		sceIoClose(mp3_fd);
		mp3_fd = -1;
	}
}