Add cyan.theme
[cmus.git] / pcm.c
blobf038be8f0bc81ee4c9fd3e5a69907a8ee4024cc7
1 /*
2 * Copyright 2005 Timo Hirvonen
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #include <pcm.h>
22 #include <inttypes.h>
25 * Functions to convert PCM to 16-bit signed little-endian stereo
27 * Conversion for 8-bit PCM):
28 * 1. phase
29 * unsigned -> signed
30 * mono -> stereo
31 * 8 -> 16
33 * Conversion for 16-bit PCM:
34 * 1. phase
35 * be -> le
36 * unsigned -> signed
38 * 2. phase
39 * mono -> stereo
41 * There's no reason to split 8-bit conversion to 2 phases because we need to
42 * use separate buffer for 8->16 conversion anyway.
44 * Conversions for 16-bit stereo can be done in place. 16-bit mono needs to be
45 * converted to stereo so it's worthwhile to split the conversion to 2 phases.
48 void convert_u8_1ch_to_s16_2ch(char *dst, const char *src, int count)
50 int16_t *d = (int16_t *)dst;
51 const uint8_t *s = (const uint8_t *)src;
52 int i, j = 0;
54 for (i = 0; i < count; i++) {
55 int16_t sample = s[i] << 8;
56 sample -= 32768;
57 d[j++] = sample;
58 d[j++] = sample;
62 void convert_s8_1ch_to_s16_2ch(char *dst, const char *src, int count)
64 int16_t *d = (int16_t *)dst;
65 const int8_t *s = (const int8_t *)src;
66 int i, j = 0;
68 for (i = 0; i < count; i++) {
69 int16_t sample = s[i] << 8;
70 d[j++] = sample;
71 d[j++] = sample;
75 void convert_u8_2ch_to_s16_2ch(char *dst, const char *src, int count)
77 int16_t *d = (int16_t *)dst;
78 const int8_t *s = (const int8_t *)src;
79 int i;
81 for (i = 0; i < count; i++) {
82 int16_t sample = s[i] << 8;
83 sample -= 32768;
84 d[i] = sample;
88 void convert_s8_2ch_to_s16_2ch(char *dst, const char *src, int count)
90 int16_t *d = (int16_t *)dst;
91 const int8_t *s = (const int8_t *)src;
92 int i;
94 for (i = 0; i < count; i++) {
95 int16_t sample = s[i] << 8;
96 d[i] = sample;
100 void convert_u16_le_to_s16_le(char *buf, int count)
102 int16_t *b = (int16_t *)buf;
103 int i;
105 for (i = 0; i < count; i++) {
106 int sample = (uint16_t)b[i];
107 sample -= 32768;
108 b[i] = sample;
112 void convert_u16_be_to_s16_le(char *buf, int count)
114 int16_t *b = (int16_t *)buf;
115 int i;
117 for (i = 0; i < count; i++) {
118 uint16_t u = b[i];
119 int sample;
121 u = (u << 8) | (u >> 8);
122 sample = (int)u - 32768;
123 b[i] = sample;
127 void convert_s16_be_to_s16_le(char *buf, int count)
129 int16_t *b = (int16_t *)buf;
130 int i;
132 for (i = 0; i < count; i++) {
133 uint16_t sample = b[i];
134 b[i] = (sample << 8) | (sample >> 8);
138 void convert_16_1ch_to_16_2ch(char *dst, const char *src, int count)
140 int16_t *d = (int16_t *)dst;
141 const int16_t *s = (const int16_t *)src;
142 int i, j = 0;
144 for (i = 0; i < count; i++) {
145 d[j++] = s[i];
146 d[j++] = s[i];