(data: Uint8Array, audioSpecificConfig: AacAudioSpecificConfig)
| 1565 | }; |
| 1566 | |
| 1567 | export const aacToAdts = (data: Uint8Array, audioSpecificConfig: AacAudioSpecificConfig) => { |
| 1568 | const { objectType, frequencyIndex, channelConfiguration } = audioSpecificConfig; |
| 1569 | const profile = objectType - 1; |
| 1570 | |
| 1571 | const header = new Uint8Array(7); |
| 1572 | const headerBitstream = new Bitstream(header); |
| 1573 | |
| 1574 | headerBitstream.writeBits(12, 0b1111_11111111); // Syncword |
| 1575 | headerBitstream.writeBits(1, 0); // MPEG Version |
| 1576 | headerBitstream.writeBits(2, 0); // Layer |
| 1577 | headerBitstream.writeBits(1, 1); // Protection absence |
| 1578 | headerBitstream.writeBits(2, profile); // Profile |
| 1579 | headerBitstream.writeBits(4, frequencyIndex); // MPEG-4 Sampling Frequency Index |
| 1580 | headerBitstream.writeBits(1, 0); // Private bit |
| 1581 | headerBitstream.writeBits(3, channelConfiguration); // MPEG-4 Channel Configuration |
| 1582 | headerBitstream.writeBits(1, 0); // Originality |
| 1583 | headerBitstream.writeBits(1, 0); // Home |
| 1584 | headerBitstream.writeBits(1, 0); // Copyright ID bit |
| 1585 | headerBitstream.writeBits(1, 0); // Copyright ID start |
| 1586 | headerBitstream.skipBits(13); // Frame length |
| 1587 | headerBitstream.writeBits(11, 0x7ff); // Buffer fullness |
| 1588 | headerBitstream.writeBits(2, 0); // Number of AAC frames minus 1 |
| 1589 | // Omit CRC check |
| 1590 | |
| 1591 | const frameLength = data.byteLength + header.byteLength; |
| 1592 | headerBitstream.pos = 30; |
| 1593 | headerBitstream.writeBits(13, frameLength); |
| 1594 | |
| 1595 | const final = new Uint8Array(header.byteLength + data.byteLength); |
| 1596 | final.set(header, 0); |
| 1597 | final.set(data, header.byteLength); |
| 1598 | |
| 1599 | return final; |
| 1600 | }; |
no test coverage detected