File: gap_audio_util.c

package info (click to toggle)
gimp-gap 2.6.0%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 20,720 kB
  • ctags: 7,997
  • sloc: ansic: 119,817; sh: 3,890; makefile: 932; lisp: 97; pascal: 55
file content (123 lines) | stat: -rw-r--r-- 3,556 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* gap_audio_util.c
 *
 *  GAP common encoder audio utility procedures
 *
 */

/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
/* 2002.01.05 hof  removed p_get_wavparams
 */

/* SYTEM (UNIX) includes */
#include <stdio.h>
#include <stdlib.h>

/* GIMP includes */
#include "gtk/gtk.h"
#include "libgimp/gimp.h"


/* GAP includes */
#include "gap_audio_util.h"

extern      int gap_debug; /* ==0  ... dont print debug infos */

/* --------------------------------
 * gap_audio_util_stereo_split16to16
 * --------------------------------
 */
void
gap_audio_util_stereo_split16to16(unsigned char *l_left_ptr, unsigned char *l_right_ptr, unsigned char *l_aud_ptr, long l_data_len)
{
  long l_idx;

  /* split stereo 16 bit data from wave data (sequence is  2 bytes left channel, 2 right, 2 left, 2 right ...)
   * into 2 separate datablocks for left and right channel of 16 bit per sample
   */
  l_idx = 0;
  while(l_idx < l_data_len)
  {
    *(l_left_ptr++)  = l_aud_ptr[l_idx++];
    *(l_left_ptr++)  = l_aud_ptr[l_idx++];
    *(l_right_ptr++) = l_aud_ptr[l_idx++];
    *(l_right_ptr++) = l_aud_ptr[l_idx++];
  }
}  /* end gap_audio_util_stereo_split16to16 */

/* --------------------------------
 * gap_audio_util_dbl_sample_8_to_16
 * --------------------------------
 */
void
gap_audio_util_dbl_sample_8_to_16(unsigned char insample8,
                     unsigned char *lsb_out,
                     unsigned char *msb_out)
{
  /* 16 bit audiodata is signed,
   *  8 bit audiodata is unsigned
   */

   /* this conversion uses only positive 16bit values
    */
   *msb_out = (insample8 >> 1);
   *lsb_out = ((insample8 << 7) &  0x80);
   return;


   /* this conversion makes use of negative 16bit values
    * and the full sample range
    * (somehow it sounds not as good as the other one)
    */
   *msb_out = (insample8 -64);
   *lsb_out = 0;
}  /* end gap_audio_util_dbl_sample_8_to_16 */

/* --------------------------------
 * gap_audio_util_stereo_split8to16
 * --------------------------------
 */
void
gap_audio_util_stereo_split8to16(unsigned char *l_left_ptr, unsigned char *l_right_ptr, unsigned char *l_aud_ptr, long l_data_len)
{
  long l_idx;
  unsigned char l_lsb, l_msb;

  /* split stereo 8 bit data from wave data (sequence is  2 bytes left channel, 2 right, 2 left, 2 right ...)
   * into 2 separate datablocks for left and right channel of 16 bit per sample
   */
  l_idx = 0;
  while(l_idx < l_data_len)
  {
    gap_audio_util_dbl_sample_8_to_16(l_aud_ptr[l_idx], &l_lsb, &l_msb);
    l_idx++;
    *(l_left_ptr++)  = l_lsb;
    *(l_left_ptr++)  = l_msb;

    gap_audio_util_dbl_sample_8_to_16(l_aud_ptr[l_idx], &l_lsb, &l_msb);
    l_idx++;
    *(l_left_ptr++)  = l_lsb;
    *(l_left_ptr++)  = l_msb;
  }
}  /* end gap_audio_util_stereo_split8to16 */