Beispiel #1
0
int playerStart(char *path,pMalloc extern_malloc,pFree extern_free,	int(*callback)(int)){
	int ret,ch;MODFILE mod;
	if(!extern_malloc || !extern_free)return -1;
	if((ch=sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL,PSP_AUDIO_SAMPLE_ALIGN(768),PSP_AUDIO_FORMAT_STEREO))<0)return ch;
	myMalloc=extern_malloc;
	myFree	=extern_free;
	MODFILE_Init(&mod);
	if((ret=MODFILE_Load(path, &mod))<0)return ret;
	mod.musicvolume = 255;
	mod.sfxvolume = 255;
	mod.callback = NULL;//callback;
	MODFILE_Start(&mod);
	MODFILE_SetFormat(&mod, 44100, 2,16,1/*unsigned*/);
	SceCtrlData pad;
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(1);
	for(int i=0;;i++){
		sceCtrlReadBufferPositive(&pad,1);
		if(pad.Buttons&PSP_CTRL_START)break;
		mod.mixingbuf =(void*)out[i%2];
		mod.mixingbuflen = 768*2*2;
		MODFILE_Player(&mod);
		sceAudioOutputBlocking(ch, PSP_AUDIO_VOLUME_MAX,out[i%2]);
	}
	MODFILE_Stop(&mod);
	MODFILE_Free(&mod);
	sceAudioChRelease(ch);
	return 0;
}
Beispiel #2
0
// The real thread function
void PspAudio::threadFunction() {
	assert(_callback);
	PSP_DEBUG_PRINT_FUNC("audio thread started\n");

	while (_init) {		// Keep looping so long as we haven't been told to stop
		if (_paused)
			PSP_DEBUG_PRINT("audio thread paused\n");
		while (_paused) {	// delay until we stop pausing
			PspThread::delayMicros(100000);	// 100ms
			if (!_paused)
				PSP_DEBUG_PRINT("audio thread unpaused\n");
		}

		PSP_DEBUG_PRINT("remaining samples[%d]\n", _remainingSamples);

		PSP_DEBUG_PRINT("filling buffer[%d]\n", _bufferToFill);
		_callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in data
		nextBuffer(_bufferToFill);

		PSP_DEBUG_PRINT("playing buffer[%d].\n", _bufferToPlay);
		playBuffer();
		nextBuffer(_bufferToPlay);
	} // while _init

	// destroy everything
	free(_buffers[0]);
	sceAudioChRelease(_pspChannel);
	PSP_DEBUG_PRINT("audio thread exiting. ****************************\n");
}
Beispiel #3
0
static void CleanUp(){
	if ( mp3_audio_thread >= 0 ) {
		sceKernelDeleteThread(mp3_audio_thread);
		mp3_audio_thread = -1;
	}
	
	if ( mp3_audio_channel >= 0 ) {
		sceAudioChRelease(mp3_audio_channel);
		mp3_audio_channel = -1;
	}
	
	if ( !mp3_file_handle ) {
		sceIoClose(mp3_file_handle);
		mp3_file_handle = 0;
	}
	
	mp3_data_start = 0;
	mp3_output_buffers = 0;
	
	mp3_play = 0;
	mp3_pause = 0;
	
	if ( mp3_codec_flag ) {
		sceAudiocodecReleaseEDRAM(mp3_codec_buffer);
		mp3_codec_flag = 0;
	}
}
Beispiel #4
0
/**
 * stop_channel:  Stop playback from the given playback buffer.
 *
 * [Parameters]
 *     buffer_desc: Playback buffer descriptor
 * [Return value]
 *     None
 */
void stop_channel(PSPSoundBufferDesc *buffer_desc)
{
    if (!buffer_desc) {
        DMSG("buffer_desc == NULL");
        return;
    }
    if (!buffer_desc->started) {
        DMSG("Buffer has not been started!");
        return;
    }

    /* Signal the thread to stop, then wait for it (if we try to stop the
     * thread in the middle of an audio write, we won't be able to free
     * the hardware channel) */
    buffer_desc->stop = 1;
    int tries;
    for (tries = (1000 * (2*BUFFER_SIZE)/PLAYBACK_RATE); tries > 0; tries--) {
        if (sys_delete_thread_if_stopped(buffer_desc->thread, NULL)) {
            break;
        }
        sceKernelDelayThread(1000);  // Wait for 1ms before trying again
    }

    if (!tries) {
        /* The thread didn't stop on its own, so terminate it with
         * extreme prejudice */
        sceKernelTerminateDeleteThread(buffer_desc->thread);
        sceAudioChRelease(buffer_desc->channel);
        memset(buffer_desc, 0, sizeof(*buffer_desc));
    }
}
Beispiel #5
0
void pmp_play_close(struct pmp_play_struct *p, int usePos, int pspType)
	{
	if (!(p->audio_reserved < 0)) {
		while(sceAudioGetChannelRestLen(0) > 0 );
		sceAudioChRelease(0);
	}
	cooleyesAudioSetFrequency(sceKernelDevkitVersion(), 44100);

	if (!(p->semaphore_can_get   < 0)) sceKernelDeleteSema(p->semaphore_can_get);
	if (!(p->semaphore_can_put   < 0)) sceKernelDeleteSema(p->semaphore_can_put);
	if (!(p->semaphore_can_show  < 0)) sceKernelDeleteSema(p->semaphore_can_show);
	if (!(p->semaphore_show_done < 0)) sceKernelDeleteSema(p->semaphore_show_done);

	if (!(p->output_thread < 0)) sceKernelDeleteThread(p->output_thread);
	if (!(p->show_thread   < 0)) sceKernelDeleteThread(p->show_thread);

	pmp_decode_close(&p->decoder, pspType);

	int i = 0;
	for (i=0; i<p->subtitle_count; i++)
		subtitle_parse_close( &subtitle_parser[i] );
	
	//if (usePos) pmp_stat_save( p );
	pmp_stat_save( p );
	
	pmp_play_safe_constructor(p);
	}
Beispiel #6
0
int pspAudioInit()
{
	int i,ret;
	int failed=0;
	char str[32];

	audio_terminate=0;
	audio_ready=0;

	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
    AudioStatus[i].handle = -1;
    AudioStatus[i].threadhandle = -1;
    AudioStatus[i].volumeright = PSP_VOLUME_MAX;
    AudioStatus[i].volumeleft  = PSP_VOLUME_MAX;
    AudioStatus[i].callback = 0;
    AudioStatus[i].pdata = 0;
	}
	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		if ((AudioStatus[i].handle = sceAudioChReserve(-1,PSP_NUM_AUDIO_SAMPLES,0))<0) 
      failed=1;
	}
	if (failed) {
		for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
			if (AudioStatus[i].handle != -1) 
        sceAudioChRelease(AudioStatus[i].handle);
			AudioStatus[i].handle = -1;
		}
		return -1;
	}
	audio_ready = 1;
	strcpy(str,"audiot0");
	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		str[6]='0'+i;
		AudioStatus[i].threadhandle = sceKernelCreateThread(str,(void*)&AudioChannelThread,0x12,0x10000,0,NULL);
		if (AudioStatus[i].threadhandle < 0) {
			AudioStatus[i].threadhandle = -1;
			failed=1;
			break;
		}
		ret=sceKernelStartThread(AudioStatus[i].threadhandle,sizeof(i),&i);
		if (ret!=0) {
			failed=1;
			break;
		}
	}
	if (failed) {
		audio_terminate=1;
		for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
			if (AudioStatus[i].threadhandle != -1) {
				//sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL);
				sceKernelDeleteThread(AudioStatus[i].threadhandle);
			}
			AudioStatus[i].threadhandle = -1;
		}
		audio_ready=0;
		return -1;
	}
	return 0;
}
Beispiel #7
0
static void PSPAUDIO_CloseDevice(_THIS)
{
    if (this->hidden->channel >= 0) {
        sceAudioChRelease(this->hidden->channel);
    }
    free(this->hidden->rawbuf);  /* this uses memalign(), not SDL_malloc(). */
    SDL_free(this->hidden);
}
Beispiel #8
0
void OSPC_StopPlay(){
	if (OSPC_thread<0) return;
	OSPC_exit=1;  	
  sceKernelWaitThreadEnd( OSPC_thread, NULL );
	sceKernelDeleteThread( OSPC_thread );
	OSPC_thread=-1;
	sceAudioChRelease( OSPC_sound_fd );
  OSPC_Stop();            
  OSPC_Close(); 
  if (OSPC_id) free(OSPC_id);
}
Beispiel #9
0
/* digi_psp_exit:
 *  Shuts down the sound driver.
 */
static void digi_psp_exit(int input)
{
   if (input)
      return;

   psp_audio_on = FALSE;
   sceKernelDeleteThread(audio_thread_UID);
   sceAudioChRelease(hw_channel);

   _mixer_exit();
}
Beispiel #10
0
void
psp_audio_end()
{
  psp_audio_term = 1;
  if (psp_audio_thid != -1) {
		sceKernelDeleteThread( psp_audio_thid );
    psp_audio_thid = -1;
  }
  if (psp_cdaudio_thid != -1) {
		sceKernelDeleteThread( psp_cdaudio_thid );
    psp_cdaudio_thid = -1;
  }
  if (psp_audio_chid != -1) {
    sceAudioChRelease( psp_audio_chid );
    psp_audio_chid = -1;
  }
  if (psp_cdaudio_chid != -1) {
    sceAudioChRelease( psp_cdaudio_chid );
    psp_cdaudio_chid = -1;
  }
}
Beispiel #11
0
static void PSPAUD_CloseDevice(_THIS)
{
    if (this->hidden->channel >= 0) {
        sceAudioChRelease(this->hidden->channel);
        this->hidden->channel = -1;
    }

    if (this->hidden->rawbuf != NULL) {
        free(this->hidden->rawbuf);
        this->hidden->rawbuf = NULL;
    }
}
Beispiel #12
0
void OSPC_PlayBuffer(char *buff,int len,int release,int vol)
{
    int i,j,pollcpt;
    char str[256];
    SPC_ID666 *id;
    char *emulator[3]={"Unknown","Zsnes","Snes9x"};
    uint8 *scr;
   
    OSPC_Init();

    if (i=OSPC_LoadBuffer(buff,len))
    {
    	sprintf(str,"Error at SPC loading, code : %d",i);
    	msgBoxLines(str,60);
    	//gp32_pause();
    	//GpAppExit();
    	return;
    }
     

	OSPC_id=OSPC_GetID666(spc_data);
		
  OSPC_sound_fd = sceAudioChReserve( -1, 1024, 0 );
  OSPC_exit=0;
  OSPC_volume=vol;
  OSPC_thread = sceKernelCreateThread( "OSPC Thread", (SceKernelThreadEntry)OSPC_PlayThread, 0x8, 256*1024, 0, 0 );
  if (OSPC_thread<0) {
  	msgBoxLines("Cannot create OSPC playback thread",60);
  } else {
  	//init start time		
		sceKernelLibcGettimeofday( &OSPC_start_time, 0 );
  	
  	sceKernelStartThread( OSPC_thread, 0, 0 );
  	
  	if (release) return;
  	
  	for (;;) {
  		pgWaitV();
  		if (get_pad()) break;
  	}
  	OSPC_exit=1;  	
  	sceKernelWaitThreadEnd( OSPC_thread, NULL );
		sceKernelDeleteThread( OSPC_thread );
		OSPC_thread=-1;
  }    
  sceAudioChRelease( OSPC_sound_fd );
  OSPC_Stop();            
  OSPC_Close();    
  if (OSPC_id) free(OSPC_id);
}
Beispiel #13
0
/**
 * start_channel:  Allocate a new channel and starts playback.
 *
 * [Parameters]
 *     buffer_desc: Playback buffer descriptor
 * [Return value]
 *     Nonzero on success, zero on error
 */
static int start_channel(PSPSoundBufferDesc *buffer_desc)
{
    if (!buffer_desc) {
        DMSG("buffer_desc == NULL");
        return 0;
    }
    if (buffer_desc->started) {
        DMSG("Buffer is already started!");
        return 0;
    }

    /* Allocate a hardware channel */
    buffer_desc->channel = sceAudioChReserve(
        PSP_AUDIO_NEXT_CHANNEL, BUFFER_SIZE, PSP_AUDIO_FORMAT_STEREO
    );
    if (buffer_desc->channel < 0) {
        DMSG("Failed to allocate channel: %s",
             psp_strerror(buffer_desc->channel));
        return 0;
    }

    /* Initialize the ring buffer */
    buffer_desc->cur_play = NUM_BUFFERS - 1;
    buffer_desc->next_play = 0;
    buffer_desc->next_write = 0;
    int i;
    for (i = 0; i < NUM_BUFFERS; i++) {
        buffer_desc->write_ready[i] = 1;
    }
    buffer_desc->stop = 0;
    /* Also write everything out of the cache so it's ready for the ME */
    sceKernelDcacheWritebackAll();

    /* Start the playback thread */
    char thname[100];
    snprintf(thname, sizeof(thname), "YabauseSoundCh%d", buffer_desc->channel);
    SceUID handle = sys_start_thread(thname, playback_thread,
                                     THREADPRI_SOUND, 0x1000,
                                     sizeof(buffer_desc), &buffer_desc);
    if (handle < 0) {
        DMSG("Failed to create thread: %s", psp_strerror(handle));
        sceAudioChRelease(buffer_desc->channel);
        return 0;
    }
    buffer_desc->thread = handle;

    /* Success */
    buffer_desc->started = 1;
    return 1;
}
Beispiel #14
0
SceInt32 CPMFPlayer::ShutdownAudio()
{
	
	sceAudioChRelease(Audio.m_AudioChannel); //Human-Behind
	sceKernelDeleteThread(Audio.m_ThreadID);

	sceKernelDeleteSema(Audio.m_SemaphoreStart);
	sceKernelDeleteSema(Audio.m_SemaphoreLock);

	for(int i = 0; i < Audio.m_iNumBuffers; i++)
		free(Audio.m_pAudioBuffer[i]);

	return 0;
}
Beispiel #15
0
triVoid triAt3Free()
{
	triAt3Stop();
	AT3_Loaded = 0;
	
	sceKernelDelayThread(50000);
	sceAudioChRelease(AT3_Channel);
	sceAudiocodecReleaseEDRAM(AT3_Codec_Buffer);
	sceKernelWaitThreadEnd(AT3_ThreadID, NULL);
	sceKernelTerminateDeleteThread(AT3_ThreadID);
	
	if(Tune)
		triFree(Tune);
}
Beispiel #16
0
/**
 * playback_thread:  Sound playback thread.  Continually sends the ring
 * buffer data to the OS until signaled to stop.
 *
 * [Parameters]
 *     args: Thread argument size
 *     argp: Thread argument pointer
 * [Return value]
 *     Always zero
 */
static int playback_thread(SceSize args, void *argp)
{
    PSPSoundBufferDesc * const buffer_desc = *(PSPSoundBufferDesc **)argp;

    /* Temporary buffer for dummy audio data when the emulator falls behind
     * real time (filled with the last sample sent to avoid clicks).  This
     * thread is only launched once, so "static" is safe. */
    static uint32_t dummy_buffer[BUFFER_SIZE];  // 1 stereo sample = 32 bits
    static uint32_t last_sample;                // Last stereo sample played

    while (!buffer_desc->stop) {
        const unsigned int next_play = buffer_desc->next_play;
//static int x;int now=sceKernelGetSystemTimeLow();if(now-x>100000){printf("--- audio stat: %u %u %u %u cp=%u np=%u nw=%u\n",UNCACHED(buffer_desc->write_ready[0]),UNCACHED(buffer_desc->write_ready[1]),UNCACHED(buffer_desc->write_ready[2]),UNCACHED(buffer_desc->write_ready[3]),buffer_desc->cur_play,next_play,UNCACHED(buffer_desc->next_write));x=now;}
        if (!UNCACHED(buffer_desc->write_ready[next_play])) {  // i.e., ready for playback
            const void *buffer = buffer_desc->buffer[next_play];
            last_sample = ((const uint32_t *)buffer)[BUFFER_SIZE - 1];
            sceAudioOutputBlocking(buffer_desc->channel, muted ? 0 : 0x8000,
                                   buffer);
#ifdef DUMP_AUDIO
            sceIoWrite(dump_fd, buffer, BUFFER_SIZE*4);
#endif
            UNCACHED(buffer_desc->write_ready[buffer_desc->cur_play]) = 1;
            buffer_desc->cur_play = next_play;
            buffer_desc->next_play = (next_play + 1) % NUM_BUFFERS;
        } else {
            const uint32_t sample = last_sample;  // Help out optimizer
            uint32_t *ptr32 = dummy_buffer;
            unsigned int i;
            for (i = 0; i < BUFFER_SIZE; i += 8) {
                ptr32[i+0] = sample;
                ptr32[i+1] = sample;
                ptr32[i+2] = sample;
                ptr32[i+3] = sample;
                ptr32[i+4] = sample;
                ptr32[i+5] = sample;
                ptr32[i+6] = sample;
                ptr32[i+7] = sample;
            }
            sceAudioOutputBlocking(buffer_desc->channel, muted ? 0 : 0x8000,
                                   dummy_buffer);
        }
    }

    sceAudioChRelease(buffer_desc->channel);
    memset(buffer_desc, 0, sizeof(*buffer_desc));
    return 0;
}
Beispiel #17
0
void mp3_thread_stop(void)
{
	if (mp3_thread >= 0)
	{
		mp3_active = 0;
		mp3_stop();

		sceKernelWakeupThread(mp3_thread);
		sceKernelWaitThreadEnd(mp3_thread, NULL);

		sceKernelDeleteThread(mp3_thread);
		mp3_thread = -1;

		sceAudioChRelease(mp3_handle);
		mp3_handle = -1;
	}
}
Beispiel #18
0
int FreeHardwareChannel(int channel)
{
	int i;
	for (i=0;i<8;i++)
	{
		if (hardwareChannels[i]==channel)
		{
			while (AalibGetStatus(channel)!=PSPAALIB_STATUS_STOPPED)
			{
				sceKernelDelayThread(10);
			}
			sceAudioChRelease(i);
			hardwareChannels[i]=PSPAALIB_CHANNEL_NONE;
			return TRUE;
		}
	}
	return FALSE;
}
Beispiel #19
0
void audio_Term(void)
{
	int i;
	audio_ready = 0;
	audio_terminate = 1;
	for (i=0; i<CHANNELS; i++) {
		if (audio_thread_handle[i] != -1) {
			sceKernelWaitThreadEnd(audio_thread_handle[i], NULL);
			sceKernelDeleteThread(audio_thread_handle[i]);
		}
		audio_thread_handle[i] = -1;
	}
	for (i=0; i<CHANNELS; i++) {
		if (audio_handles[i] != -1) {
			sceAudioChRelease(audio_handles[i]);
			audio_handles[i] = -1;
		}
	}
}
void pspAudioEnd()
{
	int i;
	audio_ready=0;
	audio_terminate=1;

	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		if (AudioStatus[i].threadhandle != -1) {
			//sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL);
			sceKernelDeleteThread(AudioStatus[i].threadhandle);
		}
		AudioStatus[i].threadhandle = -1;
	}

	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		if (AudioStatus[i].handle != -1) {
			sceAudioChRelease(AudioStatus[i].handle);
			AudioStatus[i].handle = -1;
		}
	}
}
Beispiel #21
0
static int SoundThread()
{
	int err=0;
	int sample_count;
	int chan;
	int realSampleCount;
	int buf = 0;

	//For SMS, we need tighter timings
	if (menuConfig.sound.perfectSynchro && gblMachineType == EM_SMS)
		sample_count = 128;
	else
		sample_count = snd.sample_rate/snd.fps;
	sample_count = PSP_AUDIO_SAMPLE_ALIGN(sample_count);
	realSampleCount = sample_count / (44100 / snd.sample_rate);
	chan = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, sample_count, PSP_AUDIO_FORMAT_STEREO);

	if(chan > 0 && sample_count > 0 && sample_count <= 2048)
	{
		for(; soundRunning; )
		{
			if (soundPause)
				memset(audioOut[buf], 0, sample_count * sizeof(sample_t));
			else
				StandardSoundProcess();

			//Game Boy: réglage du son ne fonctionne pas!
			AudioGet(audioOut[buf], sample_count, realSampleCount);
			sceAudioOutputBlocking(chan, PSP_AUDIO_VOLUME_MAX, (void*)audioOut[buf]);

			if (menuConfig.sound.perfectSynchro)
				buf = 1 - buf;
		}

		sceAudioChRelease(chan);
	}

	soundRunning = -1;
	sceKernelExitDeleteThread(0);
}
Beispiel #22
0
int mp3_thread_start(void)
{
	mp3_handle  = -1;
	mp3_thread  = -1;
	mp3_active  = 0;
	mp3_status  = MP3_STOP;
	mp3_running = 0;
	mp3_sleep   = 0;

	mp3_newfile = 0;
	mp3_volume  = 0;

	memset(mp3_out[0], 0, MP3_BUFFER_SIZE);
	memset(mp3_out[1], 0, MP3_BUFFER_SIZE);

	mp3_handle = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, MP3_SAMPLES, PSP_AUDIO_FORMAT_STEREO);
	if (mp3_handle < 0)
	{
		fatalerror(TEXT(COULD_NOT_RESERVE_AUDIO_CHANNEL_FOR_MP3));
		return 0;
	}

	mp3_active = 1;

	mp3_thread = sceKernelCreateThread("MP3 thread", MP3Thread, 0x8, 0x40000, 0, NULL);
	if (mp3_thread < 0)
	{
		fatalerror(TEXT(COULD_NOT_START_MP3_THREAD));
		sceAudioChRelease(mp3_handle);
		return 0;
	}

	sceKernelStartThread(mp3_thread, 0, 0);

	return 1;
}
Beispiel #23
0
int audio_Init(void)
{
	int i, ret;
	int failed = 0;
	char str[32];
	audio_terminate=0;
	audio_ready=0;
	for(i=0; i<CHANNELS; i++)
	{
		audio_handles[i] = -1;
		audio_thread_handle[i] = -1;
		audio_ChannelCallback[i] = 0;
		audio_volumes[i][0] = MAXVOLUME;
		audio_volumes[i][1] = MAXVOLUME;
	}
	for(i=0; i<CHANNELS; i++) if((audio_handles[i] = sceAudioChReserve(-1, SAMPLES, 0)) < 0) failed = 1;
	if(failed)
	{
		for(i=0; i<CHANNELS; i++)
		{
			if(audio_handles[i] != -1) sceAudioChRelease(audio_handles[i]);
			audio_handles[i] = -1;
		}
		return -1;
	}
	audio_ready = 1;
	strcpy(str,"Sound Thread");
	for(i=0; i<CHANNELS; i++)
	{
		str[6] = '0' + i;
		audio_thread_handle[i] = sceKernelCreateThread(str, audio_ChannelThread, 0x8, 0x10000, PSP_THREAD_ATTR_USER, NULL);
		if(audio_thread_handle[i] < 0)
		{
			audio_thread_handle[i] = -1;
			failed = 1;
			break;
		}
		ret = sceKernelStartThread(audio_thread_handle[i], sizeof(i), &i);
		if(ret != 0)
		{
			failed = 1;
			break;
		}
	}
	if(failed)
	{
		audio_terminate = 1;
		for(i=0; i<CHANNELS; i++)
		{
			if(audio_thread_handle[i] != -1)
			{
				sceKernelWaitThreadEnd(audio_thread_handle[i],NULL);
				sceKernelDeleteThread(audio_thread_handle[i]);
			}
			audio_thread_handle[i] = -1;
		}
		audio_ready = 0;
		return -1;
	}
	audio_SetChannelCallback(0, audio_UpdateCallback);
	return 0;
}
Beispiel #24
0
SceInt32 CPMFPlayer::InitAudio()
{
	int i = 0, fail = 0;

	Audio.m_AudioChannel = sceAudioChReserve(-1, 512, PSP_AUDIO_FORMAT_STEREO);
	if(Audio.m_AudioChannel < 0)
	{
		sprintf(m_LastError, "sceAudioChReserve() failed: 0x%08X", (int)Audio.m_AudioChannel);
		return -1;
	}

	sceAudioSetChannelDataLen(Audio.m_AudioChannel, m_MpegAtracOutSize / 4);

	Audio.m_ThreadID = sceKernelCreateThread("audio_thread", T_Audio, 0x3D, 0x10000, PSP_THREAD_ATTR_USER, NULL);
	if(Audio.m_ThreadID < 0)
	{
		sprintf(m_LastError, "sceKernelCreateThread() failed: 0x%08X", (int)Audio.m_ThreadID);
		goto exit0;
	}

	Audio.m_SemaphoreStart = sceKernelCreateSema("audio_start_sema",  0, 0, 1, NULL);
	if(Audio.m_SemaphoreStart < 0)
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreStart);
		goto exit1;
	}

	Audio.m_SemaphoreLock = sceKernelCreateSema("audio_lock_sema",  0, 1, 1, NULL);
	if(Audio.m_SemaphoreLock	< 0 )
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreLock);
		goto exit2;
	}

	Audio.m_iNumBuffers			= 4;
	Audio.m_iFullBuffers		= 0;
	Audio.m_iPlayBuffer			= 1;
	Audio.m_iDecodeBuffer		= 0;
	Audio.m_iAbort				= 0;
	Audio.m_LastError			= m_LastError;

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = NULL;
		Audio.m_iBufferTimeStamp[i] = 0;
	}

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = memalign(64, m_MpegAtracOutSize);
		if(Audio.m_pAudioBuffer[i] < 0) fail++;
	}

	if(fail > 0)
	{
		for(i = 0; i < Audio.m_iNumBuffers; i++)
		{
			if(Audio.m_pAudioBuffer[i] != NULL)
				free(Audio.m_pAudioBuffer[i]);
		}

		sprintf(m_LastError, "malloc() failed!");
		goto exit3;
	}

	return 0;

exit3:
	sceKernelDeleteSema(Audio.m_SemaphoreLock);
exit2:
	sceKernelDeleteSema(Audio.m_SemaphoreStart);
exit1:
	sceKernelDeleteThread(Audio.m_ThreadID);
exit0:
	sceAudioChRelease(Audio.m_AudioChannel);

	return -1;
}
Beispiel #25
0
int main(int argc, char *argv[]) {
	char *at3_data;
	int at3_size;

	char *decode_data;
	int decode_size;
	int n;

	FILE *file;

	int atracID;
	int maxSamples = 0;
	int result;
	int channel;
	
	u32 puiPosition;
	u32 puiDataByte;
	
	if ((file = fopen("sample.at3", "rb")) != NULL) {
		fseek(file, 0, SEEK_END);
		at3_size = ftell(file);
		
		fseek(file, 0, SEEK_SET);
		
		at3_data = malloc(at3_size);
		decode_data = malloc(decode_size = 512 * 1024);
		memset(at3_data, 0, at3_size);
		memset(decode_data, 0, decode_size);
		
		fread(at3_data, at3_size, 1, file);

		fclose(file);
	}

	pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
	pspSdkLoadStartModule("flash0:/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_KERNEL);
	
	printf("at3: %08X, %08X\n", (unsigned int)at3_data, at3_size);
	printf("Header: %s\n", (char *)at3_data);
		
	atracID = sceAtracSetDataAndGetID(at3_data, at3_size);
	
	result = sceAtracSetLoopNum(atracID, 2);
	printf("sceAtracSetLoopNum: %08X\n", result);

	printf("sceAtracSetDataAndGetID: %08X\n", atracID);
	
	result = sceAtracGetMaxSample(atracID, &maxSamples);
	printf("sceAtracGetMaxSample: %08X, %d\n", result, maxSamples);
	
	channel = sceAudioChReserve(0, maxSamples, PSP_AUDIO_FORMAT_STEREO);
	
	result = sceAtracGetSecondBufferInfo(atracID, &puiPosition, &puiDataByte);
	printf("sceAtracGetSecondBufferInfo: %08X, %u, %u\n", result, (unsigned int)puiPosition, (unsigned int)puiDataByte);
	
	int end = 0;
	int steps = 0;
	while (!end) {
		//int remainFrame = -1;
		int remainFrame = 0;
		//int decodeBufferPosition = 0;
		int samples = 0;
		int nextSample = 0;
		u32 nextPosition = 0;
		
		if (steps < 4) {
			result = sceAtracGetNextSample(atracID, &nextSample);
			printf("sceAtracGetNextSample(%d): %d\n", result, nextSample);
			result = sceAtracGetNextDecodePosition(atracID, &nextPosition);
			printf("sceAtracGetNextDecodePosition(%d): %u\n", result, (unsigned int)nextPosition);
		}

		result = sceAtracDecodeData(atracID, (u16 *)decode_data, &samples, &end, &remainFrame);
		
		if (steps < 4) {
			
		}
		
		sceAudioSetChannelDataLen(channel, samples);
		sceAudioOutputBlocking(channel, 0x8000, decode_data);
		
		result = sceAtracGetRemainFrame(atracID, &remainFrame);

		if (steps < 4) {
			printf("sceAtracDecodeData: %08X, at3_size: %d, decode_size: %d, samples: %d, end: %d, remainFrame: %d\n\n", result, at3_size, decode_size, samples, end, remainFrame);
			if (steps == 1) {
				for (n = 0; n < 32; n++) printf("%04X ", (u16)decode_data[n]);
			}
			printf("sceAtracGetRemainFrame: %08X\n", result);
		}

		steps++;
	}
	
	sceAudioChRelease(channel);
	result = sceAtracReleaseAtracID(atracID);
	printf("sceAtracGetRemainFrame: %08X\n", result);

	return 0;
}
Beispiel #26
0
void OSPC_Play(char *fname,int release,int vol) {
	  u16 *menu_bg;	  
		u16 *dst,*src;
    int i,j,pollcpt;    
    char str[256];    
    char *emulator[3]={"Unknown","Zsnes","Snes9x"};
    uint8 *scr;
   
    OSPC_Init();

    if (i=OSPC_Load(fname))
    {
    	sprintf(str,"Error at SPC loading, code : %d",i);
    	msgBoxLines(str,60);
    	//gp32_pause();
    	//GpAppExit();
    	return;
    }
     

	OSPC_id=OSPC_GetID666(spc_data);
	
  OSPC_sound_fd = sceAudioChReserve( -1, 1024, 0 );
  OSPC_exit=0;
  OSPC_volume=vol;
  OSPC_thread = sceKernelCreateThread( "OSPC Thread", (SceKernelThreadEntry)OSPC_PlayThread, 0x8, 256*1024, 0, 0 );    
  if (OSPC_thread<0) {
  	msgBoxLines("Cannot create OSPC playback thread",60);
  } else {
  	//init start time
		scePowerSetClockFrequency(266,266,133);
		sceKernelLibcGettimeofday( &OSPC_start_time, 0 );
  	
  	sceKernelStartThread( OSPC_thread, 0, 0 );
  	
  	if (release) return;  		  		  			
  	//init bg
  	menu_bg=(u16*)malloc_64(480*272*2);
		dst=menu_bg;
		show_background(bg_img_mul,(os9x_lowbat?0x600000:0));	
		for (i=0;i<272;i++) {
			src = (u16*)pgGetVramAddr(0,i);						
			memcpy(dst,src,480*2);
			dst+=480;
		}
		//init fx
		fx_init();  		  			
  	for (;;) {
  		//show bg
  		OSPC_show_bg(menu_bg);
  		//show bg fx
  		fx_main(pgGetVramAddr(0,0));
  		
   		//batt infos
  		show_batteryinfo();
  		//music info
  		//draw frame
  		pgDrawFrame(14,14,20+230+5+1,75+1,12|(12<<5)|(12<<10));
  		pgDrawFrame(13,13,20+230+5+2,75+2,30|(30<<5)|(30<<10));
  		pgDrawFrame(12,12,20+230+5+3,75+3,12|(12<<5)|(12<<10));
  		pgFillBoxHalfer(15,15,20+230+5,75);
  		//
  		if (strlen(OSPC_id->gametitle)) sprintf(str,"Game : %s",OSPC_id->gametitle);
  		else sprintf(str,"Game : unknown");
  		mh_print(20,20,(char*)str,30|(30<<5)|(30<<10));
  		
  		if (strlen(OSPC_id->songname)) sprintf(str,"Song : %s",OSPC_id->songname);
  		else sprintf(str,"Song : unknown");  			
  		mh_print(20,30,(char*)str,30|(30<<5)|(30<<10));
  		
  		if (strlen(OSPC_id->dumper)) sprintf(str,"Dumper : %s",OSPC_id->dumper);
  		else sprintf(str,"Dumper : unknown");
  		mh_print(20,40,(char*)str,30|(30<<5)|(30<<10));
  		
  		if (strlen(OSPC_id->comments)) sprintf(str,"Comments : %s",OSPC_id->comments);
  		else sprintf(str,"Comments : unknown");
  		mh_print(20,50,(char*)str,30|(30<<5)|(30<<10));
  		
  		if (strlen(OSPC_id->author)) sprintf(str,"Author : %s",OSPC_id->author);
  		else sprintf(str,"Author : unknown");
  		mh_print(20,60,(char*)str,30|(30<<5)|(30<<10));
			//time infos
			//draw frame
			//draw frame
  		pgDrawFrame(14,94,20+65+5+1,116,8|(8<<5)|(16<<10));
  		pgDrawFrame(13,93,20+65+5+2,117,28|(28<<5)|(31<<10));
  		pgDrawFrame(12,92,20+65+5+3,118,8|(8<<5)|(16<<10));
			pgFillBoxHalfer(15,95,20+65+5,115);
			sceKernelLibcGettimeofday( &OSPC_cur_time, 0 );
			i=(OSPC_cur_time.tv_sec-OSPC_start_time.tv_sec)+(OSPC_cur_time.tv_usec-OSPC_start_time.tv_usec)/1000000;
  		sprintf(str,"%2d%c%.2d / %2d:%.2d",i/60,((i&1)?':':' '),i%60,OSPC_id->playtime/60,OSPC_id->playtime%60);
  		mh_print(20,100,(char*)str,(20)|(31<<5)|(18<<10));
  		  		
  		if (get_pad()) break;
  			
  		pgScreenFlip();
  	}
  	OSPC_exit=1;  	
  	sceKernelWaitThreadEnd( OSPC_thread, NULL );
		sceKernelDeleteThread( OSPC_thread );
		OSPC_thread=-1;
		
		free(menu_bg);
		fx_close();
  }    
  sceAudioChRelease( OSPC_sound_fd );
  OSPC_Stop();            
  OSPC_Close();    
  if (OSPC_id) free(OSPC_id);
}
Beispiel #27
0
int  MP3_Load (const char *name){
	if ( !mp3_codec_flag )
		return -1;
	mp3_file_handle = sceIoOpen(name, PSP_O_RDONLY, 0777);
	if ( !mp3_file_handle ) 
		return -1;
	if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) {
		sceIoClose(mp3_file_handle);
		return -2;
	}
	while(1) {
		if ( mp3_header_buffer[0] == 'I' && mp3_header_buffer[1] == 'D' && mp3_header_buffer[2] == '3' ) {
			unsigned char id3v2_buffer[6];
			if ( sceIoRead( mp3_file_handle, id3v2_buffer, 6 ) != 6 ) {
				sceIoClose(mp3_file_handle);
				return -2;
			}
			int id3v2_size = (int)(id3v2_buffer[2] & 0x7F) << 21 
				| (int)(id3v2_buffer[3] & 0x7F) << 14
				| (int)(id3v2_buffer[4] & 0x7F) << 7
				| (int)(id3v2_buffer[5] & 0x7F);
			sceIoLseek32(mp3_file_handle, id3v2_size, PSP_SEEK_CUR);
			if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) {
				sceIoClose(mp3_file_handle);
				return -2;
			}
			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);
			if ( sceIoRead( mp3_file_handle, mp3_header_buffer, 4 ) != 4 ) {
				sceIoClose(mp3_file_handle);
				return -2;
			}
			continue;
		}
		mp3_samplerate = (mp3_header & 0x0C00) >> 10;
		if ( mp3_samplerate != 0 && mp3_samplerate != 1 ) {
			sceIoClose(mp3_file_handle);
			return -3;
		}
		mp3_samplerate = (mp3_samplerate == 0)?44100:48000;
	
		mp3_channels = (mp3_header & 0x00C0) >> 6;
		mp3_channels = (mp3_channels == 3)?1:2;
	
		mp3_data_start = sceIoLseek32(mp3_file_handle, -4, PSP_SEEK_CUR);
		
		break;
	}
	
	mp3_audio_channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, MP3_SAMPLE_COUNT, PSP_AUDIO_FORMAT_STEREO);
	if ( mp3_audio_channel < 0 ) {
		sceIoClose(mp3_file_handle);
		return -4;
	}
	
	mp3_audio_thread = sceKernelCreateThread("mp3_audio_thread",MP3OutputThread,0x12,0x10000,0,NULL);
	
	if ( mp3_audio_thread < 0 ) {
		sceAudioChRelease(mp3_audio_channel);
		sceIoClose(mp3_file_handle);
		return -5;
	}
	
	return 1;
}