summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/modplug/load_ams.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/modplug/load_ams.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/modplug/load_ams.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/modplug/load_ams.cpp b/core/multimedia/opieplayer/modplug/load_ams.cpp
index 3dd1c2b..ad1cc01 100644
--- a/core/multimedia/opieplayer/modplug/load_ams.cpp
+++ b/core/multimedia/opieplayer/modplug/load_ams.cpp
@@ -437,195 +437,195 @@ BOOL CSoundFile::ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength)
437 if (m_lpszSongComments) 437 if (m_lpszSongComments)
438 { 438 {
439 memcpy(m_lpszSongComments, lpStream+dwMemPos+1, composernamelen); 439 memcpy(m_lpszSongComments, lpStream+dwMemPos+1, composernamelen);
440 m_lpszSongComments[composernamelen] = 0; 440 m_lpszSongComments[composernamelen] = 0;
441 } 441 }
442 } 442 }
443 dwMemPos += composernamelen + 1; 443 dwMemPos += composernamelen + 1;
444 // channel names 444 // channel names
445 for (UINT i=0; i<32; i++) 445 for (UINT i=0; i<32; i++)
446 { 446 {
447 UINT chnnamlen = lpStream[dwMemPos]; 447 UINT chnnamlen = lpStream[dwMemPos];
448 if ((chnnamlen) && (chnnamlen < MAX_CHANNELNAME)) 448 if ((chnnamlen) && (chnnamlen < MAX_CHANNELNAME))
449 { 449 {
450 memcpy(ChnSettings[i].szName, lpStream+dwMemPos+1, chnnamlen); 450 memcpy(ChnSettings[i].szName, lpStream+dwMemPos+1, chnnamlen);
451 } 451 }
452 dwMemPos += chnnamlen + 1; 452 dwMemPos += chnnamlen + 1;
453 if (dwMemPos + chnnamlen + 256 >= dwMemLength) return TRUE; 453 if (dwMemPos + chnnamlen + 256 >= dwMemLength) return TRUE;
454 } 454 }
455 // packed comments (ignored) 455 // packed comments (ignored)
456 UINT songtextlen = *((LPDWORD)(lpStream+dwMemPos)); 456 UINT songtextlen = *((LPDWORD)(lpStream+dwMemPos));
457 dwMemPos += songtextlen; 457 dwMemPos += songtextlen;
458 if (dwMemPos + 256 >= dwMemLength) return TRUE; 458 if (dwMemPos + 256 >= dwMemLength) return TRUE;
459 } 459 }
460 // Order List 460 // Order List
461 { 461 {
462 for (UINT i=0; i<MAX_ORDERS; i++) 462 for (UINT i=0; i<MAX_ORDERS; i++)
463 { 463 {
464 Order[i] = 0xFF; 464 Order[i] = 0xFF;
465 if (dwMemPos + 2 >= dwMemLength) return TRUE; 465 if (dwMemPos + 2 >= dwMemLength) return TRUE;
466 if (i < psh->orders) 466 if (i < psh->orders)
467 { 467 {
468 Order[i] = lpStream[dwMemPos]; 468 Order[i] = lpStream[dwMemPos];
469 dwMemPos += 2; 469 dwMemPos += 2;
470 } 470 }
471 } 471 }
472 } 472 }
473 // Pattern Data 473 // Pattern Data
474 for (UINT ipat=0; ipat<psh->patterns; ipat++) 474 for (UINT ipat=0; ipat<psh->patterns; ipat++)
475 { 475 {
476 if (dwMemPos+8 >= dwMemLength) return TRUE; 476 if (dwMemPos+8 >= dwMemLength) return TRUE;
477 UINT packedlen = *((LPDWORD)(lpStream+dwMemPos)); 477 UINT packedlen = *((LPDWORD)(lpStream+dwMemPos));
478 UINT numrows = 1 + (UINT)(lpStream[dwMemPos+4]); 478 UINT numrows = 1 + (UINT)(lpStream[dwMemPos+4]);
479 //UINT patchn = 1 + (UINT)(lpStream[dwMemPos+5] & 0x1F); 479 //UINT patchn = 1 + (UINT)(lpStream[dwMemPos+5] & 0x1F);
480 //UINT patcmds = 1 + (UINT)(lpStream[dwMemPos+5] >> 5); 480 //UINT patcmds = 1 + (UINT)(lpStream[dwMemPos+5] >> 5);
481 UINT patnamlen = lpStream[dwMemPos+6]; 481 UINT patnamlen = lpStream[dwMemPos+6];
482 dwMemPos += 4; 482 dwMemPos += 4;
483 if ((ipat < MAX_PATTERNS) && (packedlen < dwMemLength-dwMemPos) && (numrows >= 8)) 483 if ((ipat < MAX_PATTERNS) && (packedlen < dwMemLength-dwMemPos) && (numrows >= 8))
484 { 484 {
485 if ((patnamlen) && (patnamlen < MAX_PATTERNNAME)) 485 if ((patnamlen) && (patnamlen < MAX_PATTERNNAME))
486 { 486 {
487 char s[MAX_PATTERNNAME]; // changed from CHAR 487 char s[MAX_PATTERNNAME]; // changed from CHAR
488 memcpy(s, lpStream+dwMemPos+3, patnamlen); 488 memcpy(s, lpStream+dwMemPos+3, patnamlen);
489 s[patnamlen] = 0; 489 s[patnamlen] = 0;
490 SetPatternName(ipat, s); 490 SetPatternName(ipat, s);
491 } 491 }
492 PatternSize[ipat] = numrows; 492 PatternSize[ipat] = numrows;
493 Patterns[ipat] = AllocatePattern(numrows, m_nChannels); 493 Patterns[ipat] = AllocatePattern(numrows, m_nChannels);
494 if (!Patterns[ipat]) return TRUE; 494 if (!Patterns[ipat]) return TRUE;
495 // Unpack Pattern Data 495 // Unpack Pattern Data
496 LPCBYTE psrc = lpStream + dwMemPos; 496 LPCBYTE psrc = lpStream + dwMemPos;
497 UINT pos = 3 + patnamlen; 497 UINT pos = 3 + patnamlen;
498 UINT row = 0; 498 UINT row = 0;
499 while ((pos < packedlen) && (row < numrows)) 499 while ((pos < packedlen) && (row < numrows))
500 { 500 {
501 MODCOMMAND *m = Patterns[ipat] + row * m_nChannels; 501 MODCOMMAND *m = Patterns[ipat] + row * m_nChannels;
502 UINT byte1 = psrc[pos++]; 502 UINT byte1 = psrc[pos++];
503 UINT ch = byte1 & 0x1F; 503 UINT ch = byte1 & 0x1F;
504 // Read Note + Instr 504 // Read Note + Instr
505 if (!(byte1 & 0x40)) 505 if (!(byte1 & 0x40))
506 { 506 {
507 UINT byte2 = psrc[pos++]; 507 UINT byte2 = psrc[pos++];
508 UINT note = byte2 & 0x7F; 508 UINT note = byte2 & 0x7F;
509 if (note) m[ch].note = (note > 1) ? (note-1) : 0xFF; 509 if (note) m[ch].note = (note > 1) ? (note-1) : 0xFF;
510 m[ch].instr = psrc[pos++]; 510 m[ch].instr = psrc[pos++];
511 // Read Effect 511 // Read Effect
512 while (byte2 & 0x80) 512 while (byte2 & 0x80)
513 { 513 {
514 byte2 = psrc[pos++]; 514 byte2 = psrc[pos++];
515 if (byte2 & 0x40) 515 if (byte2 & 0x40)
516 { 516 {
517 m[ch].volcmd = VOLCMD_VOLUME; 517 m[ch].volcmd = VOLCMD_VOLUME;
518 m[ch].vol = byte2 & 0x3F; 518 m[ch].vol = byte2 & 0x3F;
519 } else 519 } else
520 { 520 {
521 UINT command = byte2 & 0x3F; 521 UINT command = byte2 & 0x3F;
522 UINT param = psrc[pos++]; 522 UINT param = psrc[pos++];
523 if (command == 0x0C) 523 if (command == 0x0C)
524 { 524 {
525 m[ch].volcmd = VOLCMD_VOLUME; 525 m[ch].volcmd = VOLCMD_VOLUME;
526 m[ch].vol = param / 2; 526 m[ch].vol = param / 2;
527 } else 527 } else
528 if (command < 0x10) 528 if (command < 0x10)
529 { 529 {
530 m[ch].command = command; 530 m[ch].command = command;
531 m[ch].param = param; 531 m[ch].param = param;
532 ConvertModCommand(&m[ch]); 532 ConvertModCommand(&m[ch]);
533 } else 533 } else
534 { 534 {
535 // TODO: AMS effects 535 // TODO: AMS effects
536 } 536 }
537 } 537 }
538 } 538 }
539 } 539 }
540 if (byte1 & 0x80) row++; 540 if (byte1 & 0x80) row++;
541 } 541 }
542 } 542 }
543 dwMemPos += packedlen; 543 dwMemPos += packedlen;
544 } 544 }
545 // Read Samples 545 // Read Samples
546 for (UINT iSmp=1; iSmp<=m_nSamples; iSmp++) if (Ins[iSmp].nLength) 546 for (UINT iSmp=1; iSmp<=m_nSamples; iSmp++) if (Ins[iSmp].nLength)
547 { 547 {
548 if (dwMemPos >= dwMemLength - 9) return TRUE; 548 if (dwMemPos >= dwMemLength - 9) return TRUE;
549 UINT flags; 549 UINT flags;
550 if (packedsamples[iSmp] & 0x03) 550 if (packedsamples[iSmp] & 0x03)
551 { 551 {
552 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8; 552 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8;
553 } else 553 } else
554 { 554 {
555 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S; 555 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S;
556 } 556 }
557 dwMemPos += ReadSample(&Ins[iSmp], flags, (LPSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos); 557 dwMemPos += ReadSample(&Ins[iSmp], flags, (LPSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos);
558 } 558 }
559 return TRUE; 559 return TRUE;
560} 560}
561 561
562 562
563///////////////////////////////////////////////////////////////////// 563/////////////////////////////////////////////////////////////////////
564// AMS Sample unpacking 564// AMS Sample unpacking
565 565
566void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char packcharacter) 566void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char packcharacter)
567{ 567{
568 UINT tmplen = dmax; 568 UINT tmplen = dmax;
569 signed char *amstmp = new signed char[tmplen]; 569 signed char *amstmp = new signed char[tmplen];
570 570
571 if (!amstmp) return; 571 if (!amstmp) return;
572 // Unpack Loop 572 // Unpack Loop
573 { 573 {
574 signed char *p = amstmp; 574 signed char *p = amstmp;
575 UINT i=0, j=0; 575 UINT i=0, j=0;
576 while ((i < inputlen) && (j < tmplen)) 576 while ((i < inputlen) && (j < tmplen))
577 { 577 {
578 signed char ch = psrc[i++]; 578 signed char ch = psrc[i++];
579 if (ch == packcharacter) 579 if (ch == packcharacter)
580 { 580 {
581 BYTE ch2 = psrc[i++]; 581 BYTE ch2 = psrc[i++];
582 if (ch2) 582 if (ch2)
583 { 583 {
584 ch = psrc[i++]; 584 ch = psrc[i++];
585 while (ch2--) 585 while (ch2--)
586 { 586 {
587 p[j++] = ch; 587 p[j++] = ch;
588 if (j >= tmplen) break; 588 if (j >= tmplen) break;
589 } 589 }
590 } else p[j++] = packcharacter; 590 } else p[j++] = packcharacter;
591 } else p[j++] = ch; 591 } else p[j++] = ch;
592 } 592 }
593 } 593 }
594 // Bit Unpack Loop 594 // Bit Unpack Loop
595 { 595 {
596 signed char *p = amstmp; 596 signed char *p = amstmp;
597 UINT bitcount = 0x80, dh; 597 UINT bitcount = 0x80, dh;
598 UINT k=0; 598 UINT k=0;
599 for (UINT i=0; i<dmax; i++) 599 for (UINT i=0; i<dmax; i++)
600 { 600 {
601 BYTE al = *p++; 601 BYTE al = *p++;
602 dh = 0; 602 dh = 0;
603 for (UINT count=0; count<8; count++) 603 for (UINT count=0; count<8; count++)
604 { 604 {
605 UINT bl = al & bitcount; 605 UINT bl = al & bitcount;
606 bl = ((bl|(bl<<8)) >> ((dh+8-count) & 7)) & 0xFF; 606 bl = ((bl|(bl<<8)) >> ((dh+8-count) & 7)) & 0xFF;
607 bitcount = ((bitcount|(bitcount<<8)) >> 1) & 0xFF; 607 bitcount = ((bitcount|(bitcount<<8)) >> 1) & 0xFF;
608 pdest[k++] |= bl; 608 pdest[k++] |= bl;
609 if (k >= dmax) 609 if (k >= dmax)
610 { 610 {
611 k = 0; 611 k = 0;
612 dh++; 612 dh++;
613 } 613 }
614 } 614 }
615 bitcount = ((bitcount|(bitcount<<8)) >> dh) & 0xFF; 615 bitcount = ((bitcount|(bitcount<<8)) >> dh) & 0xFF;
616 } 616 }
617 } 617 }
618 // Delta Unpack 618 // Delta Unpack
619 { 619 {
620 signed char old = 0; 620 signed char old = 0;
621 for (UINT i=0; i<dmax; i++) 621 for (UINT i=0; i<dmax; i++)
622 { 622 {
623 int pos = ((LPBYTE)pdest)[i]; 623 int pos = ((LPBYTE)pdest)[i];
624 if ((pos != 128) && (pos & 0x80)) pos = -(pos & 0x7F); 624 if ((pos != 128) && (pos & 0x80)) pos = -(pos & 0x7F);
625 old -= (signed char)pos; 625 old -= (signed char)pos;
626 pdest[i] = old; 626 pdest[i] = old;
627 } 627 }
628 } 628 }
629 delete amstmp; 629 delete [] amstmp;
630} 630}
631 631