/*------------------------------------------------------ «µ«¦«ó«É«¨«ß«å«ì£«·«ç«óôøÑ¢ûù ------------------------------------------------------*/ int sound_init(void) { qsound_sh_start(); #ifdef GP2X if (sound_fd >= 0) close(sound_fd); sound_fd = open("/dev/dsp", O_WRONLY|O_ASYNC); if (sound_fd == -1) { printf("Couldn't open /dev/dsp device.\n"); option_sound_enable = 0; return 0; } else { int rate, bits, stereo, frag; rate = 44100 >> (2 - option_samplerate); bits = 16; stereo = 1; ioctl(sound_fd, SNDCTL_DSP_SPEED, &rate); ioctl(sound_fd, SNDCTL_DSP_SETFMT, &bits); ioctl(sound_fd, SNDCTL_DSP_STEREO, &stereo); frag = 10 + option_samplerate; frag |= 2 << 16; ioctl(sound_fd, SNDCTL_DSP_SETFRAGMENT, &frag); } sound_id = pthread_create(&sound_th, NULL, sound_thread, NULL); if (sound_id < 0) { msg_printf("Sound thread create failed."); option_sound_enable = 0; return 0; } sound_play = 1; #else SDL_AudioSpec spec; spec.format = AUDIO_S16; spec.channels = 2; spec.freq = 44100 >> (2 - option_samplerate); spec.samples = SOUND_SAMPLES >> (2 - option_samplerate); spec.callback = qsound_update; spec.userdata = NULL; if (SDL_OpenAudio(&spec, NULL) < 0) { printf("Unable to open audio: %s.\n", SDL_GetError()); return 0; } SDL_PauseAudio(0); #endif printf("Sound device initialized...\n"); return 1; }
int32 qsf_command(void *handle, int32 command, int32 parameter) { qsf_synth_t *s = handle; switch (command) { case COMMAND_RESTART: memcpy (s->RAM, s->initRAM, 0x1000); memcpy (s->RAM2, s->initRAM2, 0x1000); if (s->z80) { z80_reset(s->z80, NULL); z80_set_irq_callback(s->z80, qsf_irq_cb); } qsound_sh_stop (s->qs); s->qs = qsound_sh_start(&qsintf); s->samples_to_next_tick = samples_per_tick; return AO_SUCCESS; } return AO_FAIL; }
int init_sound_emulators(void) { int i,j; if(change_sample_rate) saStopSoundEmulators(); if (emulators_active) return 0; change_sample_rate = 0; if( SndMachine ){ if( !SndMachine->first ){ saInitVolPan(); /* moved. (hiro-shi) */ SndMachine->first = 1; /* first flag clear */ streams_sh_start(); /* streaming system initialize & start */ for( j = 0; j < SndMachine->control_max; j++ ){ switch( SndMachine->init[j] ){ #if HAS_YM2203 case SOUND_YM2203: i = YM2203_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM2151 case SOUND_YM2151S: i = YM2151_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM2413 case SOUND_YM2413: i = YM2413_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM2151_ALT case SOUND_YM2151J: i = YM2151_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM2610 case SOUND_YM2610: i = YM2610_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM2610B case SOUND_YM2610B: i = YM2610B_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_MSM5205_BUFF case SOUND_MSM5205_BUFF: i = MSM5205buffer_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_ADPCM case SOUND_M6295: i = OKIM6295_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_AY8910 case SOUND_AY8910: i = AY8910_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YM3812 case SOUND_YM3812: i = YM3812_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_SMP16 case SOUND_SMP16: i = SMP16buffer_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_M6585 case SOUND_M6585: i = M6585buffer_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YMZ280B case SOUND_YMZ280B: i = YMZ280B_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_ES5505 case SOUND_ES5505: i = ES5505_sh_start( SndMachine->intf[j] ); break; case SOUND_ES5506: i = ES5506_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_QSOUND case SOUND_QSOUND: i = qsound_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_YMF278B case SOUND_YMF278B: i = YMF278B_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_NAMCO case SOUND_NAMCO: i = namco_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_X1_010 case SOUND_X1_010: i = seta_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_DAC case SOUND_DAC: i = DAC_sh_start( SndMachine->intf[j] ); break; #endif #if HAS_DXSMP case SOUND_DXSMP: i = dxsmp_sh_start( SndMachine->intf[j] ); break; #endif default: i = 1; break; } if( i ){ audio_sample_rate = 0; SndMachine = NULL; printf("emulator init failed\n"); return 1; } } } } emulators_active = 1; return 0; }
void *qsf_start(const char *path, uint8 *buffer, uint32 length) { qsf_synth_t *s = malloc (sizeof (qsf_synth_t)); memset (s, 0, sizeof (qsf_synth_t)); uint8 *file = NULL, *lib_decoded = NULL, *lib_raw_file = NULL; uint64 file_len, lib_len, lib_raw_length; corlett_t *lib; s->z80 = z80_init(); s->z80->userdata = s; s->Z80ROM = malloc(512*1024); s->QSamples = malloc(8*1024*1024); s->skey1 = s->skey2 = 0; s->akey = 0; s->xkey = 0; s->cur_bank = 0; // Decode the current QSF if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { return AO_FAIL; } // Get the library file if (s->c->lib[0] != 0) { uint64 tmp_length; char libpath[PATH_MAX]; ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath)); #if DEBUG_LOADER printf("Loading library: %s\n", libpath); #endif if (ao_get_lib(libpath, &lib_raw_file, &tmp_length) != AO_SUCCESS) { free (file); qsf_stop (s); return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); free (file); qsf_stop (s); return NULL; } // Free up raw file free(lib_raw_file); // use the contents qsf_walktags(s, lib_decoded, lib_decoded+lib_len); // Dispose the corlett structure for the lib - we don't use it free(lib); if (lib_decoded) { free (lib_decoded); lib_decoded = NULL; } } // now patch the file into RAM OVER the libraries qsf_walktags(s, file, file+file_len); free(file); if ((s->skey1 != 0) && (s->skey2 != 0)) { #if DEBUG_LOADER printf("Decoding Kabuki: skey1 %08x skey2 %08x akey %04x xkey %02x\n", skey1, skey2, akey, xkey); #endif s->uses_kabuki = 1; cps1_decode((unsigned char *)s->Z80ROM, s->skey1, s->skey2, s->akey, s->xkey); } // set qsfby tag strcpy(s->qsfby, "n/a"); if (s->c) { int i; for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { if (!strcasecmp(s->c->tag_name[i], "qsfby")) { strcpy(s->qsfby, s->c->tag_data[i]); } } } memcpy (s->initRAM, s->RAM, 0x1000); memcpy (s->initRAM2, s->RAM2, 0x1000); if (s->z80) { z80_reset(s->z80, NULL); z80_set_irq_callback(s->z80, qsf_irq_cb); } qsintf.sample_rom = s->QSamples; s->qs = qsound_sh_start(&qsintf); s->samples_to_next_tick = samples_per_tick; return s; }
int32 qsf_start(uint8 *buffer, uint32 length) { uint8 *file, *lib_decoded, *lib_raw_file; uint64 file_len, lib_len, lib_raw_length; corlett_t *lib; z80_init(); Z80ROM = malloc(512*1024); QSamples = malloc(8*1024*1024); skey1 = skey2 = 0; akey = 0; xkey = 0; cur_bank = 0; memset(RAM, 0, 0x1000); memset(RAM2, 0, 0x1000); // Decode the current QSF if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) { return AO_FAIL; } // Get the library file if (c->lib[0] != 0) { uint64 tmp_length; #if DEBUG_LOADER printf("Loading library: %s\n", c->lib); #endif if (ao_get_lib(c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) { return AO_FAIL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); return AO_FAIL; } // Free up raw file free(lib_raw_file); // use the contents qsf_walktags(lib_decoded, lib_decoded+lib_len); // Dispose the corlett structure for the lib - we don't use it free(lib); } // now patch the file into RAM OVER the libraries qsf_walktags(file, file+file_len); free(file); if ((skey1 != 0) && (skey2 != 0)) { #if DEBUG_LOADER printf("Decoding Kabuki: skey1 %08x skey2 %08x akey %04x xkey %02x\n", skey1, skey2, akey, xkey); #endif uses_kabuki = 1; cps1_decode((unsigned char *)Z80ROM, skey1, skey2, akey, xkey); } // set qsfby tag strcpy(qsfby, "n/a"); if (c) { int i; for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { if (!strcasecmp(c->tag_name[i], "qsfby")) { strcpy(qsfby, c->tag_data[i]); } } } z80_reset(NULL); z80_set_irq_callback(qsf_irq_cb); qsintf.sample_rom = QSamples; qsound_sh_start(&qsintf); return AO_SUCCESS; }