diff options
-rw-r--r-- | engines/lab/audioi.cpp | 285 |
1 files changed, 28 insertions, 257 deletions
diff --git a/engines/lab/audioi.cpp b/engines/lab/audioi.cpp index 37aecd58a4..e2c5af819d 100644 --- a/engines/lab/audioi.cpp +++ b/engines/lab/audioi.cpp @@ -28,84 +28,35 @@ * */ -#include "lab/stddefines.h" +#include "audio/mixer.h" +#include "audio/audiostream.h" +#include "audio/decoders/raw.h" +#include "lab/lab.h" +#include "lab/stddefines.h" #include "lab/labfun.h" namespace Lab { #define PLAYBUFSIZE 65536L -#if defined(DOSCODE) -const char VERSION[] = "1.01"; - -char *AudioI_DriverName = "a32sbdg.dll"; -#endif - extern bool MusicOn; -#if defined(DOSCODE) -static HTIMER server; -static HDRIVER hdriver; -static char *drvr; -static char *dll; -static drvr_desc *desc; -#endif //static sound_buff firstblock, tempblock; static int bufnum; -#if defined(DOSCODE) -static unsigned seg1; -static unsigned seg2; -static union REGS inregs, outregs; -#endif bool EffectPlaying = false, ContMusic = false, DoMusic = false; static char *CurMusic, *startMusic; static uint32 StartMusicLen; - - -#if defined(DOSCODE) -static uint16 *mem, *head, *tail, counter; - -#pragma off (check_stack) -void cdecl timer_callback(void) { - - head = (uint16 *)(0x41A); - tail = (uint16 *)(0x41C); - mem = (uint16 *)(0x400 + *head); - - if (*tail > *head) - counter = (*tail - *head) >> 1; - else - counter = (*head - *tail) >> 1; - - if (counter > 16) - counter = 16; - - while (counter) { - if ((*mem == 0x2e03) || (*mem == 0x300) || (*mem == 0x0003)) { - *tail = *head; - return; - } - - mem++; - counter--; - } -} -#endif +static Audio::SoundHandle g_musicHandle; void freeAudio(void) { if (!DoMusic) return; -#if defined(DOSCODE) - AIL_release_timer_handle(server); - - AIL_shutdown(NULL); -#else + // TODO //SDLWrapAudio(); -#endif } @@ -114,114 +65,10 @@ bool initAudio(void) { if (!DoMusic) return true; +// TODO #if 0 -#if defined(DOSCODE) - - AudioI_DriverName = "a32sbdg.dll"; - - // - // Allocate two 16K buffers from real-mode (lower 1MB) memory - // - // *buf1, *buf2 -> protected-mode pointers to buffers (sel:0000) - // *seg1, *seg2 -> real-mode (physical) pointers to buffers (seg:0000) - // - // Note: DPMI calculations assume flat model near pointer offset 0 = - // segment 0, offset 0 (Rational DOS4GW). The reason -- our simple - // file loader function can't use the far pointer formed by the selector - // returned by the DPMI call. - - // Note that these examples do not implement out-of-memory error - // checking - // - - inregs.x.eax = 0x100; - inregs.x.ebx = (16384 / 16); - int386(0x31, &inregs, &outregs); - - seg1 = outregs.x.eax << 16; - buf1 = (char *)(outregs.x.eax * 16); - - if (buf1 == NULL) - return false; - - inregs.x.eax = 0x100; - inregs.x.ebx = (16384 / 16); - int386(0x31, &inregs, &outregs); - - seg2 = outregs.x.eax << 16; - buf2 = (char *)(outregs.x.eax * 16); - - if (buf2 == NULL) - return false; - - // - // Load driver file - // - - dll = FILE_read(AudioI_DriverName, NULL); - - if (dll == NULL) { - return false; - } - - drvr = DLL_load(dll, DLLMEM_ALLOC | DLLSRC_MEM, NULL); - - if (drvr == NULL) { - return false; - } - - free(dll); - - // - // Initialize API before calling any Library functions - // - - AIL_startup(); - - hdriver = AIL_register_driver(drvr); - - if (hdriver == -1) { - AIL_shutdown(NULL); - return false; - } - - // - // Get driver type and factory default I/O parameters; exit if - // driver is not capable of interpreting PCM sound data - // - - desc = AIL_describe_driver(hdriver); - - if (desc->drvr_type != DSP_DRVR) { - AIL_shutdown(NULL); - return false; - } - - if (!AIL_detect_device(hdriver, desc->default_IO, desc->default_IRQ, desc->default_DMA, desc->default_DRQ)) { - desc->default_IRQ = 5; - - if (!AIL_detect_device(hdriver, desc->default_IO, desc->default_IRQ, desc->default_DMA, desc->default_DRQ)) { - AIL_shutdown(NULL); - return false; - } - } - - AIL_init_driver(hdriver, desc->default_IO, desc->default_IRQ, desc->default_DMA, desc->default_DRQ); - - // - // Register a timer function; set up for 10-millisecond (100 Hz.) - // callback intervals - // - - server = AIL_register_timer(timer_callback); - - if (server != -1) { - AIL_set_timer_period(server, 20000L); - AIL_start_timer(server); - } - -#else // we allocate extra mempory for 16-bit samples + // TODO: 8-bit mono sample for DOS buf1 = malloc(PLAYBUFSIZE); if (buf1 == NULL) @@ -234,8 +81,6 @@ bool initAudio(void) { if (!SDLInitAudio()) return false; - -#endif #endif return true; @@ -248,57 +93,23 @@ void initSampleRate(uint16 SampleSpeed) { if (SampleSpeed < 4000) SampleSpeed = 4000; -#if defined(DOSCODE) - firstblock.sample_rate = 256 - (1000000L / SampleSpeed); - firstblock.pack_type = 0 | 0x80; // 8-bit mono sample -#else //firstblock.sample_rate = SampleSpeed; //firstblock.pack_type = AUDIO_S16; // SOUND_MONO | SOUND_16BIT; // 16-bit mono sample -#endif + // TODO: 8-bit mono sample for DOS } bool musicBufferEmpty(uint16 i) { -#if defined(NEWCODE) - return (AIL_sound_buffer_status(hdriver, i) == DAC_DONE); -#else - //return (SDLSoundBufferStatus(i) == DAC_DONE); - return true; -#endif + // TODO: Multiple streams + return !g_lab->_mixer->isSoundHandleActive(g_musicHandle); } void playMusicBlock(void *Ptr, uint32 Size, uint16 BufferNum, uint16 SampleSpeed) { -#if defined(DOSCODE) - uint32 TempPtr; - uint32 seg; - char *buf; - - TempPtr = ((uint32) Ptr) / 16L; - - seg = TempPtr << 16; - buf = (char *)(TempPtr * 16); - - if (SampleSpeed < 4000) - SampleSpeed = 4000; - - firstblock.sample_rate = 256 - (1000000L / SampleSpeed); - firstblock.pack_type = 0 | 0x80; // 8-bit mono sample - - tempblock = firstblock; - tempblock.sel_data = buf; - tempblock.seg_data = seg; - tempblock.len = Size; - - AIL_register_sound_buffer(hdriver, BufferNum, &tempblock); - AIL_format_sound_buffer(hdriver, &tempblock); - - AIL_start_digital_playback(hdriver); - AIL_set_digital_playback_volume(hdriver, 127); -#else + // TODO #if 0 if (SampleSpeed < 4000) @@ -306,6 +117,7 @@ void playMusicBlock(void *Ptr, uint32 Size, uint16 BufferNum, uint16 SampleSpeed firstblock.sample_rate = SampleSpeed; firstblock.pack_type = SOUND_MONO | SOUND_16BIT; // 16-bit mono sample + // TODO: 8-bit mono sample for DOS tempblock = firstblock; tempblock.sel_data = Ptr; @@ -313,7 +125,6 @@ void playMusicBlock(void *Ptr, uint32 Size, uint16 BufferNum, uint16 SampleSpeed SDLPlayBuffer(BufferNum, &tempblock); #endif -#endif } @@ -324,52 +135,14 @@ void updateSoundBuffers(void) { if (!EffectPlaying) return; -#if defined(DOSCODE) - - for (int i = 0; i < 2; i++) { - if ((AIL_sound_buffer_status(hdriver, i) == DAC_DONE) && firstblock.len) { - tempblock.len = MIN(16384L, firstblock.len); - firstblock.len -= tempblock.len; - - if (!(bufnum ^= 1)) { - memcpy(buf1, CurMusic, (unsigned) tempblock.len); - tempblock.sel_data = buf1; - tempblock.seg_data = seg1; - } else { - memcpy(buf2, CurMusic, (unsigned) tempblock.len); - tempblock.sel_data = buf2; - tempblock.seg_data = seg2; - } - - CurMusic += tempblock.len; - - AIL_register_sound_buffer(hdriver, i, &tempblock); - AIL_format_sound_buffer(hdriver, &tempblock); - - AIL_start_digital_playback(hdriver); - AIL_set_digital_playback_volume(hdriver, 127); - } - } - - // - // Playback ends when no bytes are left in the source data and - // the status of both buffers equals DAC_DONE - // - - if (!firstblock.len) { - if (ContMusic) { - CurMusic = startMusic; - firstblock.len = StartMusicLen; - } else if ((AIL_sound_buffer_status(hdriver, 0) == DAC_DONE) && - (AIL_sound_buffer_status(hdriver, 1) == DAC_DONE)) { - flushAudio(); - EffectPlaying = false; - } + // TODO + // FIXME: Very crude implementation + if (musicBufferEmpty(0)) { + flushAudio(); + EffectPlaying = false; } -#else #if 0 - for (int i = 0; i < 2; i++) { if ((SDLSoundBufferStatus(i) == DAC_DONE) && firstblock.len) { // use extra memory for 16-bit samples @@ -407,7 +180,6 @@ void updateSoundBuffers(void) { } #endif -#endif } @@ -416,11 +188,7 @@ void flushAudio(void) { if (!DoMusic) return; -#if defined(DOSCODE) - AIL_stop_digital_playback(hdriver); -#else - //SDLStopPlayback(); -#endif + g_lab->_mixer->stopHandle(g_musicHandle); EffectPlaying = false; } @@ -439,13 +207,9 @@ void playMusic(uint16 SampleSpeed, uint16 Volume, uint32 Length, bool flush, voi if (SampleSpeed < 4000) SampleSpeed = 4000; -#if defined(DOSCODE) - firstblock.sample_rate = 256 - (1000000L / SampleSpeed); - firstblock.pack_type = 0 | 0x80; // 8-bit mono sample -#else //firstblock.sample_rate = SampleSpeed; //firstblock.pack_type = SOUND_MONO | SOUND_16BIT; // 16-bit mono sample -#endif + // TODO: 8-bit mono sample for DOS //firstblock.len = Length; bufnum = 0; @@ -455,6 +219,13 @@ void playMusic(uint16 SampleSpeed, uint16 Volume, uint32 Length, bool flush, voi startMusic = CurMusic; StartMusicLen = Length; + byte soundFlags = Audio::FLAG_LITTLE_ENDIAN; + if (g_lab->getPlatform() == Common::kPlatformWindows) + soundFlags |= Audio::FLAG_16BITS; + + Audio::SeekableAudioStream *audStream = Audio::makeRawStream((const byte *)Data, Length, SampleSpeed, soundFlags, DisposeAfterUse::NO); + g_lab->_mixer->playStream(Audio::Mixer::kMusicSoundType, &g_musicHandle, audStream); + updateSoundBuffers(); } |