@siteed/audio-studio 3.2.0-beta.1 → 3.2.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/CHANGELOG.md +356 -5
- package/android/src/main/java/net/siteed/audiostudio/AudioStreamDecoder.kt +306 -94
- package/android/src/main/java/net/siteed/audiostudio/AudioStudioModule.kt +39 -6
- package/build/cjs/errors/AudioStreamError.js +9 -0
- package/build/cjs/errors/AudioStreamError.js.map +1 -1
- package/build/cjs/errors/AudioStreamError.test.js +22 -1
- package/build/cjs/errors/AudioStreamError.test.js.map +1 -1
- package/build/cjs/streamAudioData.js +99 -32
- package/build/cjs/streamAudioData.js.map +1 -1
- package/build/cjs/utils/audioProcessing.js +14 -10
- package/build/cjs/utils/audioProcessing.js.map +1 -1
- package/build/esm/errors/AudioStreamError.js +9 -0
- package/build/esm/errors/AudioStreamError.js.map +1 -1
- package/build/esm/errors/AudioStreamError.test.js +22 -1
- package/build/esm/errors/AudioStreamError.test.js.map +1 -1
- package/build/esm/streamAudioData.js +99 -32
- package/build/esm/streamAudioData.js.map +1 -1
- package/build/esm/utils/audioProcessing.js +14 -10
- package/build/esm/utils/audioProcessing.js.map +1 -1
- package/build/types/errors/AudioStreamError.d.ts.map +1 -1
- package/build/types/streamAudioData.d.ts +5 -0
- package/build/types/streamAudioData.d.ts.map +1 -1
- package/build/types/utils/audioProcessing.d.ts +2 -2
- package/build/types/utils/audioProcessing.d.ts.map +1 -1
- package/ios/AudioStreamDecoder.swift +191 -100
- package/ios/AudioStudioModule.swift +48 -9
- package/package.json +163 -146
- package/scripts/README.md +58 -0
- package/src/errors/AudioStreamError.test.ts +29 -2
- package/src/errors/AudioStreamError.ts +14 -0
- package/src/streamAudioData.ts +146 -42
- package/src/utils/audioProcessing.ts +25 -14
- package/android/src/androidTest/assets/chorus.wav +0 -0
- package/android/src/androidTest/assets/jfk.wav +0 -0
- package/android/src/androidTest/assets/osr_us_000_0010_8k.wav +0 -0
- package/android/src/androidTest/assets/recorder_hello_world.wav +0 -0
- package/android/src/androidTest/java/net/siteed/audiostudio/AudioFinalMetadataContractInstrumentedTest.kt +0 -190
- package/android/src/androidTest/java/net/siteed/audiostudio/AudioProcessorInstrumentedTest.kt +0 -197
- package/android/src/androidTest/java/net/siteed/audiostudio/AudioRecorderInstrumentedTest.kt +0 -487
- package/android/src/androidTest/java/net/siteed/audiostudio/AudioRecorderPerformanceInstrumentedTest.kt +0 -250
- package/android/src/androidTest/java/net/siteed/audiostudio/OpusRangeDecodeRegressionInstrumentedTest.kt +0 -186
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/AudioFocusStrategyIntegrationTest.kt +0 -332
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/BufferDurationIntegrationTest.kt +0 -324
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/CompressedOnlyOutputTest.kt +0 -253
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/DeviceDisconnectionFallbackTest.kt +0 -218
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/EventEmissionIntervalTest.kt +0 -120
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/M4aFormatTest.kt +0 -345
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/OutputControlIntegrationTest.kt +0 -340
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/PcmStreamingDurationTest.kt +0 -252
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/README.md +0 -95
- package/android/src/androidTest/java/net/siteed/audiostudio/integration/run_integration_tests.sh +0 -43
- package/android/src/test/java/net/siteed/audiostudio/AndroidCallStateTest.kt +0 -37
- package/android/src/test/java/net/siteed/audiostudio/AndroidEventEmitterTest.kt +0 -28
- package/android/src/test/java/net/siteed/audiostudio/AudioFileHandlerTest.kt +0 -279
- package/android/src/test/java/net/siteed/audiostudio/AudioFocusStrategyTest.kt +0 -249
- package/android/src/test/java/net/siteed/audiostudio/AudioFormatTest.kt +0 -151
- package/android/src/test/java/net/siteed/audiostudio/AudioFormatUtilsTest.kt +0 -273
- package/android/src/test/java/net/siteed/audiostudio/DeviceDisconnectionFallbackUnitTest.kt +0 -140
- package/android/src/test/java/net/siteed/audiostudio/InterruptionAutoResumePolicyTest.kt +0 -49
- package/android/src/test/resources/chorus.wav +0 -0
- package/android/src/test/resources/generate_test_audio.py +0 -94
- package/android/src/test/resources/jfk.wav +0 -0
- package/android/src/test/resources/osr_us_000_0010_8k.wav +0 -0
- package/android/src/test/resources/recorder_hello_world.wav +0 -0
- package/ios/AudioStudioTests/AudioFileHandlerTests.swift +0 -338
- package/ios/AudioStudioTests/AudioFormatUtilsTests.swift +0 -331
- package/ios/AudioStudioTests/AudioStreamDecoderTests.swift +0 -128
- package/ios/AudioStudioTests/AudioTestHelpers.swift +0 -130
- package/ios/AudioStudioTests/CompressedOnlyOutputTests.swift +0 -334
- package/ios/AudioStudioTests/EventEmissionIntervalTests.swift +0 -105
- package/ios/AudioStudioTests/Info.plist +0 -22
- package/ios/AudioStudioTests/README.md +0 -39
- package/ios/AudioStudioTests/SimpleAudioTest.swift +0 -98
- package/ios/AudioStudioTests/TestAudioGenerator.swift +0 -75
- package/ios/tests/README.md +0 -41
- package/ios/tests/integration/buffer_and_fallback_test.swift +0 -178
- package/ios/tests/integration/buffer_duration_test.swift +0 -185
- package/ios/tests/integration/compressed_only_output_test.swift +0 -271
- package/ios/tests/integration/output_control_test.swift +0 -322
- package/ios/tests/integration/run_integration_tests.sh +0 -37
- package/ios/tests/opus_support_test_macos.swift +0 -154
- package/ios/tests/standalone/audio_processing_test.swift +0 -144
- package/ios/tests/standalone/audio_recording_test.swift +0 -277
- package/ios/tests/standalone/audio_streaming_test.swift +0 -249
- package/ios/tests/standalone/standalone_test.swift +0 -144
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
package net.siteed.audiostudio
|
|
2
|
-
|
|
3
|
-
import org.junit.Test
|
|
4
|
-
import org.junit.Assert.*
|
|
5
|
-
import java.nio.ByteBuffer
|
|
6
|
-
import java.nio.ByteOrder
|
|
7
|
-
import kotlin.math.abs
|
|
8
|
-
|
|
9
|
-
class AudioFormatUtilsTest {
|
|
10
|
-
|
|
11
|
-
@Test
|
|
12
|
-
fun testConvertBitDepth_8to16() {
|
|
13
|
-
// Given - 8-bit PCM data (unsigned, centered at 128)
|
|
14
|
-
val input8bit = byteArrayOf(0, 64, 128.toByte(), 192.toByte(), 255.toByte())
|
|
15
|
-
|
|
16
|
-
// When
|
|
17
|
-
val output16bit = AudioFormatUtils.convertBitDepth(input8bit, 8, 16)
|
|
18
|
-
|
|
19
|
-
// Then
|
|
20
|
-
val buffer = ByteBuffer.wrap(output16bit).order(ByteOrder.LITTLE_ENDIAN)
|
|
21
|
-
val samples = ShortArray(output16bit.size / 2)
|
|
22
|
-
buffer.asShortBuffer().get(samples)
|
|
23
|
-
|
|
24
|
-
// Verify conversion (8-bit 128 = silence = 16-bit 0)
|
|
25
|
-
assertEquals("First sample should be -32768", -32768, samples[0].toInt())
|
|
26
|
-
assertEquals("Middle sample (128) should be 0", 0, samples[2].toInt())
|
|
27
|
-
assertEquals("Last sample should be 32767", 32767, samples[4].toInt())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Test
|
|
31
|
-
fun testConvertBitDepth_16to8() {
|
|
32
|
-
// Given - 16-bit PCM data
|
|
33
|
-
val buffer16 = ByteBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN)
|
|
34
|
-
buffer16.putShort(-32768) // Min value
|
|
35
|
-
buffer16.putShort(-16384) // -0.5
|
|
36
|
-
buffer16.putShort(0) // Silence
|
|
37
|
-
buffer16.putShort(16384) // 0.5
|
|
38
|
-
buffer16.putShort(32767) // Max value
|
|
39
|
-
|
|
40
|
-
// When
|
|
41
|
-
val output8bit = AudioFormatUtils.convertBitDepth(buffer16.array(), 16, 8)
|
|
42
|
-
|
|
43
|
-
// Then
|
|
44
|
-
assertEquals("Should have 5 samples", 5, output8bit.size)
|
|
45
|
-
assertEquals("Min should convert to 0", 0, output8bit[0].toInt() and 0xFF)
|
|
46
|
-
assertEquals("Silence should convert to 128", 128, output8bit[2].toInt() and 0xFF)
|
|
47
|
-
assertEquals("Max should convert to 255", 255, output8bit[4].toInt() and 0xFF)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Test
|
|
51
|
-
fun testConvertBitDepth_16to32() {
|
|
52
|
-
// Given - 16-bit PCM data
|
|
53
|
-
val buffer16 = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN)
|
|
54
|
-
buffer16.putShort(-32768) // Min
|
|
55
|
-
buffer16.putShort(0) // Silence
|
|
56
|
-
buffer16.putShort(32767) // Max
|
|
57
|
-
|
|
58
|
-
// When
|
|
59
|
-
val output32bit = AudioFormatUtils.convertBitDepth(buffer16.array(), 16, 32)
|
|
60
|
-
|
|
61
|
-
// Then
|
|
62
|
-
val buffer32 = ByteBuffer.wrap(output32bit).order(ByteOrder.LITTLE_ENDIAN)
|
|
63
|
-
assertEquals("Should have 3 32-bit samples", 12, output32bit.size)
|
|
64
|
-
|
|
65
|
-
// Check values (scaled appropriately)
|
|
66
|
-
val sample1 = buffer32.getInt()
|
|
67
|
-
val sample2 = buffer32.getInt()
|
|
68
|
-
val sample3 = buffer32.getInt()
|
|
69
|
-
|
|
70
|
-
assertTrue("Min value should be negative", sample1 < 0)
|
|
71
|
-
assertEquals("Silence should be 0", 0, sample2)
|
|
72
|
-
assertTrue("Max value should be positive", sample3 > 0)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Test
|
|
76
|
-
fun testConvertBitDepth_32to16() {
|
|
77
|
-
// Given - 32-bit PCM data
|
|
78
|
-
val buffer32 = ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN)
|
|
79
|
-
buffer32.putInt(Int.MIN_VALUE) // Min
|
|
80
|
-
buffer32.putInt(0) // Silence
|
|
81
|
-
buffer32.putInt(Int.MAX_VALUE) // Max
|
|
82
|
-
|
|
83
|
-
// When
|
|
84
|
-
val output16bit = AudioFormatUtils.convertBitDepth(buffer32.array(), 32, 16)
|
|
85
|
-
|
|
86
|
-
// Then
|
|
87
|
-
val buffer16 = ByteBuffer.wrap(output16bit).order(ByteOrder.LITTLE_ENDIAN)
|
|
88
|
-
assertEquals("Should have 3 16-bit samples", 6, output16bit.size)
|
|
89
|
-
|
|
90
|
-
assertEquals("Min should convert to -32768", -32768, buffer16.getShort().toInt())
|
|
91
|
-
assertEquals("Silence should be 0", 0, buffer16.getShort().toInt())
|
|
92
|
-
assertEquals("Max should convert to 32767", 32767, buffer16.getShort().toInt())
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@Test
|
|
96
|
-
fun testConvertBitDepth_sameDepth() {
|
|
97
|
-
// Given
|
|
98
|
-
val input = byteArrayOf(1, 2, 3, 4, 5, 6)
|
|
99
|
-
|
|
100
|
-
// When - Convert 16 to 16 (no-op)
|
|
101
|
-
val output = AudioFormatUtils.convertBitDepth(input, 16, 16)
|
|
102
|
-
|
|
103
|
-
// Then
|
|
104
|
-
assertArrayEquals("Should return same data", input, output)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@Test
|
|
108
|
-
fun testConvertBitDepth_emptyData() {
|
|
109
|
-
// Given
|
|
110
|
-
val emptyData = byteArrayOf()
|
|
111
|
-
|
|
112
|
-
// When
|
|
113
|
-
val output = AudioFormatUtils.convertBitDepth(emptyData, 16, 32)
|
|
114
|
-
|
|
115
|
-
// Then
|
|
116
|
-
assertEquals("Should return empty array", 0, output.size)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Test
|
|
120
|
-
fun testConvertChannels_monoToStereo() {
|
|
121
|
-
// Given - Mono 16-bit data
|
|
122
|
-
val monoData = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
123
|
-
putShort(1000)
|
|
124
|
-
putShort(2000)
|
|
125
|
-
putShort(3000)
|
|
126
|
-
}.array()
|
|
127
|
-
|
|
128
|
-
// When
|
|
129
|
-
val stereoData = AudioFormatUtils.convertChannels(monoData, 1, 2, 16)
|
|
130
|
-
|
|
131
|
-
// Then
|
|
132
|
-
val buffer = ByteBuffer.wrap(stereoData).order(ByteOrder.LITTLE_ENDIAN)
|
|
133
|
-
assertEquals("Should have 6 samples (3 stereo pairs)", 12, stereoData.size)
|
|
134
|
-
|
|
135
|
-
// Each mono sample should be duplicated to both channels
|
|
136
|
-
assertEquals("L1", 1000, buffer.getShort().toInt())
|
|
137
|
-
assertEquals("R1", 1000, buffer.getShort().toInt())
|
|
138
|
-
assertEquals("L2", 2000, buffer.getShort().toInt())
|
|
139
|
-
assertEquals("R2", 2000, buffer.getShort().toInt())
|
|
140
|
-
assertEquals("L3", 3000, buffer.getShort().toInt())
|
|
141
|
-
assertEquals("R3", 3000, buffer.getShort().toInt())
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@Test
|
|
145
|
-
fun testConvertChannels_stereoToMono() {
|
|
146
|
-
// Given - Stereo 16-bit data
|
|
147
|
-
val stereoData = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
148
|
-
putShort(1000) // L1
|
|
149
|
-
putShort(2000) // R1
|
|
150
|
-
putShort(3000) // L2
|
|
151
|
-
putShort(4000) // R2
|
|
152
|
-
}.array()
|
|
153
|
-
|
|
154
|
-
// When
|
|
155
|
-
val monoData = AudioFormatUtils.convertChannels(stereoData, 2, 1, 16)
|
|
156
|
-
|
|
157
|
-
// Then
|
|
158
|
-
val buffer = ByteBuffer.wrap(monoData).order(ByteOrder.LITTLE_ENDIAN)
|
|
159
|
-
assertEquals("Should have 2 mono samples", 4, monoData.size)
|
|
160
|
-
|
|
161
|
-
// Each mono sample should be average of L+R
|
|
162
|
-
assertEquals("Sample 1", 1500, buffer.getShort().toInt()) // (1000+2000)/2
|
|
163
|
-
assertEquals("Sample 2", 3500, buffer.getShort().toInt()) // (3000+4000)/2
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
@Test
|
|
167
|
-
fun testNormalizeAudio_quietSignal() {
|
|
168
|
-
// Given - Quiet 16-bit signal
|
|
169
|
-
val quietData = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
170
|
-
putShort(100)
|
|
171
|
-
putShort(-100)
|
|
172
|
-
putShort(50)
|
|
173
|
-
}.array()
|
|
174
|
-
|
|
175
|
-
// When
|
|
176
|
-
val normalized = AudioFormatUtils.normalizeAudio(quietData, 16)
|
|
177
|
-
|
|
178
|
-
// Then
|
|
179
|
-
val buffer = ByteBuffer.wrap(normalized).order(ByteOrder.LITTLE_ENDIAN)
|
|
180
|
-
val maxSample = abs(buffer.getShort().toInt())
|
|
181
|
-
buffer.rewind()
|
|
182
|
-
|
|
183
|
-
// The loudest sample should be close to max value
|
|
184
|
-
assertTrue("Should be normalized to near max", maxSample > 30000)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
@Test
|
|
188
|
-
fun testNormalizeAudio_alreadyLoud() {
|
|
189
|
-
// Given - Already loud signal
|
|
190
|
-
val loudData = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
191
|
-
putShort(32000)
|
|
192
|
-
putShort(-32000)
|
|
193
|
-
}.array()
|
|
194
|
-
|
|
195
|
-
// When
|
|
196
|
-
val normalized = AudioFormatUtils.normalizeAudio(loudData, 16)
|
|
197
|
-
|
|
198
|
-
// Then
|
|
199
|
-
val buffer = ByteBuffer.wrap(normalized).order(ByteOrder.LITTLE_ENDIAN)
|
|
200
|
-
val sample1 = abs(buffer.getShort().toInt())
|
|
201
|
-
val sample2 = abs(buffer.getShort().toInt())
|
|
202
|
-
|
|
203
|
-
// Should be normalized but not clipped
|
|
204
|
-
assertTrue("Samples should be near max", sample1 > 32000 && sample2 > 32000)
|
|
205
|
-
assertTrue("Samples should not exceed max", sample1 <= 32767 && sample2 <= 32767)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
@Test
|
|
209
|
-
fun testNormalizeAudio_silentSignal() {
|
|
210
|
-
// Given - Silent signal
|
|
211
|
-
val silentData = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
212
|
-
putShort(0)
|
|
213
|
-
putShort(0)
|
|
214
|
-
putShort(0)
|
|
215
|
-
}.array()
|
|
216
|
-
|
|
217
|
-
// When
|
|
218
|
-
val normalized = AudioFormatUtils.normalizeAudio(silentData, 16)
|
|
219
|
-
|
|
220
|
-
// Then
|
|
221
|
-
val buffer = ByteBuffer.wrap(normalized).order(ByteOrder.LITTLE_ENDIAN)
|
|
222
|
-
assertEquals("Silent should remain silent", 0, buffer.getShort().toInt())
|
|
223
|
-
assertEquals("Silent should remain silent", 0, buffer.getShort().toInt())
|
|
224
|
-
assertEquals("Silent should remain silent", 0, buffer.getShort().toInt())
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
@Test
|
|
228
|
-
fun testResampleAudio_upsample() {
|
|
229
|
-
// Given - 8kHz mono audio
|
|
230
|
-
val samples8k = floatArrayOf(0.0f, 0.5f, 1.0f, 0.5f, 0.0f, -0.5f, -1.0f, -0.5f)
|
|
231
|
-
|
|
232
|
-
// When - Upsample to 16kHz
|
|
233
|
-
val samples16k = AudioFormatUtils.resampleAudio(samples8k, 8000, 16000)
|
|
234
|
-
|
|
235
|
-
// Then
|
|
236
|
-
assertEquals("Should have approximately double samples", 16, samples16k.size)
|
|
237
|
-
// First and last samples should match
|
|
238
|
-
assertEquals("First sample", samples8k[0], samples16k[0], 0.01f)
|
|
239
|
-
assertEquals("Last sample", samples8k.last(), samples16k.last(), 0.01f)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
@Test
|
|
243
|
-
fun testResampleAudio_downsample() {
|
|
244
|
-
// Given - 16kHz mono audio
|
|
245
|
-
val samples16k = floatArrayOf(
|
|
246
|
-
0.0f, 0.25f, 0.5f, 0.75f, 1.0f, 0.75f, 0.5f, 0.25f,
|
|
247
|
-
0.0f, -0.25f, -0.5f, -0.75f, -1.0f, -0.75f, -0.5f, -0.25f
|
|
248
|
-
)
|
|
249
|
-
|
|
250
|
-
// When - Downsample to 8kHz
|
|
251
|
-
val samples8k = AudioFormatUtils.resampleAudio(samples16k, 16000, 8000)
|
|
252
|
-
|
|
253
|
-
// Then
|
|
254
|
-
assertEquals("Should have approximately half samples", 8, samples8k.size)
|
|
255
|
-
// Check general shape is preserved
|
|
256
|
-
val maxValue = samples8k.maxOrNull() ?: 0f
|
|
257
|
-
val minValue = samples8k.minOrNull() ?: 0f
|
|
258
|
-
assertTrue("Peak should be preserved", maxValue > 0.9f)
|
|
259
|
-
assertTrue("Trough should be preserved", minValue < -0.9f)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
@Test
|
|
263
|
-
fun testResampleAudio_sameRate() {
|
|
264
|
-
// Given
|
|
265
|
-
val samples = floatArrayOf(0.1f, 0.2f, 0.3f, 0.4f, 0.5f)
|
|
266
|
-
|
|
267
|
-
// When - Same sample rate
|
|
268
|
-
val resampled = AudioFormatUtils.resampleAudio(samples, 44100, 44100)
|
|
269
|
-
|
|
270
|
-
// Then
|
|
271
|
-
assertArrayEquals("Should return same samples", samples, resampled, 0.001f)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
package net.siteed.audiostudio
|
|
2
|
-
|
|
3
|
-
import org.junit.Assert.*
|
|
4
|
-
import org.junit.Test
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Unit test for Device Disconnection Fallback Behavior
|
|
8
|
-
*
|
|
9
|
-
* Tests the configuration and expected behavior for device disconnection scenarios.
|
|
10
|
-
*/
|
|
11
|
-
class DeviceDisconnectionFallbackUnitTest {
|
|
12
|
-
|
|
13
|
-
@Test
|
|
14
|
-
fun `test RecordingConfig stores deviceDisconnectionBehavior correctly`() {
|
|
15
|
-
// Test fallback behavior
|
|
16
|
-
val fallbackConfig = RecordingConfig(
|
|
17
|
-
sampleRate = 44100,
|
|
18
|
-
channels = 1,
|
|
19
|
-
encoding = "pcm_16bit",
|
|
20
|
-
deviceDisconnectionBehavior = "fallback"
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
assertEquals("Should store fallback behavior", "fallback", fallbackConfig.deviceDisconnectionBehavior)
|
|
24
|
-
|
|
25
|
-
// Test pause behavior
|
|
26
|
-
val pauseConfig = RecordingConfig(
|
|
27
|
-
sampleRate = 44100,
|
|
28
|
-
channels = 1,
|
|
29
|
-
encoding = "pcm_16bit",
|
|
30
|
-
deviceDisconnectionBehavior = "pause"
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
assertEquals("Should store pause behavior", "pause", pauseConfig.deviceDisconnectionBehavior)
|
|
34
|
-
|
|
35
|
-
// Test default behavior (should be null)
|
|
36
|
-
val defaultConfig = RecordingConfig(
|
|
37
|
-
sampleRate = 44100,
|
|
38
|
-
channels = 1,
|
|
39
|
-
encoding = "pcm_16bit"
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
assertNull("Default behavior should be null", defaultConfig.deviceDisconnectionBehavior)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Test
|
|
46
|
-
fun `test AudioRecorderManager stores deviceDisconnectionBehavior`() {
|
|
47
|
-
val config = RecordingConfig(
|
|
48
|
-
sampleRate = 44100,
|
|
49
|
-
channels = 1,
|
|
50
|
-
encoding = "pcm_16bit",
|
|
51
|
-
deviceDisconnectionBehavior = "fallback"
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
// Verify the config has the correct behavior
|
|
55
|
-
assertEquals("fallback", config.deviceDisconnectionBehavior)
|
|
56
|
-
|
|
57
|
-
// AudioRecorderManager should use this configuration
|
|
58
|
-
// The actual AudioRecorderManager.getDeviceDisconnectionBehavior()
|
|
59
|
-
// will return this value when recording is started with this config
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@Test
|
|
63
|
-
fun `test device disconnection behavior values`() {
|
|
64
|
-
val validBehaviors = listOf("fallback", "pause")
|
|
65
|
-
|
|
66
|
-
for (behavior in validBehaviors) {
|
|
67
|
-
val config = RecordingConfig(
|
|
68
|
-
sampleRate = 44100,
|
|
69
|
-
channels = 1,
|
|
70
|
-
encoding = "pcm_16bit",
|
|
71
|
-
deviceDisconnectionBehavior = behavior
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
assertEquals("Should accept $behavior behavior", behavior, config.deviceDisconnectionBehavior)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@Test
|
|
79
|
-
fun `test interruption event reasons`() {
|
|
80
|
-
// Test expected event reasons for device disconnection scenarios
|
|
81
|
-
val expectedReasons = mapOf(
|
|
82
|
-
"fallback" to listOf("deviceFallback", "deviceSwitchFailed"),
|
|
83
|
-
"pause" to listOf("deviceDisconnected")
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
// Verify the expected reasons are valid strings
|
|
87
|
-
expectedReasons.forEach { (behavior, reasons) ->
|
|
88
|
-
assertNotNull("Behavior $behavior should have reasons", reasons)
|
|
89
|
-
assertTrue("Behavior $behavior should have at least one reason", reasons.isNotEmpty())
|
|
90
|
-
|
|
91
|
-
reasons.forEach { reason ->
|
|
92
|
-
assertNotNull("Reason should not be null", reason)
|
|
93
|
-
assertTrue("Reason should not be empty", reason.isNotEmpty())
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@Test
|
|
99
|
-
fun `test fallback behavior logic`() {
|
|
100
|
-
// Test the logic for fallback behavior
|
|
101
|
-
val behavior = "fallback"
|
|
102
|
-
|
|
103
|
-
// When behavior is fallback:
|
|
104
|
-
// 1. Should attempt to get default device
|
|
105
|
-
// 2. If default device exists, should select it
|
|
106
|
-
// 3. If selection succeeds, should send "deviceFallback" event
|
|
107
|
-
// 4. If selection fails, should pause and send "deviceSwitchFailed" event
|
|
108
|
-
// 5. If no default device, should pause and send "deviceDisconnected" event
|
|
109
|
-
|
|
110
|
-
when (behavior) {
|
|
111
|
-
"fallback" -> {
|
|
112
|
-
// This branch should be taken
|
|
113
|
-
assertTrue("Should handle fallback behavior", true)
|
|
114
|
-
}
|
|
115
|
-
else -> {
|
|
116
|
-
fail("Should not reach default case for fallback behavior")
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@Test
|
|
122
|
-
fun `test pause behavior logic`() {
|
|
123
|
-
// Test the logic for pause behavior
|
|
124
|
-
val behavior = "pause"
|
|
125
|
-
|
|
126
|
-
// When behavior is pause:
|
|
127
|
-
// 1. Should pause recording immediately
|
|
128
|
-
// 2. Should send "deviceDisconnected" event
|
|
129
|
-
|
|
130
|
-
when (behavior) {
|
|
131
|
-
"fallback" -> {
|
|
132
|
-
fail("Should not handle as fallback")
|
|
133
|
-
}
|
|
134
|
-
else -> {
|
|
135
|
-
// This branch should be taken for pause
|
|
136
|
-
assertTrue("Should handle pause behavior", true)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
package net.siteed.audiostudio
|
|
2
|
-
|
|
3
|
-
import org.junit.Assert.assertFalse
|
|
4
|
-
import org.junit.Assert.assertTrue
|
|
5
|
-
import org.junit.Test
|
|
6
|
-
|
|
7
|
-
class InterruptionAutoResumePolicyTest {
|
|
8
|
-
@Test
|
|
9
|
-
fun autoResumesOnlyWhenSystemInterruptionPausedRecording() {
|
|
10
|
-
assertTrue(InterruptionAutoResumePolicy.shouldAutoResume(
|
|
11
|
-
autoResumeAfterInterruption = true,
|
|
12
|
-
isRecording = true,
|
|
13
|
-
isPaused = true,
|
|
14
|
-
pausedBySystemInterruption = true
|
|
15
|
-
))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@Test
|
|
19
|
-
fun doesNotAutoResumeUserPausedRecording() {
|
|
20
|
-
assertFalse(InterruptionAutoResumePolicy.shouldAutoResume(
|
|
21
|
-
autoResumeAfterInterruption = true,
|
|
22
|
-
isRecording = true,
|
|
23
|
-
isPaused = true,
|
|
24
|
-
pausedBySystemInterruption = false
|
|
25
|
-
))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Test
|
|
29
|
-
fun requiresAutoResumeAndActivePausedRecording() {
|
|
30
|
-
assertFalse(InterruptionAutoResumePolicy.shouldAutoResume(
|
|
31
|
-
autoResumeAfterInterruption = false,
|
|
32
|
-
isRecording = true,
|
|
33
|
-
isPaused = true,
|
|
34
|
-
pausedBySystemInterruption = true
|
|
35
|
-
))
|
|
36
|
-
assertFalse(InterruptionAutoResumePolicy.shouldAutoResume(
|
|
37
|
-
autoResumeAfterInterruption = true,
|
|
38
|
-
isRecording = false,
|
|
39
|
-
isPaused = true,
|
|
40
|
-
pausedBySystemInterruption = true
|
|
41
|
-
))
|
|
42
|
-
assertFalse(InterruptionAutoResumePolicy.shouldAutoResume(
|
|
43
|
-
autoResumeAfterInterruption = true,
|
|
44
|
-
isRecording = true,
|
|
45
|
-
isPaused = false,
|
|
46
|
-
pausedBySystemInterruption = true
|
|
47
|
-
))
|
|
48
|
-
}
|
|
49
|
-
}
|
|
Binary file
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Generate test WAV files for Android unit tests
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import wave
|
|
7
|
-
import struct
|
|
8
|
-
import math
|
|
9
|
-
import array
|
|
10
|
-
|
|
11
|
-
def generate_sine_wave(frequency, duration, sample_rate, amplitude=0.5):
|
|
12
|
-
"""Generate sine wave samples"""
|
|
13
|
-
num_samples = int(duration * sample_rate)
|
|
14
|
-
samples = []
|
|
15
|
-
for i in range(num_samples):
|
|
16
|
-
t = i / sample_rate
|
|
17
|
-
value = amplitude * math.sin(2 * math.pi * frequency * t)
|
|
18
|
-
# Convert to 16-bit PCM
|
|
19
|
-
pcm_value = int(value * 32767)
|
|
20
|
-
samples.append(pcm_value)
|
|
21
|
-
return samples
|
|
22
|
-
|
|
23
|
-
def create_wav_file(filename, channels, sample_rate, bit_depth, duration, frequency=440):
|
|
24
|
-
"""Create a WAV file with specified parameters"""
|
|
25
|
-
print(f"Creating {filename}...")
|
|
26
|
-
|
|
27
|
-
# Generate samples for left channel (or mono)
|
|
28
|
-
samples = generate_sine_wave(frequency, duration, sample_rate)
|
|
29
|
-
|
|
30
|
-
# For stereo, generate right channel with different frequency
|
|
31
|
-
if channels == 2:
|
|
32
|
-
right_samples = generate_sine_wave(frequency * 1.5, duration, sample_rate)
|
|
33
|
-
|
|
34
|
-
# Prepare the data
|
|
35
|
-
if bit_depth == 16:
|
|
36
|
-
# Create array of signed shorts
|
|
37
|
-
audio_data = array.array('h') # signed short
|
|
38
|
-
|
|
39
|
-
for i in range(len(samples)):
|
|
40
|
-
if channels == 1:
|
|
41
|
-
audio_data.append(samples[i])
|
|
42
|
-
else:
|
|
43
|
-
# Interleave stereo samples
|
|
44
|
-
audio_data.append(samples[i])
|
|
45
|
-
audio_data.append(right_samples[i])
|
|
46
|
-
elif bit_depth == 8:
|
|
47
|
-
# Create array of unsigned bytes
|
|
48
|
-
audio_data = array.array('B') # unsigned char
|
|
49
|
-
|
|
50
|
-
for i in range(len(samples)):
|
|
51
|
-
# Convert to 8-bit unsigned
|
|
52
|
-
sample_8bit = ((samples[i] + 32768) >> 8) & 0xFF
|
|
53
|
-
if channels == 1:
|
|
54
|
-
audio_data.append(sample_8bit)
|
|
55
|
-
else:
|
|
56
|
-
right_8bit = ((right_samples[i] + 32768) >> 8) & 0xFF
|
|
57
|
-
audio_data.append(sample_8bit)
|
|
58
|
-
audio_data.append(right_8bit)
|
|
59
|
-
else:
|
|
60
|
-
raise ValueError(f"Unsupported bit depth: {bit_depth}")
|
|
61
|
-
|
|
62
|
-
# Write WAV file
|
|
63
|
-
with wave.open(filename, 'wb') as wav_file:
|
|
64
|
-
wav_file.setnchannels(channels)
|
|
65
|
-
wav_file.setsampwidth(bit_depth // 8)
|
|
66
|
-
wav_file.setframerate(sample_rate)
|
|
67
|
-
wav_file.writeframes(audio_data.tobytes())
|
|
68
|
-
|
|
69
|
-
print(f" Created: {filename} ({duration}s, {sample_rate}Hz, {channels}ch, {bit_depth}bit)")
|
|
70
|
-
|
|
71
|
-
# Generate test files
|
|
72
|
-
if __name__ == "__main__":
|
|
73
|
-
try:
|
|
74
|
-
# Basic mono file
|
|
75
|
-
create_wav_file("test_mono_16bit_44100.wav",
|
|
76
|
-
channels=1, sample_rate=44100, bit_depth=16, duration=1.0)
|
|
77
|
-
|
|
78
|
-
# Stereo file
|
|
79
|
-
create_wav_file("test_stereo_16bit_48000.wav",
|
|
80
|
-
channels=2, sample_rate=48000, bit_depth=16, duration=1.0)
|
|
81
|
-
|
|
82
|
-
# Short duration file
|
|
83
|
-
create_wav_file("test_short_100ms.wav",
|
|
84
|
-
channels=1, sample_rate=44100, bit_depth=16, duration=0.1)
|
|
85
|
-
|
|
86
|
-
# Silent file (0 Hz frequency)
|
|
87
|
-
create_wav_file("test_silence.wav",
|
|
88
|
-
channels=1, sample_rate=44100, bit_depth=16, duration=0.5, frequency=0)
|
|
89
|
-
|
|
90
|
-
print("\nAll test WAV files generated successfully!")
|
|
91
|
-
except Exception as e:
|
|
92
|
-
print(f"Error: {e}")
|
|
93
|
-
import traceback
|
|
94
|
-
traceback.print_exc()
|
|
Binary file
|
|
Binary file
|
|
Binary file
|