home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wvis0626.zip / warpvision_20020626.zip / gui / audio.hpp next >
C/C++ Source or Header  |  2002-06-19  |  6KB  |  206 lines

  1. /*
  2.  * WarpVision GUI audio part
  3.  *
  4.  * CopyRight Vlad Stelmahovsky
  5.  *
  6.  * WarpVision is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * WarpVision is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20. */
  21.  
  22.  
  23. void set_sound_state(BOOL state)
  24. {
  25.  
  26.     USHORT             usDeviceID;
  27.     MCI_SET_PARMS      msp;
  28.     USHORT ushSt;
  29.  
  30.     if (state) ushSt = MCI_SET_ON;
  31.      else ushSt = MCI_SET_OFF;
  32. //    msp.dwLevel = vol;                  /* 50% of volume */
  33.     msp.dwAudio = MCI_SET_AUDIO_ALL;
  34.     mciSendCommand(DART.DeviceID,
  35.                    MCI_SET,
  36.                    MCI_WAIT | MCI_SET_AUDIO | ushSt,
  37.                    (DWORD)&msp, 0);
  38.  
  39.   return;
  40.  
  41. }
  42.  
  43. void set_volume(ULONG vol)
  44. {
  45.  
  46.     USHORT             usDeviceID;
  47.     MCI_SET_PARMS      msp;
  48.  
  49.     msp.dwLevel = vol;                  /* 50% of volume */
  50.     msp.dwAudio = MCI_SET_AUDIO_ALL;
  51.     mciSendCommand(DART.DeviceID,
  52.                    MCI_SET,
  53.                    MCI_WAIT | MCI_SET_AUDIO |
  54.                    MCI_SET_VOLUME,
  55.                    (DWORD)&msp, 0);
  56.  
  57.   set_slider_volume(&skn->audio_sld, vol); // set volume from the driver
  58.  
  59.   return;
  60.  
  61. }
  62.  
  63. USHORT get_volume()
  64. {
  65.    ULONG    ulError;
  66.    BOOL     disc_loaded;
  67.    USHORT    vol;
  68.                     /* Set to TRUE by this example if media is present */
  69.    MCI_STATUS_PARMS  mstatusp;
  70.    memset ( &mstatusp, 0, sizeof ( MCI_STATUS_PARMS ) );
  71.    mstatusp.dwItem = MCI_STATUS_VOLUME;
  72.  
  73.    ulError = mciSendCommand(DART.DeviceID,      /* Device ID              */
  74.     MCI_STATUS,                              /* MCI status message     */
  75.     MCI_WAIT | MCI_STATUS_ITEM,
  76.                                              /* Flags for this message */
  77.     (DWORD) &mstatusp,                       /* Data structure         */
  78.     0);                                      /* No user parm           */
  79.  
  80.    if (!(ulError & 0xffff))
  81.      {
  82.        vol = LOUSHORT(mstatusp.dwReturn);    /* Media present
  83.                                                      status            */
  84.      } else vol = 0;
  85. return vol;
  86. }
  87.  
  88. #define AUDIO_FRAME_SIZE   65535
  89. extern "C" {
  90.     sample_t *my_a52_data;
  91.     a52_state_t *my_a52_state;
  92.     static int my_a52_flags;
  93.     sample_t my_a52_level, my_a52_bias;
  94.     int my_a52_sample_rate;
  95.     int my_a52_bit_rate;
  96.  
  97.     UCHAR *my_audio_buffer;
  98.     UCHAR *my_input_audio_buffer;
  99.     int my_input_audio_buffer_len;
  100.  
  101. int my_a52_fill_buffer(sh_audio_t *sh_audio)
  102. {
  103.     int length;
  104.  
  105.     my_input_audio_buffer_len = 0;
  106.  
  107.     // Sync frame
  108.     for(;;)
  109.     {
  110.         while(my_input_audio_buffer_len < 7)
  111.         {
  112.             int chr;
  113.  
  114.             chr = demux_getc(sh_audio->ds);
  115.  
  116.             if (chr < 0)
  117.                return -1;
  118.  
  119.             my_input_audio_buffer[my_input_audio_buffer_len++] = chr;
  120.         }
  121.  
  122.         length = a52_syncinfo(my_input_audio_buffer,
  123.                               &my_a52_flags,
  124.                               &my_a52_sample_rate,
  125.                               &my_a52_bit_rate);
  126.         // if done
  127.         if(length >= 7 && length <= 3840)
  128.             break;
  129.  
  130.         // resync
  131.         memmove(my_input_audio_buffer, my_input_audio_buffer + 1, 6);
  132.         my_input_audio_buffer_len--;
  133.     }
  134.  
  135.     // read a52 frame
  136.     my_input_audio_buffer_len = demux_read_data(sh_audio->ds,
  137.                                              my_input_audio_buffer + 7,
  138.                                              length - 7);
  139.     return length;
  140. }
  141.  
  142. ULONG get_audio_bps(sh_audio_t *sh_audioLL)
  143. {
  144.     int rc;
  145. //    sample_t *a52_data;
  146. //    a52_state_t *a52_state;
  147. //    static int a52_flags;
  148. //    sample_t a52_level, a52_bias;
  149. //    int a52_sample_rate;
  150. //    int a52_bit_rate;
  151.  
  152. //    UCHAR *audio_buffer;
  153. //    UCHAR *input_audio_buffer;
  154. //    int input_audio_buffer_len;
  155.     audio_header_t audio_header;
  156.     ULONG bps;
  157.  
  158.     my_input_audio_buffer = (UCHAR *)malloc(AUDIO_FRAME_SIZE * 4);
  159.     my_input_audio_buffer_len = 0;
  160.  
  161.     my_audio_buffer = (UCHAR *)malloc(AUDIO_FRAME_SIZE * 4);
  162.     audio_header.audio_buffer_used = 0;
  163.  
  164. //    memset(&audio_header, 0, sizeof(audio_header_t));
  165.  
  166.     switch(sh_audioLL->codec->codec_type)
  167.     {
  168.         case AUDIO_MPEG:
  169.  
  170.             MP3_Init();
  171.             MP3_DecodeFrame(my_audio_buffer, -1);
  172.             bps = (ULONG)MP3_bitrate*(1000/8);
  173. //            MP3_Close();
  174.  
  175.         break;
  176.  
  177.     case AUDIO_AC3:
  178. //        printf("a52 initing\n");fflush(stdout);
  179.            my_a52_state = a52_init(0);
  180.            if (my_a52_state == NULL) return 0L;
  181. //           printf("a52 buffer fulling\n");fflush(stdout);
  182. //           if (sh_audio != NULL) {
  183.           if (my_a52_fill_buffer(sh_audioLL) < 0) return 0L;
  184. //          } else printf("sh_audio shit!!!\n");fflush(stdout);
  185.           //            printf("a52 decoding frame\n");fflush(stdout);
  186.             my_a52_flags = A52_STEREO;
  187.             my_a52_flags |= A52_ADJUST_LEVEL;
  188.             my_a52_level = 1;
  189.             my_a52_bias = 384;
  190.  
  191.            if (a52_frame(my_a52_state,
  192.                           my_input_audio_buffer,
  193.                           &my_a52_flags, &my_a52_level, my_a52_bias) != 0)
  194.                 return 0L;
  195.                 bps = (ULONG)(float)my_a52_bit_rate/8;
  196.  
  197.         break;
  198.  
  199.         case AUDIO_PCM:
  200.             bps = (ULONG)sh_audioLL->wf->nAvgBytesPerSec;
  201.             break;
  202.     }
  203.    return bps;
  204. } // get_audio_bps
  205. } // extern C
  206.