static StorageEntry* Ole_readStorageFromBytearray(ByteArray* bytearray) { //int position = bytearray->position; StorageEntry* storage = (StorageEntry*)malloc(sizeof(StorageEntry)); //ByteArray_print16(bytearray,0); memset(storage,0,sizeof(StorageEntry)); storage->name = ByteArray_readUtf16(bytearray,32); //bytearray->position += 64; storage->entryStrLen = ByteArray_readInt16(bytearray); storage->type= ByteArray_readByte(bytearray); storage->color= ByteArray_readByte(bytearray); storage->leftSonId = ByteArray_readInt32(bytearray); storage->rightSonId = ByteArray_readInt32(bytearray); storage->rootId = ByteArray_readInt32(bytearray); storage->id= bytearray->data+bytearray->position; bytearray->position+=16; storage->uid= ByteArray_readInt32(bytearray); bytearray->position+=16; storage->sid0= ByteArray_readInt32(bytearray); storage->streamSize= ByteArray_readInt32(bytearray); bytearray->position+=4; printf("name: %s,",storage->name); //printf("%d,",bytearray->position-position); //printf("storage id:%d\n",storage->id); switch(storage->type) { case 0: printf("type:%s,","invalid"); return storage; break; case 1: printf("type:%s,","storage"); break; case 2: printf("type:%s,","stream"); break; case 3: printf("type:%s,","lockbytes"); break; case 4: printf("type:%s,","property"); break; case 5: printf("type:%s,","root"); break; } /* if(storage->color) printf("storage color:%s\n","black"); else printf("storage color:%s\n","red"); */ if(storage->leftSonId!=-1) printf("left :%d ;",storage->leftSonId); if(storage->rightSonId !=-1) printf("right :%d ;",storage->rightSonId); if(storage->rootId !=-1) printf("treeId :%d ;",storage->rootId); printf("streamSize:0x%x ;",storage->streamSize); printf("sectorId :%d\n",storage->sid0); //printf("-----------------------\n"); return storage; }
static void *thread_func(void* data) { (void) data; while(1) { mlock(); if(playa.thread_music_status == TS_STOPPING) { playa.thread_music_status = TS_WAITING; munlock(); msleep(1); continue; } else if(playa.thread_music_status == TS_DONE || playa.thread_music_status == TS_WAITING) { munlock(); msleep(4); continue; } munlock(); if(MUSIC_FINISHED()) { mlock(); playa.thread_music_status = TS_DONE; munlock(); continue; } GEN_MUSIC(); if(MUSIC_AVAIL()) { //dprintf(2, "writing %zu bytes...\n", (size_t) playa.out_wave.pos); slock(); if(playa.play_waveslot != -1) { struct ByteArray* mine = &playa.wave_streams[playa.play_waveslot]; if(!mine->bytesAvailable(mine)) { playa.play_waveslot = -1; goto mixin_done; } struct ByteArray* out = &playa.out_wave; off_t savepos = out->pos; size_t avail = mine->bytesAvailable(mine); size_t upsample_factor = 44100 / playa.wavhdr.wave_hdr.samplerate; size_t processed_m = 0, processed_w = 0; size_t readbytes = playa.wavhdr.wave_hdr.bitwidth == 8 ? 1 : 2; int chan[2] = { 0, 0 }; int next[2]; ByteArray_set_position(out, 0); while(processed_m < (size_t)savepos && processed_w < avail) { size_t c, u; for(c = 0; c < 2; c++) { if(c < playa.wavhdr.wave_hdr.channels) { if(readbytes == 1) next[c] = ((uint8_t) ByteArray_readByte(mine) - 128) * 256; else next[c] = ByteArray_readShort(mine); handle_overflow(&next[c]); } else next[c] = next[c - 1]; processed_w += readbytes; } for(u = 0; u < upsample_factor; u++) { for(c = 0; c < 2; c++) { int interpolated = u == 0 ? chan[c] : chan[c] + ((next[c]-chan[c]) * ((float)u/(float)upsample_factor)); interpolated = (float) interpolated * 0.3; // decrease volume to avoid overflow int music = GET_MUSIC_WORD(); int sample = music + interpolated; if(handle_overflow(&sample)) dprintf(2, "overflow\n"); MUSIC_REWIND_WORD(); ByteArray_writeShort(out, sample); processed_m += 2; } } for (c=0; c<2; c++) chan[c] = next[c]; } ByteArray_set_position(out, savepos); } mixin_done: sunlock(); BACKEND_WRITE(&playa.writer.ao, playa.wave_buffer, playa.out_wave.pos); //dprintf(2, "done\n"); playa.out_wave.pos = 0; } } return 0; }