2006-11-06 18:18:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Base declarations for working with software encoders
|
|
|
|
*
|
2013-06-22 20:41:16 +00:00
|
|
|
* Copyright (C) 2006-2013 Michael Sevakis
|
2006-11-06 18:18:05 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2006-11-06 18:18:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef ENC_BASE_H
|
|
|
|
#define ENC_BASE_H
|
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/** Encoder config structures **/
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2006-11-24 19:49:04 +00:00
|
|
|
/** aiff_enc.codec **/
|
|
|
|
struct aiff_enc_config
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
unsigned long sample_depth;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2006-11-06 18:18:05 +00:00
|
|
|
/** mp3_enc.codec **/
|
|
|
|
#define MP3_BITR_CAP_8 (1 << 0)
|
|
|
|
#define MP3_BITR_CAP_16 (1 << 1)
|
|
|
|
#define MP3_BITR_CAP_24 (1 << 2)
|
|
|
|
#define MP3_BITR_CAP_32 (1 << 3)
|
|
|
|
#define MP3_BITR_CAP_40 (1 << 4)
|
|
|
|
#define MP3_BITR_CAP_48 (1 << 5)
|
|
|
|
#define MP3_BITR_CAP_56 (1 << 6)
|
|
|
|
#define MP3_BITR_CAP_64 (1 << 7)
|
|
|
|
#define MP3_BITR_CAP_80 (1 << 8)
|
|
|
|
#define MP3_BITR_CAP_96 (1 << 9)
|
|
|
|
#define MP3_BITR_CAP_112 (1 << 10)
|
|
|
|
#define MP3_BITR_CAP_128 (1 << 11)
|
|
|
|
#define MP3_BITR_CAP_144 (1 << 12)
|
|
|
|
#define MP3_BITR_CAP_160 (1 << 13)
|
|
|
|
#define MP3_BITR_CAP_192 (1 << 14)
|
|
|
|
#define MP3_BITR_CAP_224 (1 << 15)
|
|
|
|
#define MP3_BITR_CAP_256 (1 << 16)
|
|
|
|
#define MP3_BITR_CAP_320 (1 << 17)
|
|
|
|
#define MP3_ENC_NUM_BITR 18
|
|
|
|
|
|
|
|
/* MPEG 1 */
|
|
|
|
#define MPEG1_SAMPR_CAPS (SAMPR_CAP_32 | SAMPR_CAP_48 | SAMPR_CAP_44)
|
2013-06-22 20:41:16 +00:00
|
|
|
#define MPEG1_BITR_CAPS (MP3_BITR_CAP_32 | MP3_BITR_CAP_40 | \
|
|
|
|
MP3_BITR_CAP_48 | MP3_BITR_CAP_56 | \
|
|
|
|
MP3_BITR_CAP_64 | MP3_BITR_CAP_80 | \
|
|
|
|
MP3_BITR_CAP_96 | MP3_BITR_CAP_112 | \
|
|
|
|
MP3_BITR_CAP_128 | MP3_BITR_CAP_160 | \
|
|
|
|
MP3_BITR_CAP_192 | MP3_BITR_CAP_224 | \
|
2006-11-06 18:18:05 +00:00
|
|
|
MP3_BITR_CAP_256 | MP3_BITR_CAP_320)
|
|
|
|
|
|
|
|
/* MPEG 2 */
|
|
|
|
#define MPEG2_SAMPR_CAPS (SAMPR_CAP_22 | SAMPR_CAP_24 | SAMPR_CAP_16)
|
2013-06-22 20:41:16 +00:00
|
|
|
#define MPEG2_BITR_CAPS (MP3_BITR_CAP_8 | MP3_BITR_CAP_16 | \
|
|
|
|
MP3_BITR_CAP_24 | MP3_BITR_CAP_32 | \
|
|
|
|
MP3_BITR_CAP_40 | MP3_BITR_CAP_48 | \
|
|
|
|
MP3_BITR_CAP_56 | MP3_BITR_CAP_64 | \
|
|
|
|
MP3_BITR_CAP_80 | MP3_BITR_CAP_96 | \
|
|
|
|
MP3_BITR_CAP_112 | MP3_BITR_CAP_128 | \
|
2006-11-06 18:18:05 +00:00
|
|
|
MP3_BITR_CAP_144 | MP3_BITR_CAP_160)
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* MPEG 2.5 */
|
|
|
|
#define MPEG2_5_SAMPR_CAPS (SAMPR_CAP_8 | SAMPR_CAP_12 | SAMPR_CAP_11)
|
|
|
|
#define MPEG2_5_BITR_CAPS MPEG2_BITR_CAPS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HAVE_MPEG* defines mainly apply to the bitrate menu */
|
2007-06-06 21:24:20 +00:00
|
|
|
#if (REC_SAMPR_CAPS & MPEG1_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
|
|
|
|
#define HAVE_MPEG1_SAMPR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (REC_SAMPR_CAPS & MPEG2_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
|
2006-11-06 18:18:05 +00:00
|
|
|
#define HAVE_MPEG2_SAMPR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2007-06-06 21:24:20 +00:00
|
|
|
#if (REC_SAMPR_CAPS & MPEG2_5_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
|
2006-11-06 18:18:05 +00:00
|
|
|
#define HAVE_MPEG2_5_SAMPR
|
|
|
|
#endif
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
|
|
#define MP3_ENC_SAMPR_CAPS (MPEG1_SAMPR_CAPS | MPEG2_SAMPR_CAPS)
|
|
|
|
|
|
|
|
/* This number is count of full encoder set */
|
|
|
|
#define MP3_ENC_NUM_SAMPR 6
|
|
|
|
|
2011-12-14 21:45:25 +00:00
|
|
|
#if 0
|
2006-11-06 18:18:05 +00:00
|
|
|
extern const unsigned long mp3_enc_sampr[MP3_ENC_NUM_SAMPR];
|
2011-12-14 21:45:25 +00:00
|
|
|
#endif
|
2006-11-06 18:18:05 +00:00
|
|
|
extern const unsigned long mp3_enc_bitr[MP3_ENC_NUM_BITR];
|
|
|
|
|
|
|
|
struct mp3_enc_config
|
|
|
|
{
|
|
|
|
unsigned long bitrate;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MP3_ENC_BITRATE_CFG_DEFAULT 11 /* 128 */
|
|
|
|
#define MP3_ENC_BITRATE_CFG_VALUE_LIST "8,16,24,32,40,48,56,64,80,96," \
|
|
|
|
"112,128,144,160,192,224,256,320"
|
|
|
|
|
|
|
|
/** wav_enc.codec **/
|
|
|
|
#define WAV_ENC_SAMPR_CAPS SAMPR_CAP_ALL
|
|
|
|
|
|
|
|
struct wav_enc_config
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
unsigned long sample_depth;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/** wavpack_enc.codec **/
|
|
|
|
#define WAVPACK_ENC_SAMPR_CAPS SAMPR_CAP_ALL
|
|
|
|
|
|
|
|
struct wavpack_enc_config
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
unsigned long sample_depth;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* General config information about any encoder */
|
2006-11-06 18:18:05 +00:00
|
|
|
struct encoder_config
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
/* states which *_enc_config member is valid */
|
|
|
|
int rec_format; /* REC_FORMAT_* value */
|
|
|
|
int afmt; /* AFMT_* value */
|
|
|
|
};
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct mp3_enc_config mp3_enc;
|
|
|
|
struct wavpack_enc_config wavpack_enc;
|
|
|
|
struct wav_enc_config wav_enc;
|
2013-06-22 20:39:40 +00:00
|
|
|
};
|
2006-11-06 18:18:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Encoder chunk macros and definitions **/
|
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* What sort of data does the header describe? */
|
|
|
|
enum CHUNK_T
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2013-06-22 20:41:16 +00:00
|
|
|
CHUNK_T_DATA = 0x0, /* Encoded audio data */
|
|
|
|
CHUNK_T_STREAM_START = 0x1, /* Stream start marker */
|
|
|
|
CHUNK_T_STREAM_END = 0x2, /* Stream end marker */
|
|
|
|
CHUNK_T_WRAP = 0x3 /* Buffer early wrap marker */
|
2006-11-06 18:18:05 +00:00
|
|
|
};
|
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* Header for every buffer slot and chunk */
|
|
|
|
union enc_chunk_hdr
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2013-06-22 20:41:16 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32_t type : 2; /* Chunk type (CHUNK_T_*) */
|
|
|
|
uint32_t err : 1; /* Encoder error */
|
|
|
|
uint32_t pre : 1; /* Chunk is prerecorded data */
|
|
|
|
uint32_t aux0 : 1; /* Aux flag 0 - for encoder */
|
|
|
|
uint32_t unused : 3; /* */
|
|
|
|
uint32_t size : 24; /* size of data */
|
|
|
|
};
|
|
|
|
uint32_t zero; /* Zero-out struct access */
|
|
|
|
intptr_t reserved1; /* Want it at least pointer-sized */
|
|
|
|
} __attribute__((__may_alias__));
|
|
|
|
|
|
|
|
#define ENC_HDR_SIZE (sizeof (union enc_chunk_hdr))
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* When hdr.type is CHUNK_T_STREAM_START */
|
|
|
|
struct enc_chunk_file
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2013-06-22 20:41:16 +00:00
|
|
|
union enc_chunk_hdr hdr; /* This chunk's header */
|
|
|
|
/* hdr.size = slot count of chunk */
|
|
|
|
char path[]; /* NULL-terminated path of file */
|
|
|
|
} __attribute__((__may_alias__));
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* If flags = CHUNK_T_STREAM_END, just the header exists */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* When hdr.type is CHUNK_T_DATA */
|
|
|
|
struct enc_chunk_data
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2013-06-22 20:41:16 +00:00
|
|
|
union enc_chunk_hdr hdr; /* IN,OUT: This chunk's header */
|
|
|
|
/* hdr.size = total size of data[] */
|
|
|
|
uint32_t pcm_count; /* OUT: number of PCM samples encoded */
|
|
|
|
uint8_t data[]; /* OUT: encoded audio data */
|
|
|
|
} __attribute__((__may_alias__));
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* CHUNK_T_STREAM_END and CHUNK_T_WRAP consist of only the header */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
#define ENC_FILE_HDR(hdr) ((struct enc_chunk_file *)(hdr))
|
|
|
|
#define ENC_DATA_HDR(hdr) ((struct enc_chunk_data *)(hdr))
|
|
|
|
|
|
|
|
/* Audio and encoder stream parameters */
|
|
|
|
struct enc_inputs
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
|
|
|
/* IN parameters */
|
2013-06-22 20:41:16 +00:00
|
|
|
unsigned long sample_rate; /* PCM samplerate setting */
|
|
|
|
int num_channels; /* Number of audio channels */
|
|
|
|
struct encoder_config *config; /* Encoder settings */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
/* IN,OUT parameters */
|
|
|
|
unsigned long enc_sample_rate; /* Actual sample rate accepted by encoder
|
|
|
|
(for recorded time calculation) */
|
|
|
|
};
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
enum enc_callback_reason
|
|
|
|
{
|
|
|
|
ENC_CB_INPUTS, /* 'params' is struct enc_inputs * */
|
|
|
|
ENC_CB_STREAM, /* 'params' is union enc_chunk_hdr * */
|
|
|
|
};
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2013-06-22 20:41:16 +00:00
|
|
|
typedef int (* enc_callback_t)(enum enc_callback_reason reason, void *params);
|
2006-11-06 18:18:05 +00:00
|
|
|
|
|
|
|
#endif /* ENC_BASE_H */
|