Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2011 Xiph.Org Foundation |
| 2 | Written by Jean-Marc Valin */ |
| 3 | /* |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions |
| 6 | are met: |
| 7 | |
| 8 | - Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | |
| 11 | - Redistributions in binary form must reproduce the above copyright |
| 12 | notice, this list of conditions and the following disclaimer in the |
| 13 | documentation and/or other materials provided with the distribution. |
| 14 | |
| 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Jean-Marc Valin | cb05e7c | 2012-04-20 16:40:24 -0400 | [diff] [blame] | 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include "config.h" |
| 30 | #endif |
| 31 | |
| 32 | #include "opus_multistream.h" |
| 33 | #include "opus.h" |
| 34 | #include "opus_private.h" |
| 35 | #include "stack_alloc.h" |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 36 | #include <stdarg.h> |
| 37 | #include "float_cast.h" |
Jean-Marc Valin | 85b8e62 | 2011-08-29 16:10:08 -0400 | [diff] [blame] | 38 | #include "os_support.h" |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 39 | |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 40 | |
Jean-Marc Valin | ae0e2ca | 2012-11-07 19:57:33 -0500 | [diff] [blame] | 41 | int validate_layout(const ChannelLayout *layout) |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 42 | { |
| 43 | int i, max_channel; |
| 44 | |
| 45 | max_channel = layout->nb_streams+layout->nb_coupled_streams; |
| 46 | if (max_channel>255) |
| 47 | return 0; |
| 48 | for (i=0;i<layout->nb_channels;i++) |
| 49 | { |
| 50 | if (layout->mapping[i] >= max_channel && layout->mapping[i] != 255) |
| 51 | return 0; |
| 52 | } |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | |
Jean-Marc Valin | ae0e2ca | 2012-11-07 19:57:33 -0500 | [diff] [blame] | 57 | int get_left_channel(const ChannelLayout *layout, int stream_id, int prev) |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 58 | { |
| 59 | int i; |
| 60 | i = (prev<0) ? 0 : prev+1; |
| 61 | for (;i<layout->nb_channels;i++) |
| 62 | { |
| 63 | if (layout->mapping[i]==stream_id*2) |
| 64 | return i; |
| 65 | } |
| 66 | return -1; |
| 67 | } |
| 68 | |
Jean-Marc Valin | ae0e2ca | 2012-11-07 19:57:33 -0500 | [diff] [blame] | 69 | int get_right_channel(const ChannelLayout *layout, int stream_id, int prev) |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 70 | { |
| 71 | int i; |
| 72 | i = (prev<0) ? 0 : prev+1; |
| 73 | for (;i<layout->nb_channels;i++) |
| 74 | { |
| 75 | if (layout->mapping[i]==stream_id*2+1) |
| 76 | return i; |
| 77 | } |
| 78 | return -1; |
| 79 | } |
| 80 | |
Jean-Marc Valin | ae0e2ca | 2012-11-07 19:57:33 -0500 | [diff] [blame] | 81 | int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev) |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 82 | { |
| 83 | int i; |
| 84 | i = (prev<0) ? 0 : prev+1; |
| 85 | for (;i<layout->nb_channels;i++) |
| 86 | { |
Gregory Maxwell | 92c896e | 2011-11-28 23:19:08 -0500 | [diff] [blame] | 87 | if (layout->mapping[i]==stream_id+layout->nb_coupled_streams) |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 88 | return i; |
| 89 | } |
| 90 | return -1; |
| 91 | } |
| 92 | |