Changeset 78 for mppenc/branches/r2d/src/mppenc.c
- Timestamp:
- 10/27/06 18:42:05 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/src/mppenc.c
r77 r78 1408 1408 1409 1409 1410 void OverdriveReport ( mpc_encoder_t * e )1410 static void OverdriveReport ( mpc_encoder_t * e ) 1411 1411 { 1412 1412 if ( e->Overflows > 0 ) { // report internal clippings … … 1432 1432 #include <fpu_control.h> 1433 1433 1434 void Init_FPU ( void )1434 static void Init_FPU ( void ) 1435 1435 { 1436 1436 mpc_uint16_t cw; … … 1457 1457 } 1458 1458 1459 static FILE * OpenStream(char * OutputName) 1460 { 1461 FILE * OutputFile = NULL; 1462 1463 /* open bitstream file */ 1464 if ( 0 == strcmp ( OutputName, "/dev/null") ) 1465 OutputFile = fopen (DEV_NULL, "wb"); 1466 else if ( 0 == strcmp ( OutputName, "-") || 0 == strcmp ( OutputName, "/dev/stdout") ) 1467 OutputFile = SETBINARY_OUT (stdout); 1468 else 1469 switch ( WriteMode ) { 1470 default: 1471 stderr_printf ( "\033[33;41;1mERROR\033[0m: Invalid Write mode, internal error\n" ); 1472 exit(1); 1473 case MODE_NEVER_OVERWRITE: 1474 OutputFile = fopen ( OutputName, "rb" ); 1475 if ( OutputFile != NULL ) { 1476 fclose ( OutputFile ); 1477 stderr_printf ( "\033[33;41;1mERROR\033[0m: Output file '%s' already exists\n", OutputName ); 1478 exit(1); 1479 } 1480 OutputFile = fopen ( OutputName, "w+b" ); 1481 break; 1482 case MODE_OVERWRITE: 1483 OutputFile = fopen ( OutputName, "w+b" ); 1484 break; 1485 case MODE_ASK_FOR_OVERWRITE: 1486 OutputFile = fopen ( OutputName, "rb" ); 1487 if ( OutputFile != NULL ) { 1488 char c; 1489 fclose ( OutputFile ); 1490 stderr_printf ( "\nmppenc: Output file '%s' already exists, overwrite (Y/n)? ", OutputName ); 1491 c = waitkey (); 1492 if ( c != 'Y' && c != 'y' ) { 1493 stderr_printf ( "No!!!\n\n*** Canceled overwrite ***\n" ); 1494 exit(1); 1495 } 1496 stderr_printf ( " YES\n" ); 1497 } 1498 OutputFile = fopen ( OutputName, "w+b" ); 1499 break; 1500 } 1501 1502 if ( OutputFile == NULL ) { 1503 stderr_printf ( "\033[33;41;1mERROR\033[0m: Could not create output file '%s'\n", OutputName ); 1504 exit(1); 1505 } 1506 return OutputFile; 1507 } 1508 1459 1509 static int 1460 1510 mainloop ( int argc, char** argv ) … … 1468 1518 unsigned int CurrentRead = 0; // current read Samples per channel 1469 1519 unsigned int N; // counter for processed frames 1470 unsigned int LastValidSamples = 0; // number of valid samples for the last frame1471 unsigned int LastValidFrame = 0; // overall number of frames1472 1520 char* InputName = NULL; // Name of WAVE file 1473 1521 char* OutputName = NULL; // Name of bitstream file 1474 FILE* OutputFile = NULL; // Filepointer to output file1475 1522 int Silence = 0; 1476 1523 int OldSilence = 0; 1477 1524 time_t T; 1478 UintMax_t OldBufferedBits;1479 BitstreamPos bitstreampos;1480 1525 int TransientL [PART_SHORT]; // Flag of transient detection 1481 1526 int TransientR [PART_SHORT]; // Flag of transient detection … … 1491 1536 Init_Psychoakustik (&m); 1492 1537 Init_FPU (); 1493 Init_SV 7(&e);1538 Init_SV8 (&e); 1494 1539 1495 1540 // initialize PCM-data … … 1556 1601 } 1557 1602 1558 /* open bitstream file */ 1559 if ( 0 == strcmp ( OutputName, "/dev/null") ) { 1560 OutputFile = fopen (DEV_NULL, "wb"); 1561 } 1562 else if ( 0 == strcmp ( OutputName, "-") || 0 == strcmp ( OutputName, "/dev/stdout") ) { 1563 OutputFile = SETBINARY_OUT (stdout); 1564 } 1565 else 1566 switch ( WriteMode ) { 1567 default: 1568 stderr_printf ( "\033[33;41;1mERROR\033[0m: Invalid Write mode, internal error\n" ); 1569 return 1; 1570 case MODE_NEVER_OVERWRITE: 1571 OutputFile = fopen ( OutputName, "rb" ); 1572 if ( OutputFile != NULL ) { 1573 fclose ( OutputFile ); 1574 stderr_printf ( "\033[33;41;1mERROR\033[0m: Output file '%s' already exists\n", OutputName ); 1575 return 1; 1576 } 1577 OutputFile = fopen ( OutputName, "w+b" ); 1578 break; 1579 case MODE_OVERWRITE: 1580 OutputFile = fopen ( OutputName, "w+b" ); 1581 break; 1582 case MODE_ASK_FOR_OVERWRITE: 1583 OutputFile = fopen ( OutputName, "rb" ); 1584 if ( OutputFile != NULL ) { 1585 char c; 1586 fclose ( OutputFile ); 1587 stderr_printf ( "\nmppenc: Output file '%s' already exists, overwrite (Y/n)? ", OutputName ); 1588 c = waitkey (); 1589 if ( c != 'Y' && c != 'y' ) { 1590 stderr_printf ( "No!!!\n\n*** Canceled overwrite ***\n" ); 1591 return 1; 1592 } 1593 stderr_printf ( " YES\n" ); 1594 } 1595 OutputFile = fopen ( OutputName, "w+b" ); 1596 break; 1597 } 1598 1599 if ( OutputFile == NULL ) { 1600 stderr_printf ( "\033[33;41;1mERROR\033[0m: Could not create output file '%s'\n", OutputName ); 1601 return 1; 1602 } 1603 1604 #ifndef IO_BUFFERING 1605 setvbuf ( OutputFile, NULL, _IONBF, 0 ); 1606 #endif 1603 e.outputFile = OpenStream(OutputName); 1607 1604 1608 1605 ShowParameters (&m, InputName, OutputName ); … … 1624 1621 1625 1622 e.MS_Channelmode = m.MS_Channelmode; 1626 e.BufferedBits = 0; 1627 LastValidFrame = (SamplesInWAVE + BLOCK - 1) / BLOCK; 1628 LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1; 1629 WriteHeader_SV7 ( &e, m.Max_Band, m.MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, m.PNS > 0 ? 0x17 : 0x07, m.SampleFreq ); 1623 // e.BufferedBits = 0; 1624 writeMagic(&e); 1625 WriteHeader_SV8 ( &e, m.Max_Band, m.MS_Channelmode > 0, SamplesInWAVE, 1626 0x08, m.PNS > 0, m.SampleFreq, 1627 Wave.Channels > 2 ? 2 : Wave.Channels); 1628 writeBlock(&e, "SI", TRUE); 1630 1629 1631 1630 1632 1631 // initialize timer 1633 ShowProgress (&m, 0, SamplesInWAVE, e. BufferedBits );1632 ShowProgress (&m, 0, SamplesInWAVE, e.outputBits ); 1634 1633 T = time ( NULL ); 1635 1634 … … 1653 1652 UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq ); 1654 1653 SamplesInWAVE = AllSamplesRead; 1655 1656 // in the case of a broken wav-header, recalculate the overall frames1657 // and the valid samples for the last frame1658 LastValidFrame = (SamplesInWAVE + BLOCK - 1) / BLOCK;1659 LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1;1660 // fprintf ( stderr, "\nKorrupt WAV file in Frame %d: NEU!: Frames: %u, last valid: %u\n", -1, LastValidFrame, LastValidSamples );1661 1654 } 1662 1655 … … 1708 1701 } 1709 1702 1710 if ( e.Zaehler >= BUFFER_ALMOST_FULL || LowDelay ) {1711 FlushBitstream ( OutputFile, e.Buffer, e.Zaehler );1712 e.Zaehler = 0;1713 }1714 1715 1703 OldSilence = Silence; 1716 OldBufferedBits = e.BufferedBits;1717 GetBitstreamPos ( &e, &bitstreampos );1718 WriteBits ( &e, 0, 20 ); // Reserve 20 bits for jump-information1719 1704 WriteBitstream_SV7 ( &e, m.Max_Band, Q ); // write SV7-Bitstream 1720 WriteBitsAt ( &e, (Uint32_t)(e.BufferedBits - OldBufferedBits - 20), 20, bitstreampos ); // Patch 20 bits for jump-information to the right value1721 1705 1722 1706 if ( (Int)(time (NULL) - T) >= 0 ) { // output 1723 1707 T += labs (DisplayUpdateTime); 1724 ShowProgress (&m, (UintMax_t)(N+1) * BLOCK, SamplesInWAVE, e.BufferedBits );1708 ShowProgress (&m, (UintMax_t)(N+1) * BLOCK, SamplesInWAVE, e.outputBits ); 1725 1709 } 1726 1710 … … 1742 1726 UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq ); 1743 1727 SamplesInWAVE = AllSamplesRead; 1744 1745 // in the case of broken wav-header, recalculate the overall frames 1746 // and the valid samples for the last frame 1747 LastValidFrame = (SamplesInWAVE + BLOCK - 1) / BLOCK; 1748 LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1; 1749 // fprintf ( stderr, "\nKorrupt WAV file in Frame %d: NEU!: Frames: %u, last valid: %u\n", N, LastValidFrame, LastValidSamples ); 1750 } 1751 1752 if ( N == LastValidFrame - 1 ) { 1753 WriteBits ( &e, LastValidSamples, 11 ); 1754 // fprintf ( stderr, "\nGltige Samples im letzten Frame: %4u \n", LastValidSamples ); 1755 } 1756 if ( N >= LastValidFrame ) { 1757 // fprintf ( stderr, "Zusï¿œzlicher Frame %u (von %u) angehï¿œgt. \n", N, LastValidFrame ); 1758 } 1759 1760 } 1761 1762 // write the last incomplete word to buffer, so it's written during the next flush 1763 FinishBitstream(&e); 1764 ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.BufferedBits ); 1765 1766 FlushBitstream ( OutputFile, e.Buffer, e.Zaehler ); 1767 e.Zaehler = 0; 1768 1769 UpdateHeader ( OutputFile, LastValidFrame, LastValidSamples ); 1728 } 1729 } 1730 1731 // write the last incomplete block 1732 writeBlock(&e, "AD", FALSE); 1733 ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.outputBits ); 1770 1734 1771 1735 if(EnableTags) 1772 FinalizeTags ( OutputFile, APE_Version );1773 fclose ( OutputFile );1736 FinalizeTags ( e.outputFile, APE_Version ); 1737 fclose ( e.outputFile ); 1774 1738 fclose ( Wave.fp ); 1775 1739
Note: See TracChangeset
for help on using the changeset viewer.