static void pull_event_loop(audioport_t *port, sys_event_queue_t id) { sys_event_t event; int16_t *in_buf = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)); float *conv_buf = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(float)); while (!port->quit_thread) { uint32_t has_read = 0; if (port->sample_cb) has_read = port->sample_cb(in_buf, CELL_AUDIO_BLOCK_SAMPLES * port->channels, port->userdata); else { has_read = CELL_AUDIO_BLOCK_SAMPLES * port->channels; sys_lwmutex_lock(&port->lock, SYS_NO_TIMEOUT); uint32_t avail = fifo_read_avail(port->buffer); if (avail < CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)) has_read = avail / sizeof(int16_t); fifo_read(port->buffer, in_buf, has_read * sizeof(int16_t)); sys_lwmutex_unlock(&port->lock); } if (has_read < CELL_AUDIO_BLOCK_SAMPLES * port->channels) memset(in_buf + has_read, 0, (CELL_AUDIO_BLOCK_SAMPLES * port->channels - has_read) * sizeof(int16_t)); resampler_int16_t_to_float(conv_buf, in_buf, CELL_AUDIO_BLOCK_SAMPLES * port->channels); sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); cellAudioAddData(port->audio_port, conv_buf, CELL_AUDIO_BLOCK_SAMPLES, 1.0); pthread_cond_signal(&port->cond); } free(conv_buf); }
static void event_loop(uint64_t data) #endif { float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS] __attribute__((aligned(16))); sys_event_queue_t id; sys_ipc_key_t key; sys_event_t event; ps3_audio_t *aud = data; cellAudioCreateNotifyEventQueue(&id, &key); cellAudioSetNotifyEventQueue(key); while (!aud->quit_thread) { sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT); if (fifo_read_avail(aud->buffer) >= sizeof(out_tmp)) fifo_read(aud->buffer, out_tmp, sizeof(out_tmp)); else memset(out_tmp, 0, sizeof(out_tmp)); sys_lwmutex_unlock(&aud->lock); sys_lwcond_signal(&aud->cond); cellAudioAddData(aud->audio_port, out_tmp, CELL_AUDIO_BLOCK_SAMPLES, 1.0); } cellAudioRemoveNotifyEventQueue(key); sys_ppu_thread_exit(0); }
int ESAudio::ProcessAudioThread (void* aBcD) { int16_t samples[1024]; float outbuffer[512]; sys_event_t event; while(!ThreadDie) { if(0 != sys_event_queue_receive(QueueID, &event, 100 * 1000)) { break; } RingBuffer.ReadDataSilentUnderrun((uint32_t*)samples, 256); if(!Semaphore->GetValue()) { Semaphore->Post(); } for(uint32_t i = 0; i != 256 * 2; i ++) { outbuffer[i] = ((float)samples[i]) / 32768.0f; } cellAudioAddData(Port, outbuffer, 256, 1); } ThreadDie = false; return 0; }
static void spu_printf_handler_entry(uint64_t arg) { SampleUtilSpursPrintfService *service = (SampleUtilSpursPrintfService *)(uintptr_t)arg; int ret; for (;;) { sys_spu_thread_t spu; sys_event_t event; ret = sys_event_queue_receive(service->equeue, &event, 0); if (event.source == TERMINATING_PORT_NAME) { printf ("Finalizing the spu printf handler\n"); sys_ppu_thread_exit(0); } spu = event.data1; int sret = spu_thread_printf(spu, event.data3); ret = sys_spu_thread_write_spu_mb(spu, sret); if (ret) { printf ("sys_spu_thread_write_spu_mb failed (%d)\n", ret); sys_ppu_thread_exit(-1); } } /* never reach here */ sys_ppu_thread_exit(0); }
static u32 playOneBlock(u64 *readIndex, float *dst, const audio_mode_t *am, const audio_buf_t *ab, sys_event_queue_t snd_queue, int channels) { u32 ret = 0; u64 current_block = *readIndex; int64_t pts; u32 audio_block_index = (current_block + 1) % AUDIO_BLOCK_8; sys_event_t event; ret = sys_event_queue_receive(snd_queue, &event, 20 * 1000); float *buf = dst + channels * AUDIO_BLOCK_SAMPLES * audio_block_index; if(ab == NULL) { fillBuffersilence(buf, channels); } else { if(ab->ab_isfloat) copy_buf_float(buf, ab, channels); else copy_buf_int16(buf, ab, channels); if((pts = ab->ab_pts) != AV_NOPTS_VALUE && ab->ab_mp != NULL) { pts += am->am_audio_delay * 1000; pts -= 1000000LL * (AUDIO_BLOCK_SAMPLES * AUDIO_BLOCK_8) / 48000; media_pipe_t *mp = ab->ab_mp; hts_mutex_lock(&mp->mp_clock_mutex); mp->mp_audio_clock = pts; mp->mp_audio_clock_realtime = showtime_get_ts(); mp->mp_audio_clock_epoch = ab->ab_epoch; hts_mutex_unlock(&mp->mp_clock_mutex); } } return 0; }
static void resampler_event_loop(audioport_t *port, sys_event_queue_t id) { sys_event_t event; port->re_buffer = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(float)); port->re_pull_buffer = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)); float *res_buffer = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(float)); while (!port->quit_thread) { resampler_cb_read(port->re, CELL_AUDIO_BLOCK_SAMPLES, res_buffer); sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); cellAudioAddData(port->audio_port, res_buffer, CELL_AUDIO_BLOCK_SAMPLES, 1.0); } free(res_buffer); free(port->re_buffer); free(port->re_pull_buffer); port->re_buffer = NULL; port->re_pull_buffer = NULL; }
//UPDATE: this function is not currently being used in the speex task or spurs manager void _SpursPrintfThreadMain(uint64_t arg) { sys_event_t event; int iReturn; // E For unused parameter warnings (void) arg; while (1) { iReturn=sys_event_queue_receive(_g_SpuPrintfEventQueue, &event, SYS_NO_TIMEOUT); if (iReturn!=CELL_OK) { fprintf(stderr, "Event queue receive wasn't successful: %i\n", iReturn); exit(-1); } iReturn=spu_thread_printf(event.data1, event.data3); sys_spu_thread_write_spu_mb(event.data1, iReturn); } }