Ticket #8017: creative.diff

File creative.diff, 5.0 KB (added by SF/xtrochu, 22 years ago)
  • resource.cpp

    RCS file: /cvsroot/scummvm/scummvm/resource.cpp,v
    retrieving revision 1.103
    diff -u -r1.103 resource.cpp
     
    725725                total_size = fileReadDwordBE();
    726726                fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
    727727                return 1;
     728        } else if (basetag == MKID('Crea')) {
     729                fileSeek(_fileHandle, -12, SEEK_CUR);
     730                total_size = fileReadDwordBE();
     731                fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
     732                return 1;
    728733        } else {
    729734                fprintf(stderr, "WARNING: Unrecognized base tag 0x%08lx in sound %d\n", basetag, idx);
    730735        }
     
    837842{
    838843        byte *ptr;
    839844
    840         debug(9, "nukeResource(%s,%d)", resTypeFromId(type), idx);
    841845
    842846        CHECK_HEAP if (!res.address[type])
    843847                  return;
     
    845849        assert(idx >= 0 && idx < res.num[type]);
    846850
    847851        if ((ptr = res.address[type][idx]) != NULL) {
     852                debug(9, "nukeResource(%s,%d)", resTypeFromId(type), idx);
    848853                res.address[type][idx] = 0;
    849854                res.flags[type][idx] = 0;
    850855                _allocatedSize -= ((MemBlkHeader *)ptr)->size;
  • sound.cpp

    RCS file: /cvsroot/scummvm/scummvm/sound.cpp,v
    retrieving revision 1.129
    diff -u -r1.129 sound.cpp
     
    4848                _scumm->_vars[_scumm->VAR_LAST_SOUND] = sound;
    4949                _scumm->ensureResourceLoaded(rtSound, sound);
    5050                addSoundToQueue2(sound);
     51        } else {
     52                // WARNING ! This may break something, maybe this sould be put inside if(_gameID == GID_FT) ?
     53                // But why addSoundToQueue should not queue sound ?
     54                _scumm->ensureResourceLoaded(rtSound, sound);
     55                addSoundToQueue2(sound);
    5156        }
    5257
    5358//      if (_features & GF_AUDIOTRACKS)
     
    162167        _soundQuePos = 0;
    163168}
    164169
     170static char * read_creative_voc_file(byte * ptr, int & size, int & rate) {
     171        assert(strncmp((char*)ptr, "Creative Voice File\x1A", 20) == 0);
     172        int offset = READ_LE_UINT16(ptr+20);
     173        short version = READ_LE_UINT16(ptr+22);
     174        short code = READ_LE_UINT16(ptr+24);
     175        assert(version == 0x010A || version == 0x0114);
     176        assert(code == ~version + 0x1234);
     177        bool quit = 0;
     178        char * ret_sound = 0; size = 0;
     179        while(!quit) {
     180                int len = READ_LE_UINT32(ptr + offset);
     181                offset += 4;
     182                int code = len & 0xFF;          // FIXME not sure this is endian correct
     183                len >>= 8;
     184                switch(code) {
     185                        case 0: quit = 1; break;
     186                        case 1: {
     187                                int time_constant = ptr[offset++];
     188                                int packing = ptr[offset++];
     189                                len -= 2;
     190                                rate = 1000000L / (256L - time_constant);
     191                                debug(9, "VOC Data Bloc : %d, %d, %d", rate, packing, len);
     192                                if(packing == 0) {
     193                                        if(size) {
     194                                                ret_sound = (char*)realloc(ret_sound, size + len);
     195                                        } else {
     196                                                ret_sound = (char*)malloc(len);
     197                                        }
     198                                        memcpy(ret_sound + size, ptr + offset, len);
     199                                        size += len;
     200                                } else {
     201                                        warning("VOC file packing %d unsupported", packing);
     202                                }
     203                                } break;
     204                        case 6: // begin of loop
     205                                debug(3, "loops in Creative files not supported");
     206                                break;
     207                        case 7: // end of loop
     208                                break;
     209                        default:
     210                                warning("Invalid code in VOC file : %d", code);
     211                                //~ quit = 1;
     212                                break;
     213                }
     214                offset += len;
     215        }
     216        debug(9, "VOC Data Size : %d", size);
     217        return ret_sound;
     218}
     219
    165220void Sound::playSound(int sound) {
    166221        byte *ptr;
    167         IMuse *se = _scumm->_imuse;
    168 
     222       
    169223        ptr = _scumm->getResourceAddress(rtSound, sound);
    170224        if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('SOUN')) {
    171225                ptr += 8;
     
    180234                _scumm->current_cd_sound = sound;
    181235                return;
    182236        }
    183 
    184237        // Support for SFX in Monkey Island 1, Mac version
    185238        // This is rather hackish right now, but works OK. SFX are not sounding
    186239        // 100% correct, though, not sure right now what is causing this.
    187         if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('Mac1')) {
     240        else if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('Mac1')) {
    188241
    189242                // Read info from the header
    190243                int size = READ_UINT32_UNALIGNED(ptr+0x60);
     
    216269                _scumm->_mixer->play_raw(NULL, sound, size, rate, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE);
    217270                return;
    218271        }
     272        else if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('Crea')) {
     273                int size, rate;
     274                char * sound = read_creative_voc_file(ptr, size, rate);
     275                if(sound != NULL) {
     276                        _scumm->_mixer->play_raw(NULL, sound, size, rate, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE);
     277                }
     278                return;
     279        }
    219280        // Support for sampled sound effects in Monkey1 and Monkey2
    220281        else if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('SBL ')) {
    221282                debug(2, "Using SBL sound effect");
     
    332393        if (_scumm->_gameId == GID_MONKEY_VGA)
    333394                return;                                                                                 /* FIXME */
    334395
     396        IMuse *se = _scumm->_imuse;
    335397        if (se) {
    336398                _scumm->getResourceAddress(rtSound, sound);
    337399                se->start_sound(sound);