1 /// Translated from C to D 2 module soundio.channel_layout; 3 4 @nogc nothrow: 5 extern(C): __gshared: 6 7 8 import soundio.soundio_private; 9 import soundio.util; 10 import core.stdc.stdio; 11 import core.stdc.string: strlen; 12 13 package: 14 15 static SoundIoChannelLayout[26] builtin_channel_layouts = [ 16 { 17 "Mono", 18 1, 19 [ 20 SoundIoChannelId.FrontCenter, 21 ], 22 }, 23 { 24 "Stereo", 25 2, 26 [ 27 SoundIoChannelId.FrontLeft, 28 SoundIoChannelId.FrontRight, 29 ], 30 }, 31 { 32 "2.1", 33 3, 34 [ 35 SoundIoChannelId.FrontLeft, 36 SoundIoChannelId.FrontRight, 37 SoundIoChannelId.Lfe, 38 ], 39 }, 40 { 41 "3.0", 42 3, 43 [ 44 SoundIoChannelId.FrontLeft, 45 SoundIoChannelId.FrontRight, 46 SoundIoChannelId.FrontCenter, 47 ] 48 }, 49 { 50 "3.0 (back)", 51 3, 52 [ 53 SoundIoChannelId.FrontLeft, 54 SoundIoChannelId.FrontRight, 55 SoundIoChannelId.BackCenter, 56 ] 57 }, 58 { 59 "3.1", 60 4, 61 [ 62 SoundIoChannelId.FrontLeft, 63 SoundIoChannelId.FrontRight, 64 SoundIoChannelId.FrontCenter, 65 SoundIoChannelId.Lfe, 66 ] 67 }, 68 { 69 "4.0", 70 4, 71 [ 72 SoundIoChannelId.FrontLeft, 73 SoundIoChannelId.FrontRight, 74 SoundIoChannelId.FrontCenter, 75 SoundIoChannelId.BackCenter, 76 ] 77 }, 78 { 79 "Quad", 80 4, 81 [ 82 SoundIoChannelId.FrontLeft, 83 SoundIoChannelId.FrontRight, 84 SoundIoChannelId.BackLeft, 85 SoundIoChannelId.BackRight, 86 ], 87 }, 88 { 89 "Quad (side)", 90 4, 91 [ 92 SoundIoChannelId.FrontLeft, 93 SoundIoChannelId.FrontRight, 94 SoundIoChannelId.SideLeft, 95 SoundIoChannelId.SideRight, 96 ] 97 }, 98 { 99 "4.1", 100 5, 101 [ 102 SoundIoChannelId.FrontLeft, 103 SoundIoChannelId.FrontRight, 104 SoundIoChannelId.FrontCenter, 105 SoundIoChannelId.BackCenter, 106 SoundIoChannelId.Lfe, 107 ] 108 }, 109 { 110 "5.0 (back)", 111 5, 112 [ 113 SoundIoChannelId.FrontLeft, 114 SoundIoChannelId.FrontRight, 115 SoundIoChannelId.FrontCenter, 116 SoundIoChannelId.BackLeft, 117 SoundIoChannelId.BackRight, 118 ] 119 }, 120 { 121 "5.0 (side)", 122 5, 123 [ 124 SoundIoChannelId.FrontLeft, 125 SoundIoChannelId.FrontRight, 126 SoundIoChannelId.FrontCenter, 127 SoundIoChannelId.SideLeft, 128 SoundIoChannelId.SideRight, 129 ] 130 }, 131 { 132 "5.1", 133 6, 134 [ 135 SoundIoChannelId.FrontLeft, 136 SoundIoChannelId.FrontRight, 137 SoundIoChannelId.FrontCenter, 138 SoundIoChannelId.SideLeft, 139 SoundIoChannelId.SideRight, 140 SoundIoChannelId.Lfe, 141 ] 142 }, 143 { 144 "5.1 (back)", 145 6, 146 [ 147 SoundIoChannelId.FrontLeft, 148 SoundIoChannelId.FrontRight, 149 SoundIoChannelId.FrontCenter, 150 SoundIoChannelId.BackLeft, 151 SoundIoChannelId.BackRight, 152 SoundIoChannelId.Lfe, 153 ] 154 }, 155 { 156 "6.0 (side)", 157 6, 158 [ 159 SoundIoChannelId.FrontLeft, 160 SoundIoChannelId.FrontRight, 161 SoundIoChannelId.FrontCenter, 162 SoundIoChannelId.SideLeft, 163 SoundIoChannelId.SideRight, 164 SoundIoChannelId.BackCenter, 165 ] 166 }, 167 { 168 "6.0 (front)", 169 6, 170 [ 171 SoundIoChannelId.FrontLeft, 172 SoundIoChannelId.FrontRight, 173 SoundIoChannelId.SideLeft, 174 SoundIoChannelId.SideRight, 175 SoundIoChannelId.FrontLeftCenter, 176 SoundIoChannelId.FrontRightCenter, 177 ] 178 }, 179 { 180 "Hexagonal", 181 6, 182 [ 183 SoundIoChannelId.FrontLeft, 184 SoundIoChannelId.FrontRight, 185 SoundIoChannelId.FrontCenter, 186 SoundIoChannelId.BackLeft, 187 SoundIoChannelId.BackRight, 188 SoundIoChannelId.BackCenter, 189 ] 190 }, 191 { 192 "6.1", 193 7, 194 [ 195 SoundIoChannelId.FrontLeft, 196 SoundIoChannelId.FrontRight, 197 SoundIoChannelId.FrontCenter, 198 SoundIoChannelId.SideLeft, 199 SoundIoChannelId.SideRight, 200 SoundIoChannelId.BackCenter, 201 SoundIoChannelId.Lfe, 202 ] 203 }, 204 { 205 "6.1 (back)", 206 7, 207 [ 208 SoundIoChannelId.FrontLeft, 209 SoundIoChannelId.FrontRight, 210 SoundIoChannelId.FrontCenter, 211 SoundIoChannelId.BackLeft, 212 SoundIoChannelId.BackRight, 213 SoundIoChannelId.BackCenter, 214 SoundIoChannelId.Lfe, 215 ] 216 }, 217 { 218 "6.1 (front)", 219 7, 220 [ 221 SoundIoChannelId.FrontLeft, 222 SoundIoChannelId.FrontRight, 223 SoundIoChannelId.SideLeft, 224 SoundIoChannelId.SideRight, 225 SoundIoChannelId.FrontLeftCenter, 226 SoundIoChannelId.FrontRightCenter, 227 SoundIoChannelId.Lfe, 228 ] 229 }, 230 { 231 "7.0", 232 7, 233 [ 234 SoundIoChannelId.FrontLeft, 235 SoundIoChannelId.FrontRight, 236 SoundIoChannelId.FrontCenter, 237 SoundIoChannelId.SideLeft, 238 SoundIoChannelId.SideRight, 239 SoundIoChannelId.BackLeft, 240 SoundIoChannelId.BackRight, 241 ] 242 }, 243 { 244 "7.0 (front)", 245 7, 246 [ 247 SoundIoChannelId.FrontLeft, 248 SoundIoChannelId.FrontRight, 249 SoundIoChannelId.FrontCenter, 250 SoundIoChannelId.SideLeft, 251 SoundIoChannelId.SideRight, 252 SoundIoChannelId.FrontLeftCenter, 253 SoundIoChannelId.FrontRightCenter, 254 ] 255 }, 256 { 257 "7.1", 258 8, 259 [ 260 SoundIoChannelId.FrontLeft, 261 SoundIoChannelId.FrontRight, 262 SoundIoChannelId.FrontCenter, 263 SoundIoChannelId.SideLeft, 264 SoundIoChannelId.SideRight, 265 SoundIoChannelId.BackLeft, 266 SoundIoChannelId.BackRight, 267 SoundIoChannelId.Lfe, 268 ] 269 }, 270 { 271 "7.1 (wide)", 272 8, 273 [ 274 SoundIoChannelId.FrontLeft, 275 SoundIoChannelId.FrontRight, 276 SoundIoChannelId.FrontCenter, 277 SoundIoChannelId.SideLeft, 278 SoundIoChannelId.SideRight, 279 SoundIoChannelId.FrontLeftCenter, 280 SoundIoChannelId.FrontRightCenter, 281 SoundIoChannelId.Lfe, 282 ] 283 }, 284 { 285 "7.1 (wide) (back)", 286 8, 287 [ 288 SoundIoChannelId.FrontLeft, 289 SoundIoChannelId.FrontRight, 290 SoundIoChannelId.FrontCenter, 291 SoundIoChannelId.BackLeft, 292 SoundIoChannelId.BackRight, 293 SoundIoChannelId.FrontLeftCenter, 294 SoundIoChannelId.FrontRightCenter, 295 SoundIoChannelId.Lfe, 296 ] 297 }, 298 { 299 "Octagonal", 300 8, 301 [ 302 SoundIoChannelId.FrontLeft, 303 SoundIoChannelId.FrontRight, 304 SoundIoChannelId.FrontCenter, 305 SoundIoChannelId.SideLeft, 306 SoundIoChannelId.SideRight, 307 SoundIoChannelId.BackLeft, 308 SoundIoChannelId.BackRight, 309 SoundIoChannelId.BackCenter, 310 ] 311 }, 312 ]; 313 314 enum CHANNEL_NAME_ALIAS_COUNT = 3; 315 alias const(char)*[CHANNEL_NAME_ALIAS_COUNT] channel_names_t; 316 static channel_names_t* channel_names = [ 317 ["(Invalid Channel)", null, null], 318 ["Front Left", "FL", "front-left"], 319 ["Front Right", "FR", "front-right"], 320 ["Front Center", "FC", "front-center"], 321 ["LFE", "LFE", "lfe"], 322 ["Back Left", "BL", "rear-left"], 323 ["Back Right", "BR", "rear-right"], 324 ["Front Left Center", "FLC", "front-left-of-center"], 325 ["Front Right Center", "FRC", "front-right-of-center"], 326 ["Back Center", "BC", "rear-center"], 327 ["Side Left", "SL", "side-left"], 328 ["Side Right", "SR", "side-right"], 329 ["Top Center", "TC", "top-center"], 330 ["Top Front Left", "TFL", "top-front-left"], 331 ["Top Front Center", "TFC", "top-front-center"], 332 ["Top Front Right", "TFR", "top-front-right"], 333 ["Top Back Left", "TBL", "top-rear-left"], 334 ["Top Back Center", "TBC", "top-rear-center"], 335 ["Top Back Right", "TBR", "top-rear-right"], 336 ["Back Left Center", null, null], 337 ["Back Right Center", null, null], 338 ["Front Left Wide", null, null], 339 ["Front Right Wide", null, null], 340 ["Front Left High", null, null], 341 ["Front Center High", null, null], 342 ["Front Right High", null, null], 343 ["Top Front Left Center", null, null], 344 ["Top Front Right Center", null, null], 345 ["Top Side Left", null, null], 346 ["Top Side Right", null, null], 347 ["Left LFE", null, null], 348 ["Right LFE", null, null], 349 ["LFE 2", null, null], 350 ["Bottom Center", null, null], 351 ["Bottom Left Center", null, null], 352 ["Bottom Right Center", null, null], 353 ["Mid/Side Mid", null, null], 354 ["Mid/Side Side", null, null], 355 ["Ambisonic W", null, null], 356 ["Ambisonic X", null, null], 357 ["Ambisonic Y", null, null], 358 ["Ambisonic Z", null, null], 359 ["X-Y X", null, null], 360 ["X-Y Y", null, null], 361 ["Headphones Left", null, null], 362 ["Headphones Right", null, null], 363 ["Click Track", null, null], 364 ["Foreign Language", null, null], 365 ["Hearing Impaired", null, null], 366 ["Narration", null, null], 367 ["Haptic", null, null], 368 ["Dialog Centric Mix", null, null], 369 ["Aux", null, null], 370 ["Aux 0", null, null], 371 ["Aux 1", null, null], 372 ["Aux 2", null, null], 373 ["Aux 3", null, null], 374 ["Aux 4", null, null], 375 ["Aux 5", null, null], 376 ["Aux 6", null, null], 377 ["Aux 7", null, null], 378 ["Aux 8", null, null], 379 ["Aux 9", null, null], 380 ["Aux 10", null, null], 381 ["Aux 11", null, null], 382 ["Aux 12", null, null], 383 ["Aux 13", null, null], 384 ["Aux 14", null, null], 385 ["Aux 15", null, null], 386 ]; 387 388 const(char)* soundio_get_channel_name(SoundIoChannelId id) { 389 if (id >= channel_names.length) 390 return "(Invalid Channel)"; 391 else 392 return channel_names[id][0]; 393 } 394 395 bool soundio_channel_layout_equal(const(SoundIoChannelLayout)* a, const(SoundIoChannelLayout)* b) { 396 if (a.channel_count != b.channel_count) 397 return false; 398 399 for (int i = 0; i < a.channel_count; i += 1) { 400 if (a.channels[i] != b.channels[i]) 401 return false; 402 } 403 404 return true; 405 } 406 407 int soundio_channel_layout_builtin_count() { 408 return builtin_channel_layouts.length; 409 } 410 411 const(SoundIoChannelLayout)* soundio_channel_layout_get_builtin(int index) { 412 assert(index >= 0); 413 assert(index <= builtin_channel_layouts.length); 414 return &builtin_channel_layouts[index]; 415 } 416 417 int soundio_channel_layout_find_channel(const(SoundIoChannelLayout)* layout, SoundIoChannelId channel) { 418 for (int i = 0; i < layout.channel_count; i += 1) { 419 if (layout.channels[i] == channel) 420 return i; 421 } 422 return -1; 423 } 424 425 bool soundio_channel_layout_detect_builtin(SoundIoChannelLayout* layout) { 426 for (int i = 0; i < builtin_channel_layouts.length; i += 1) { 427 const(SoundIoChannelLayout)* builtin_layout = &builtin_channel_layouts[i]; 428 if (soundio_channel_layout_equal(builtin_layout, layout)) { 429 layout.name = builtin_layout.name; 430 return true; 431 } 432 } 433 layout.name = null; 434 return false; 435 } 436 437 const(SoundIoChannelLayout)* soundio_channel_layout_get_default(int channel_count) { 438 switch (channel_count) { 439 case 1: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId.Mono); 440 case 2: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId.Stereo); 441 case 3: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._3Point0); 442 case 4: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._4Point0); 443 case 5: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._5Point0Back); 444 case 6: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._5Point1Back); 445 case 7: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._6Point1); 446 case 8: return soundio_channel_layout_get_builtin(SoundIoChannelLayoutId._7Point1); 447 default: break; 448 } 449 return null; 450 } 451 452 SoundIoChannelId soundio_parse_channel_id(const(char)* str, int str_len) { 453 for (int id = 0; id < channel_names.length; id += 1) { 454 for (int i = 0; i < CHANNEL_NAME_ALIAS_COUNT; i += 1) { 455 const(char)* alias_ = channel_names[id][i]; 456 if (!alias_) 457 break; 458 int alias_len = cast(int) strlen(alias_); 459 if (soundio_streql(alias_, alias_len, str, str_len)) 460 return cast(SoundIoChannelId)id; 461 } 462 } 463 return SoundIoChannelId.Invalid; 464 }