[3327] | 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 | |
---|
[3328] | 27 | static 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 | |
---|
| 52 | char * 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 | |
---|
| 62 | int 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 | } |
---|
[3327] | 71 | |
---|
[3329] | 72 | int roardsp_chanmap_calc(struct roardsp_chanmap * map, int what, int err_on_none) { |
---|
| 73 | int a, b; |
---|
| 74 | |
---|
| 75 | if ( map == NULL ) |
---|
| 76 | return -1; |
---|
| 77 | |
---|
| 78 | switch (what) { |
---|
| 79 | case ROARDSP_CHANMAP_MAP: |
---|
| 80 | memset(map->map, (char)-1, sizeof(map->map)); |
---|
| 81 | |
---|
| 82 | for (a = 0; a < ROAR_MAX_CHANNELS; a++) { |
---|
| 83 | if ( map->in[a] == ROARDSP_CHAN_NONE ) |
---|
| 84 | continue; |
---|
| 85 | |
---|
| 86 | for (b = 0; b < ROAR_MAX_CHANNELS; b++) { |
---|
| 87 | if ( map->in[a] == map->out[b] ) { |
---|
| 88 | map->map[a] = b; |
---|
| 89 | break; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | if ( b == ROAR_MAX_CHANNELS ) { // src not found in dest |
---|
| 93 | if ( err_on_none ) |
---|
| 94 | return -1; |
---|
| 95 | |
---|
| 96 | map->map[a] = -1; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | break; |
---|
| 100 | case ROARDSP_CHANMAP_IN: |
---|
| 101 | case ROARDSP_CHANMAP_OUT: |
---|
| 102 | default: |
---|
| 103 | return -1; |
---|
| 104 | break; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | |
---|
[3327] | 110 | //ll |
---|