void ESAudio::Initialize () { cellAudioInit(); CellAudioPortParam portparam = {2, BlockCount, CELL_AUDIO_PORTATTR_BGM, 1}; cellAudioPortOpen(&portparam, &Port); cellAudioGetPortConfig(Port, &Config); cellAudioCreateNotifyEventQueue(&QueueID, &QueueKey); cellAudioSetNotifyEventQueue(QueueKey); sys_event_queue_drain(QueueID); cellAudioPortStart(Port); Thread = es_threads->MakeThread(ProcessAudioThread, 0); Semaphore = es_threads->MakeSemaphore(1); }
static int ps3_audio_start(audio_mode_t *am, audio_fifo_t *af) { prop_sub_t *s_vol; audio_buf_t *ab; u32 port_num; AudioPortConfig config; int ret; int cur_channels = 0; int running = 0; sys_event_queue_t snd_queue; u64 snd_queue_key; int achannels = 0; if(audioInit()) return -1; s_vol = prop_subscribe(PROP_SUB_DIRECT_UPDATE, PROP_TAG_CALLBACK_FLOAT, set_mastervol, NULL, PROP_TAG_ROOT, prop_mastervol, NULL); TRACE(TRACE_DEBUG, "AUDIO", "PS3 audio system initialized"); while(1) { ab = af_deq2(af, !running, am); if(ab == AF_EXIT) { ab = NULL; break; } if(ab != NULL) { if(ab->ab_channels != cur_channels) { if(running) { audioPortStop(port_num); audioRemoveNotifyEventQueue(snd_queue_key); audioPortClose(port_num); sys_event_queue_destroy(snd_queue, 0); running = 0; } cur_channels = ab->ab_channels; AudioOutConfiguration conf; memset(&conf, 0, sizeof(conf)); switch(cur_channels) { case 2: achannels = 2; conf.channel = 2; conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM; break; case 6: achannels = 8; if(max_pcm >= 6) { conf.channel = 6; conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM; } else if(max_dts == 6) { conf.channel = 6; conf.encoder = AUDIO_OUT_CODING_TYPE_DTS; } else if(max_ac3 == 6) { conf.channel = 6; conf.encoder = AUDIO_OUT_CODING_TYPE_AC3; } else { conf.channel = 2; conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM; conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_A; } break; case 7: case 8: achannels = 8; if(max_pcm == 8) { conf.channel = 8; conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM; } else if(max_dts == 6) { conf.channel = 6; conf.encoder = AUDIO_OUT_CODING_TYPE_DTS; conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_B; } else if(max_ac3 == 6) { conf.channel = 6; conf.encoder = AUDIO_OUT_CODING_TYPE_AC3; conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_B; } else { conf.channel = 2; conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM; conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_A; } break; } int r; r = audioOutConfigure(AUDIO_OUT_PRIMARY, &conf, NULL, 1); if(r == 0) { int i; for(i = 0; i < 100;i++) { AudioOutState state; r = audioOutGetState(AUDIO_OUT_PRIMARY, 0, &state ); if(r != 0) break; TRACE(TRACE_DEBUG, "AUDIO", "The state is %d", state.state); if(state.state == 2) continue; usleep(100); break; } } AudioPortParam params; params.numChannels = achannels; params.numBlocks = AUDIO_BLOCK_8; params.attr = 0; params.level = 1; ret = audioPortOpen(¶ms, &port_num); TRACE(TRACE_DEBUG, "AUDIO", "PS3 audio port %d opened", port_num); audioGetPortConfig(port_num, &config); audioCreateNotifyEventQueue(&snd_queue, &snd_queue_key); audioSetNotifyEventQueue(snd_queue_key); sys_event_queue_drain(snd_queue); audioPortStart(port_num); running = 1; } } playOneBlock((u64*)(u64)config.readIndex, (float*)(u64)config.audioDataStart, am, ab, snd_queue, achannels); if(ab != NULL) ab_free(ab); } TRACE(TRACE_DEBUG, "AUDIO", "leaving the loop"); if(running) { audioPortStop(port_num); audioRemoveNotifyEventQueue(snd_queue_key); audioPortClose(port_num); sys_event_queue_destroy(snd_queue, 0); } audioQuit(); prop_unsubscribe(s_vol); return 0; }