source: roaraudio/libroardsp/channels.c @ 3330:b7af6ecf138b

Last change on this file since 3330:b7af6ecf138b was 3330:b7af6ecf138b, checked in by phi, 14 years ago

added roardsp_chanlist2str()

File size: 3.8 KB
Line 
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "libroardsp.h"
26
27static struct {
28 int id;
29 char * name;
30 char * sn;
31} _g_chans[] = {
32 {ROARDSP_CHAN_NONE,           "NONE",           "NONE"           },
33 {ROARDSP_CHAN_FRONT_LEFT,     "FRONT_LEFT",     "FL"             },
34 {ROARDSP_CHAN_FRONT_RIGHT,    "FRONT_RIGHT",    "FR"             },
35 {ROARDSP_CHAN_SIDE_LEFT,      "SIDE_LEFT",      "SL"             },
36 {ROARDSP_CHAN_SIDE_RIGHT,     "SIDE_RIGHT",     "SR"             },
37 {ROARDSP_CHAN_BACK_LEFT,      "BACK_LEFT",      "BL"             },
38 {ROARDSP_CHAN_BACK_RIGHT,     "BACK_RIGHT",     "BR"             },
39 {ROARDSP_CHAN_FRONT_CENTER,   "FRONT_CENTER",   "FC"             },
40 {ROARDSP_CHAN_SIDE_CENTER,    "SIDE_CENTER",    "SC"             },
41 {ROARDSP_CHAN_BACK_CENTER,    "BACK_CENTER",    "BC"             },
42 {ROARDSP_CHAN_LEFT,           "LEFT",           "L"              }, // alias
43 {ROARDSP_CHAN_RIGHT,          "RIGHT",          "R"              }, // alias
44 {ROARDSP_CHAN_CENTER,         "CENTER",         "C"              }, // alias
45 {ROARDSP_CHAN_MONO,           "MONO",           "M"              }, // alias
46 {ROARDSP_CHAN_MS_MID,         "MS_MID",         "MID"            },
47 {ROARDSP_CHAN_MS_SIDE,        "MS_SIDE",        "SIDE"           },
48 {ROARDSP_CHAN_LFE,            "LFE",            "LFE"            },
49 {ROARDSP_CHAN_EOL, NULL, NULL}
50};
51
52char * roardsp_chan2str (int chan) {
53 int i;
54
55 for (i = 0; _g_chans[i].id != ROARDSP_CHAN_EOL; i++)
56  if ( _g_chans[i].id == chan )
57   return _g_chans[i].name;
58
59 return NULL;
60}
61
62int roardsp_str2chan(char * str) {
63 int i;
64
65 for (i = 0; _g_chans[i].id != ROARDSP_CHAN_EOL; i++)
66  if ( !strcasecmp(_g_chans[i].name, str) || !strcasecmp(_g_chans[i].sn, str) )
67   return _g_chans[i].id;
68
69 return -1;
70}
71
72int    roardsp_chanlist2str(int * list, size_t len, char * str, size_t strlen) {
73 int i;
74
75 if ( list == NULL && len > 0 )
76  return -1;
77
78 if ( (str == NULL || strlen == 0) && len > 0 )
79  return -1;
80
81 if ( len == 0 ) {
82  if ( str != NULL && strlen > 0 )
83   *str = 0;
84
85  return 0;
86 }
87
88 // TODO: FIXME: do not ignore strlen from here
89 *str = 0;
90
91 for (i = 0; i < len; i++) {
92  if ( i != 0 )
93   strcat(str, ",");
94
95  strcat(str, roardsp_chan2str(list[i]));
96 }
97
98 return 0;
99}
100
101int roardsp_chanmap_calc(struct roardsp_chanmap * map, int what, int err_on_none) {
102 int a, b;
103
104 if ( map == NULL )
105  return -1;
106
107 switch (what) {
108  case ROARDSP_CHANMAP_MAP:
109    memset(map->map, (char)-1, sizeof(map->map));
110
111    for (a = 0; a < ROAR_MAX_CHANNELS; a++) {
112     if ( map->in[a] == ROARDSP_CHAN_NONE )
113      continue;
114
115     for (b = 0; b < ROAR_MAX_CHANNELS; b++) {
116      if ( map->in[a] == map->out[b] ) {
117       map->map[a] = b;
118       break;
119      }
120     }
121     if ( b == ROAR_MAX_CHANNELS ) { // src not found in dest
122      if ( err_on_none )
123       return -1;
124
125      map->map[a] = -1;
126     }
127    }
128   break;
129  case ROARDSP_CHANMAP_IN:
130  case ROARDSP_CHANMAP_OUT:
131  default:
132    return -1;
133   break;
134 }
135
136 return 0;
137}
138
139//ll
Note: See TracBrowser for help on using the repository browser.