//********************************************************************** //** SOUND //********************************************************************** //returns the number of samples the buffer can contain int PS3_initSound (void) { audioPortParam params; audioPortConfig config; audioInit(); params.numChannels = AUDIO_CHANNEL_COUNT; params.numBlocks = AUDIO_BLOCK_COUNT; params.attrib = 0; params.level = 1; audioPortOpen(¶ms, &audio_port); audioGetPortConfig(audio_port, &config); audio_buffer = (float *)config.audioDataStart; audio_buffer_end = (float *)(config.audioDataStart + config.portSize); audio_read_index_addr = config.readIndex; audioPortStart(audio_port); portSize = config.portSize; audio_block_index = 0; //audio_last_read_block = -1; return config.portSize; }
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; }
static int PSL1GHT_AUD_OpenDevice(_THIS, const char *devname, int iscapture) { deprintf( "PSL1GHT_AUD_OpenDevice(%08X.%08X, %s, %d)\n", SHW64(this), devname, iscapture); SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); int valid_datatype = 0; this->hidden = SDL_malloc(sizeof(*(this->hidden))); if (!this->hidden) { SDL_OutOfMemory(); return 0; } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); // PS3 Libaudio only handles floats while ((!valid_datatype) && (test_format)) { this->spec.format = test_format; switch (test_format) { case AUDIO_F32MSB: valid_datatype = 1; break; default: test_format = SDL_NextAudioFormat(); break; } } int ret=audioInit(); //set some parameters we want //either 2 or 8 channel _params.numChannels = AUDIO_PORT_2CH; //8 16 or 32 block buffer _params.numBlocks = AUDIO_BLOCK_8; //extended attributes _params.attrib = 0; //sound level (1 is default) _params.level = 1; ret=audioPortOpen(&_params, &_portNum); deprintf("audioPortOpen: %d\n",ret); deprintf(" portNum: %d\n",_portNum); ret=audioGetPortConfig(_portNum, &_config); deprintf("audioGetPortConfig: %d\n",ret); deprintf(" readIndex: 0x%8X\n",_config.readIndex); deprintf(" status: %d\n",_config.status); deprintf(" channelCount: %ld\n",_config.channelCount); deprintf(" numBlocks: %ld\n",_config.numBlocks); deprintf(" portSize: %d\n",_config.portSize); deprintf(" audioDataStart: 0x%8X\n",_config.audioDataStart); // create an event queue that will tell when a block is read ret=audioCreateNotifyEventQueue( &_snd_queue, &_snd_queue_key); printf("audioCreateNotifyEventQueue: %d\n",ret); // Set it to the sprx ret = audioSetNotifyEventQueue(_snd_queue_key); printf("audioSetNotifyEventQueue: %d\n",ret); // clears the event queue ret = sysEventQueueDrain(_snd_queue); printf("sysEentQueueDrain: %d\n",ret); ret=audioPortStart(_portNum); deprintf("audioPortStart: %d\n",ret); _last_filled_buf = _config.numBlocks - 1; this->spec.format = test_format; this->spec.size = sizeof(float) * AUDIO_BLOCK_SAMPLES * _config.channelCount; this->spec.freq = 48000; this->spec.samples = AUDIO_BLOCK_SAMPLES; this->spec.channels = _config.channelCount; return ret == 0; }
int main(int argc,char *argv[]) { u32 portNum,i; audioPortParam params; audioPortConfig config; s32 ret = audioInit(); printf("audioInit: %08x\n",ret); params.numChannels = AUDIO_PORT_2CH; params.numBlocks = AUDIO_BLOCK_8; params.attrib = 0x1000; params.level = 1.0f; ret = audioPortOpen(¶ms,&portNum); printf("audioPortOpen: %08x\n",ret); printf(" portNum: %d\n",portNum); ret = audioGetPortConfig(portNum,&config); printf("audioGetPortConfig: %08x\n",ret); printf("config.readIndex: %08x\n",config.readIndex); printf("config.status: %d\n",config.status); printf("config.channelCount: %ld\n",config.channelCount); printf("config.numBlocks: %ld\n",config.numBlocks); printf("config.portSize: %d\n",config.portSize); printf("config.audioDataStart: %08x\n",config.audioDataStart); ret = audioCreateNotifyEventQueue(&snd_queue,&snd_key); printf("audioCreateNotifyEventQueue: %08x\n",ret); printf("snd_queue: %16lx\n",(long unsigned int)snd_queue); printf("snd_key: %16lx\n",snd_key); ret = audioSetNotifyEventQueue(snd_key); printf("audioSetNotifyEventQueue: %08x\n",ret); ret = sysEventQueueDrain(snd_queue); printf("sysEventQueueDrain: %08x\n",ret); ret = audioPortStart(portNum); printf("audioPortStart: %08x\n",ret); i = 0; while(i<1000) { playOneBlock(&config); i++; } ret = audioPortStop(portNum); printf("audioPortStop: %08x\n",ret); ret = audioRemoveNotifyEventQueue(snd_key); printf("audioRemoveNotifyEventQueue: %08x\n",ret); ret = audioPortClose(portNum); printf("audioPortClose: %08x\n",ret); ret = sysEventQueueDestroy(snd_queue,0); printf("sysEventQueueDestroy: %08x\n",ret); ret = audioQuit(); printf("audioQuit: %08x\n",ret); return 0; }