int opl3class::fm_init(unsigned int rate) { OPL3_Reset(&chip, rate); memset(command,0,sizeof(command)); memset(time, 0, sizeof(time)); memset(samples, 0, sizeof(samples)); counter = 0; lastwrite = 0; strpos = 0; endpos = 0; resampler = resampler_create(); if (!resampler) return 0; resampler_set_rate(resampler, 49716.0 / (double)rate); return 1; }
static int OPL_SDL_Init(unsigned int port_base) { // Check if SDL_mixer has been opened already // If not, we must initialize it now if (!SDLIsInitialized()) { if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to set up sound.\n"); return 0; } if (Mix_OpenAudio(opl_sample_rate, AUDIO_S16SYS, 2, GetSliceSize()) < 0) { fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); SDL_QuitSubSystem(SDL_INIT_AUDIO); return 0; } SDL_PauseAudio(0); // When this module shuts down, it has the responsibility to // shut down SDL. sdl_was_initialized = 1; } else { sdl_was_initialized = 0; } opl_sdl_paused = 0; pause_offset = 0; // Queue structure of callbacks to invoke. callback_queue = OPL_Queue_Create(); current_time = 0; // Get the mixer frequency, format and number of channels. Mix_QuerySpec(&mixing_freq, &mixing_format, &mixing_channels); // Only supports AUDIO_S16SYS if (mixing_format != AUDIO_S16SYS || mixing_channels != 2) { fprintf(stderr, "OPL_SDL only supports native signed 16-bit LSB, " "stereo format!\n"); OPL_SDL_Shutdown(); return 0; } // Mix buffer: mix_buffer = malloc(mixing_freq * sizeof(uint32_t) * 2); // Create the emulator structure: OPL3_Reset(&opl_chip, mixing_freq); opl_opl3mode = 0; callback_mutex = SDL_CreateMutex(); callback_queue_mutex = SDL_CreateMutex(); // TODO: This should be music callback? or-? Mix_HookMusic(OPL_Mix_Callback, NULL); return 1; }