const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } int hz = GetDriverParamInt(parm, "hz", 44100); _buffer_size = GetDriverParamInt(parm, "samples", 1024) * hz / 11025; _stream = play_audio_stream(_buffer_size, 16, true, hz, 255, 128); MxInitialize(hz); return NULL; }
const char *SoundDriver_Win32::Start(const char * const *parm) { WAVEFORMATEX wfex; wfex.wFormatTag = WAVE_FORMAT_PCM; wfex.nChannels = 2; wfex.wBitsPerSample = 16; wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 44100); wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; /* Limit buffer size to prevent overflows. */ _bufsize = GetDriverParamInt(parm, "bufsize", (GB(GetVersion(), 0, 8) > 5) ? 8192 : 4096); _bufsize = min(_bufsize, UINT16_MAX); try { if (NULL == (_event = CreateEvent(NULL, FALSE, FALSE, NULL))) throw "Failed to create event"; if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)_event, 0, CALLBACK_EVENT) != MMSYSERR_NOERROR) throw "waveOutOpen failed"; MxInitialize(wfex.nSamplesPerSec); PrepareHeader(&_wave_hdr[0]); PrepareHeader(&_wave_hdr[1]); if (NULL == (_thread = CreateThread(NULL, 8192, SoundThread, 0, 0, &_threadId))) throw "Failed to create thread"; } catch (const char *error) { this->Stop(); return error; } return NULL; }
const char *SoundDriver_SDL::Start(const char * const *parm) { SDL_AudioSpec spec; const char *s = SdlOpen(SDL_INIT_AUDIO); if (s != NULL) return s; spec.freq = GetDriverParamInt(parm, "hz", 44100); spec.format = AUDIO_S16SYS; spec.channels = 2; spec.samples = 512; spec.callback = fill_sound_buffer; MxInitialize(spec.freq); SDL_CALL SDL_OpenAudio(&spec, &spec); SDL_CALL SDL_PauseAudio(0); return NULL; }
const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } _stream = play_audio_stream(BUFFER_SIZE, 16, true, 44100, 255, 128); MxInitialize(44100); return NULL; }