format: Add support for Raw PCM Signed 16 bits Little Endian

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2010-11-11 22:58:20 +01:00
parent 9843418a33
commit 456758c808
4 changed files with 66 additions and 0 deletions

View File

@ -40,6 +40,9 @@ enum format_type {
FMT_RACAL_FR,
FMT_RACAL_EFR,
/* Raw PCM */
FMT_RAWPCM_S16LE,
_FMT_MAX,
};

View File

@ -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

60
src/fmt_rawpcm.c Normal file
View File

@ -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,
};

View File

@ -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,
};