carta1 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carta1",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "An ATRAC1 audio codec implementation in JavaScript",
5
5
  "type": "module",
6
6
  "main": "codec/index.js",
@@ -1,108 +0,0 @@
1
- /**
2
- * Carta1 Audio Codec - Quadrature Mirror Filter
3
- *
4
- * This module implements QMF analysis and synthesis for subband decomposition
5
- * in the ATRAC1 codec. The QMF splits the audio signal into multiple frequency
6
- * bands for independent processing and coding.
7
- */
8
-
9
- import { QMF_DELAY } from '../core/constants.js'
10
- import { QMF_EVEN, QMF_ODD } from '../core/tables.js'
11
- import { throwError } from '../utils.js'
12
-
13
- /**
14
- * Perform QMF analysis filtering to split input into low and high frequency bands
15
- * @param {Float32Array} input - Input audio samples
16
- * @param {Float32Array} delayLine - QMF delay line state
17
- * @param {Object} qmfWorkBuffers - Optional work buffers for processing
18
- * @returns {Object} Object containing lowBand, highBand, and newDelay
19
- */
20
- export function analyzeQmfPair(input, delayLine, qmfWorkBuffers = null) {
21
- const inputLength = input.length
22
- const outputLength = inputLength >> 1
23
-
24
- const workBuffer =
25
- qmfWorkBuffers?.delay?.[inputLength] ??
26
- throwError(
27
- `analyzeQmfPair: qmfWorkBuffers.delay[${inputLength}] is required`
28
- )
29
- workBuffer.set(delayLine)
30
- workBuffer.set(input, delayLine.length)
31
-
32
- const lowBand = new Float32Array(outputLength)
33
- const highBand = new Float32Array(outputLength)
34
-
35
- for (let i = 0; i < outputLength; i++) {
36
- let evenSum = 0
37
- let oddSum = 0
38
- const offset = i * 2
39
-
40
- // Unrolled convolution
41
- for (let j = 0; j < 24; j++) {
42
- evenSum += workBuffer[offset + 47 - j * 2] * QMF_EVEN[j]
43
- oddSum += workBuffer[offset + 46 - j * 2] * QMF_ODD[j]
44
- }
45
-
46
- lowBand[i] = evenSum + oddSum
47
- highBand[i] = evenSum - oddSum
48
- }
49
-
50
- // Update delay line
51
- const newDelay = workBuffer.slice(-QMF_DELAY)
52
- return { lowBand, highBand, newDelay }
53
- }
54
-
55
- /**
56
- * Perform QMF synthesis filtering to reconstruct audio from low and high frequency bands
57
- * @param {Float32Array} lowBand - Low frequency band samples
58
- * @param {Float32Array} highBand - High frequency band samples
59
- * @param {Float32Array} delayLine - QMF delay line state
60
- * @param {Object} qmfWorkBuffers - Optional work buffers for processing
61
- * @returns {Object} Object containing output and newDelay
62
- */
63
- export function synthesizeQmfPair(
64
- lowBand,
65
- highBand,
66
- delayLine,
67
- qmfWorkBuffers = null
68
- ) {
69
- const subbandLength = lowBand.length
70
- const outputLength = subbandLength * 2
71
-
72
- const workBuffer =
73
- qmfWorkBuffers?.delay?.[outputLength] ??
74
- throwError(
75
- `synthesizeQmfPair: qmfWorkBuffers.delay[${outputLength}] is required`
76
- )
77
- workBuffer.set(delayLine)
78
-
79
- // Upsample and merge
80
- for (let i = 0; i < subbandLength; i++) {
81
- const low = lowBand[i]
82
- const high = highBand[i]
83
- const offset = QMF_DELAY + i * 2
84
- workBuffer[offset] = 0.5 * (low + high)
85
- workBuffer[offset + 1] = 0.5 * (low - high)
86
- }
87
-
88
- const output = new Float32Array(outputLength)
89
-
90
- // Convolution
91
- for (let i = 0; i < subbandLength; i++) {
92
- const offset = i * 2
93
- let sample0 = 0
94
- let sample1 = 0
95
-
96
- for (let j = 0; j < 24; j++) {
97
- const idx = offset + j * 2
98
- sample0 += workBuffer[idx] * QMF_EVEN[j]
99
- sample1 += workBuffer[idx + 1] * QMF_ODD[j]
100
- }
101
-
102
- output[i * 2] = sample1
103
- output[i * 2 + 1] = sample0
104
- }
105
-
106
- const newDelay = workBuffer.slice(-QMF_DELAY)
107
- return { output, newDelay }
108
- }