channels.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:5k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*
  2.  * FAAC - Freeware Advanced Audio Coder
  3.  * Copyright (C) 2001 Menno Bakker
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Lesser General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2.1 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Lesser General Public License for more details.
  14.  * You should have received a copy of the GNU Lesser General Public
  15.  * License along with this library; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  *
  18.  * $Id: channels.c,v 1.3 2001/06/04 23:02:24 wmay Exp $
  19.  */
  20. #include "channels.h"
  21. #include "coder.h"
  22. #include "util.h"
  23. /* If LFE present                                                       */
  24. /*  Num channels       # of SCE's       # of CPE's       #of LFE's      */ 
  25. /*  ============       ==========       ==========       =========      */
  26. /*      1                  1                0               0           */
  27. /*      2                  0                1               0           */
  28. /*      3                  1                1               0           */
  29. /*      4                  1                1               1           */
  30. /*      5                  1                2               0           */
  31. /* For more than 5 channels, use the following elements:                */
  32. /*      2*N                1                2*(N-1)         1           */
  33. /*      2*N+1              1                2*N             0           */
  34. /*                                                                      */
  35. /* Else:                                                                */
  36. /*                                                                      */  
  37. /*  Num channels       # of SCE's       # of CPE's       #of LFE's      */
  38. /*  ============       ==========       ==========       =========      */
  39. /*      1                  1                0               0           */
  40. /*      2                  0                1               0           */
  41. /*      3                  1                1               0           */
  42. /*      4                  2                1               0           */
  43. /*      5                  1                2               0           */
  44. /* For more than 5 channels, use the following elements:                */
  45. /*      2*N                2                2*(N-1)         0           */
  46. /*      2*N+1              1                2*N             0           */
  47. void GetChannelInfo(ChannelInfo *channelInfo, int numChannels, int useLfe)
  48. {
  49. int sceTag = 0;
  50. int lfeTag = 0;
  51. int cpeTag = 0;
  52. int numChannelsLeft = numChannels;
  53. /* First element is sce, except for 2 channel case */
  54. if (numChannelsLeft != 2) {
  55. channelInfo[numChannels-numChannelsLeft].present = 1;
  56. channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
  57. channelInfo[numChannels-numChannelsLeft].cpe = 0;
  58. channelInfo[numChannels-numChannelsLeft].lfe = 0;    
  59. numChannelsLeft--;
  60. }
  61. /* Next elements are cpe's */
  62. while (numChannelsLeft > 1) {
  63. /* Left channel info */
  64. channelInfo[numChannels-numChannelsLeft].present = 1;
  65. channelInfo[numChannels-numChannelsLeft].tag = cpeTag++;
  66. channelInfo[numChannels-numChannelsLeft].cpe = 1;
  67. channelInfo[numChannels-numChannelsLeft].common_window = 0;
  68. channelInfo[numChannels-numChannelsLeft].ch_is_left = 1;
  69. channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft+1;
  70. channelInfo[numChannels-numChannelsLeft].lfe = 0;    
  71. numChannelsLeft--;
  72. /* Right channel info */
  73. channelInfo[numChannels-numChannelsLeft].present = 1;
  74. channelInfo[numChannels-numChannelsLeft].cpe = 1;
  75. channelInfo[numChannels-numChannelsLeft].common_window = 0;
  76. channelInfo[numChannels-numChannelsLeft].ch_is_left = 0;
  77. channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft-1;
  78. channelInfo[numChannels-numChannelsLeft].lfe = 0;
  79. numChannelsLeft--;
  80. }
  81. /* Is there another channel left ? */
  82. if (numChannelsLeft) {
  83. if (useLfe) { 
  84. channelInfo[numChannels-numChannelsLeft].present = 1;
  85. channelInfo[numChannels-numChannelsLeft].tag = lfeTag++;
  86. channelInfo[numChannels-numChannelsLeft].cpe = 0;
  87. channelInfo[numChannels-numChannelsLeft].lfe = 1; 
  88. } else {
  89. channelInfo[numChannels-numChannelsLeft].present = 1;
  90. channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
  91. channelInfo[numChannels-numChannelsLeft].cpe = 0;
  92. channelInfo[numChannels-numChannelsLeft].lfe = 0;
  93. }
  94. numChannelsLeft--;
  95. }
  96. }