Sylvain Munaut | 456758c | 2010-11-11 22:58:20 +0100 | [diff] [blame] | 1 | /* RAW PCM output */ |
| 2 | |
| 3 | /* |
| 4 | * This file is part of gapk (GSM Audio Pocket Knife). |
| 5 | * |
| 6 | * gapk 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 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * gapk 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 gapk. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <gapk/codecs.h> |
| 21 | #include <gapk/formats.h> |
| 22 | |
| 23 | |
| 24 | static int |
| 25 | rawpcm_s16le_from_canon(uint8_t *dst, const uint8_t *src) |
| 26 | { |
| 27 | int i; |
| 28 | const uint16_t *samples = (const uint16_t *)src; |
| 29 | |
| 30 | for (i=0; i<160; i++) { |
| 31 | uint16_t w = samples[i]; |
| 32 | dst[(i<<1) ] = w & 0xff; |
| 33 | dst[(i<<1)+1] = (w >> 8) & 0xff; |
| 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static int |
| 40 | rawpcm_s16le_to_canon(uint8_t *dst, const uint8_t *src) |
| 41 | { |
| 42 | int i; |
| 43 | uint16_t *samples = (uint16_t *)dst; |
| 44 | |
| 45 | for (i=0; i<160; i++) |
| 46 | samples[i] = (src[(i<<1)+1] << 8) | src[(i<<1)]; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | const struct format_desc fmt_rawpcm_s16le = { |
| 52 | .type = FMT_RAWPCM_S16LE, |
| 53 | .codec_type = CODEC_PCM, |
| 54 | .name = "rawpcm-s16le", |
| 55 | .description = "Raw PCM samples Signed 16 bits little endian", |
| 56 | |
| 57 | .frame_len = 320, |
| 58 | .conv_from_canon = rawpcm_s16le_from_canon, |
| 59 | .conv_to_canon = rawpcm_s16le_to_canon, |
| 60 | }; |