diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2010-11-11 22:58:20 +0100 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2010-11-11 22:58:20 +0100 |
commit | 456758c80826bc9f95f9418392fdaed35a81bd04 (patch) | |
tree | ac81a8f276d6b723016e2214f82bbf1c9b0d52ca | |
parent | 9843418a3375ee93197cf9647397aa3e05cd21b8 (diff) |
format: Add support for Raw PCM Signed 16 bits Little Endian
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r-- | include/gapk/formats.h | 3 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/fmt_rawpcm.c | 60 | ||||
-rw-r--r-- | src/formats.c | 2 |
4 files changed, 66 insertions, 0 deletions
diff --git a/include/gapk/formats.h b/include/gapk/formats.h index 89cb8d7..d95dabc 100644 --- a/include/gapk/formats.h +++ b/include/gapk/formats.h @@ -40,6 +40,9 @@ enum format_type { FMT_RACAL_FR, FMT_RACAL_EFR, + /* Raw PCM */ + FMT_RAWPCM_S16LE, + _FMT_MAX, }; diff --git a/src/Makefile.am b/src/Makefile.am index 116985c..dcecac4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,4 +6,5 @@ bin_PROGRAMS = gapk gapk_SOURCES = main.c \ procqueue.c pq_file.c pq_format.c pq_codec.c \ formats.c fmt_amr.c fmt_gsm.c fmt_hr_ref.c fmt_racal.c \ + fmt_rawpcm.c \ codecs.c codec_pcm.c codec_hr.c codec_fr.c codec_efr.c diff --git a/src/fmt_rawpcm.c b/src/fmt_rawpcm.c new file mode 100644 index 0000000..185d0ca --- /dev/null +++ b/src/fmt_rawpcm.c @@ -0,0 +1,60 @@ +/* RAW PCM output */ + +/* + * This file is part of gapk (GSM Audio Pocket Knife). + * + * gapk 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 3 of the License, or + * (at your option) any later version. + * + * gapk 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 gapk. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gapk/codecs.h> +#include <gapk/formats.h> + + +static int +rawpcm_s16le_from_canon(uint8_t *dst, const uint8_t *src) +{ + int i; + const uint16_t *samples = (const uint16_t *)src; + + for (i=0; i<160; i++) { + uint16_t w = samples[i]; + dst[(i<<1) ] = w & 0xff; + dst[(i<<1)+1] = (w >> 8) & 0xff; + } + + return 0; +} + +static int +rawpcm_s16le_to_canon(uint8_t *dst, const uint8_t *src) +{ + int i; + uint16_t *samples = (uint16_t *)dst; + + for (i=0; i<160; i++) + samples[i] = (src[(i<<1)+1] << 8) | src[(i<<1)]; + + return 0; +} + +const struct format_desc fmt_rawpcm_s16le = { + .type = FMT_RAWPCM_S16LE, + .codec_type = CODEC_PCM, + .name = "rawpcm-s16le", + .description = "Raw PCM samples Signed 16 bits little endian", + + .frame_len = 320, + .conv_from_canon = rawpcm_s16le_from_canon, + .conv_to_canon = rawpcm_s16le_to_canon, +}; diff --git a/src/formats.c b/src/formats.c index 8f51c2d..9e5d07b 100644 --- a/src/formats.c +++ b/src/formats.c @@ -30,6 +30,7 @@ extern const struct format_desc fmt_hr_ref_enc; extern const struct format_desc fmt_racal_hr; extern const struct format_desc fmt_racal_fr; extern const struct format_desc fmt_racal_efr; +extern const struct format_desc fmt_rawpcm_s16le; static const struct format_desc *supported_formats[_FMT_MAX] = { [FMT_INVALID] = NULL, @@ -40,6 +41,7 @@ static const struct format_desc *supported_formats[_FMT_MAX] = { [FMT_RACAL_HR] = &fmt_racal_hr, [FMT_RACAL_FR] = &fmt_racal_fr, [FMT_RACAL_EFR] = &fmt_racal_efr, + [FMT_RAWPCM_S16LE] = &fmt_rawpcm_s16le, }; |