1 | //channels.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 |
---|
5 | * |
---|
6 | * This file is part of libroardsp a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * libroardsp is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "libroardsp.h" |
---|
27 | |
---|
28 | static struct { |
---|
29 | int id; |
---|
30 | char * name; |
---|
31 | char * sn; |
---|
32 | } _g_chans[] = { |
---|
33 | {ROARDSP_CHAN_NONE, "NONE", "NONE" }, |
---|
34 | {ROARDSP_CHAN_FRONT_LEFT, "FRONT_LEFT", "FL" }, |
---|
35 | {ROARDSP_CHAN_FRONT_RIGHT, "FRONT_RIGHT", "FR" }, |
---|
36 | {ROARDSP_CHAN_SIDE_LEFT, "SIDE_LEFT", "SL" }, |
---|
37 | {ROARDSP_CHAN_SIDE_RIGHT, "SIDE_RIGHT", "SR" }, |
---|
38 | {ROARDSP_CHAN_BACK_LEFT, "BACK_LEFT", "BL" }, |
---|
39 | {ROARDSP_CHAN_BACK_RIGHT, "BACK_RIGHT", "BR" }, |
---|
40 | {ROARDSP_CHAN_FRONT_CENTER, "FRONT_CENTER", "FC" }, |
---|
41 | {ROARDSP_CHAN_SIDE_CENTER, "SIDE_CENTER", "SC" }, |
---|
42 | {ROARDSP_CHAN_BACK_CENTER, "BACK_CENTER", "BC" }, |
---|
43 | {ROARDSP_CHAN_LEFT, "LEFT", "L" }, // alias |
---|
44 | {ROARDSP_CHAN_RIGHT, "RIGHT", "R" }, // alias |
---|
45 | {ROARDSP_CHAN_CENTER, "CENTER", "C" }, // alias |
---|
46 | {ROARDSP_CHAN_MONO, "MONO", "M" }, // alias |
---|
47 | {ROARDSP_CHAN_MS_MID, "MS_MID", "MID" }, |
---|
48 | {ROARDSP_CHAN_MS_SIDE, "MS_SIDE", "SIDE" }, |
---|
49 | {ROARDSP_CHAN_LFE, "LFE", "LFE" }, |
---|
50 | {ROARDSP_CHAN_EOL, NULL, NULL} |
---|
51 | }; |
---|
52 | |
---|
53 | char * roardsp_chan2str (int chan) { |
---|
54 | int i; |
---|
55 | |
---|
56 | for (i = 0; _g_chans[i].id != ROARDSP_CHAN_EOL; i++) |
---|
57 | if ( _g_chans[i].id == chan ) |
---|
58 | return _g_chans[i].name; |
---|
59 | |
---|
60 | return NULL; |
---|
61 | } |
---|
62 | |
---|
63 | int roardsp_str2chan(char * str) { |
---|
64 | int i; |
---|
65 | |
---|
66 | for (i = 0; _g_chans[i].id != ROARDSP_CHAN_EOL; i++) |
---|
67 | if ( !strcasecmp(_g_chans[i].name, str) || !strcasecmp(_g_chans[i].sn, str) ) |
---|
68 | return _g_chans[i].id; |
---|
69 | |
---|
70 | return -1; |
---|
71 | } |
---|
72 | |
---|
73 | int roardsp_chanlist2str(char * list, size_t len, char * str, size_t strlen) { |
---|
74 | int i; |
---|
75 | |
---|
76 | if ( list == NULL && len > 0 ) |
---|
77 | return -1; |
---|
78 | |
---|
79 | if ( (str == NULL || strlen == 0) && len > 0 ) |
---|
80 | return -1; |
---|
81 | |
---|
82 | if ( len == 0 ) { |
---|
83 | if ( str != NULL && strlen > 0 ) |
---|
84 | *str = 0; |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | // TODO: FIXME: do not ignore strlen from here |
---|
90 | *str = 0; |
---|
91 | |
---|
92 | for (i = 0; i < len; i++) { |
---|
93 | if ( i != 0 ) |
---|
94 | strcat(str, ","); |
---|
95 | |
---|
96 | strcat(str, roardsp_chan2str(list[i])); |
---|
97 | } |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | int roardsp_chanmap_calc(struct roardsp_chanmap * map, int what, int err_on_none) { |
---|
103 | int a, b; |
---|
104 | |
---|
105 | if ( map == NULL ) |
---|
106 | return -1; |
---|
107 | |
---|
108 | switch (what) { |
---|
109 | case ROARDSP_CHANMAP_MAP: |
---|
110 | memset(map->map, (char)-1, sizeof(map->map)); |
---|
111 | |
---|
112 | for (a = 0; a < ROAR_MAX_CHANNELS; a++) { |
---|
113 | if ( map->in[a] == ROARDSP_CHAN_NONE ) |
---|
114 | continue; |
---|
115 | |
---|
116 | for (b = 0; b < ROAR_MAX_CHANNELS; b++) { |
---|
117 | if ( map->in[a] == map->out[b] ) { |
---|
118 | map->map[a] = b; |
---|
119 | break; |
---|
120 | } |
---|
121 | } |
---|
122 | if ( b == ROAR_MAX_CHANNELS ) { // src not found in dest |
---|
123 | if ( err_on_none ) |
---|
124 | return -1; |
---|
125 | |
---|
126 | map->map[a] = -1; |
---|
127 | } |
---|
128 | } |
---|
129 | break; |
---|
130 | case ROARDSP_CHANMAP_IN: |
---|
131 | case ROARDSP_CHANMAP_OUT: |
---|
132 | default: |
---|
133 | return -1; |
---|
134 | break; |
---|
135 | } |
---|
136 | |
---|
137 | return 0; |
---|
138 | } |
---|
139 | |
---|
140 | //ll |
---|