opus_multistream.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include "opus_multistream.h"
  28. #include "opus.h"
  29. #include "opus_private.h"
  30. #include "stack_alloc.h"
  31. #include <stdarg.h>
  32. #include "float_cast.h"
  33. #include "os_support.h"
  34. int validate_layout(const ChannelLayout *layout)
  35. {
  36. int i, max_channel;
  37. max_channel = layout->nb_streams+layout->nb_coupled_streams;
  38. if (max_channel>255)
  39. return 0;
  40. for (i=0;i<layout->nb_channels;i++)
  41. {
  42. if (layout->mapping[i] >= max_channel && layout->mapping[i] != 255)
  43. return 0;
  44. }
  45. return 1;
  46. }
  47. int get_left_channel(const ChannelLayout *layout, int stream_id, int prev)
  48. {
  49. int i;
  50. i = (prev<0) ? 0 : prev+1;
  51. for (;i<layout->nb_channels;i++)
  52. {
  53. if (layout->mapping[i]==stream_id*2)
  54. return i;
  55. }
  56. return -1;
  57. }
  58. int get_right_channel(const ChannelLayout *layout, int stream_id, int prev)
  59. {
  60. int i;
  61. i = (prev<0) ? 0 : prev+1;
  62. for (;i<layout->nb_channels;i++)
  63. {
  64. if (layout->mapping[i]==stream_id*2+1)
  65. return i;
  66. }
  67. return -1;
  68. }
  69. int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev)
  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+layout->nb_coupled_streams)
  76. return i;
  77. }
  78. return -1;
  79. }