mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
b159a7b095 | |||
be234dc464 | |||
c9ac59e8d3 | |||
9b8f9915c2 | |||
5ccbfaa710 | |||
8f05e0751b | |||
053279541b | |||
f48bf1294c | |||
8896249ac5 | |||
5f0d784cd3 | |||
6a3b77de8e | |||
1af8624b00 | |||
29a8f73faf | |||
3b666b7546 | |||
8cb6378fca | |||
bd8c9a5d15 | |||
91ef87b610 |
30
ChangeLog
30
ChangeLog
@ -1,6 +1,32 @@
|
|||||||
|
2013-10-25 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* update ChangeLog [HEAD]
|
||||||
|
|
||||||
|
* bump version [v0.4.0]
|
||||||
|
|
||||||
|
* update README
|
||||||
|
|
||||||
|
2013-10-24 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* caf input support
|
||||||
|
|
||||||
|
* refactor pcm io routines
|
||||||
|
|
||||||
|
2013-10-23 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* cleanup metadata handling
|
||||||
|
|
||||||
|
* --tag-from-json: properly support number/total format in json track field
|
||||||
|
|
||||||
|
2013-10-22 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.3.3]
|
||||||
|
|
||||||
|
* fixed bogus sgpd written on --gapless-mode=1 and 2
|
||||||
|
|
||||||
2013-10-21 nu774 <honeycomb77@gmail.com>
|
2013-10-21 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
* bump version [HEAD]
|
* bump version [v0.3.2]
|
||||||
|
|
||||||
2013-10-20 nu774 <honeycomb77@gmail.com>
|
2013-10-20 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
@ -12,7 +38,7 @@
|
|||||||
|
|
||||||
2013-10-19 nu774 <honeycomb77@gmail.com>
|
2013-10-19 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
* update ChangeLog and git2changelog.py [origin/master]
|
* update ChangeLog and git2changelog.py
|
||||||
|
|
||||||
2013-10-18 nu774 <honeycomb77@gmail.com>
|
2013-10-18 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
@ -96,12 +96,14 @@ copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\missings\getopt.c" />
|
<ClCompile Include="..\missings\getopt.c" />
|
||||||
<ClCompile Include="..\src\aacenc.c" />
|
<ClCompile Include="..\src\aacenc.c" />
|
||||||
|
<ClCompile Include="..\src\caf_reader.c" />
|
||||||
<ClCompile Include="..\src\compat_win32.c" />
|
<ClCompile Include="..\src\compat_win32.c" />
|
||||||
<ClCompile Include="..\src\lpcm.c" />
|
<ClCompile Include="..\src\lpcm.c" />
|
||||||
<ClCompile Include="..\src\m4af.c" />
|
<ClCompile Include="..\src\m4af.c" />
|
||||||
<ClCompile Include="..\src\main.c" />
|
<ClCompile Include="..\src\main.c" />
|
||||||
<ClCompile Include="..\src\metadata.c" />
|
<ClCompile Include="..\src\metadata.c" />
|
||||||
<ClCompile Include="..\src\parson.c" />
|
<ClCompile Include="..\src\parson.c" />
|
||||||
|
<ClCompile Include="..\src\pcm_readhelper.c" />
|
||||||
<ClCompile Include="..\src\pcm_sint16_converter.c" />
|
<ClCompile Include="..\src\pcm_sint16_converter.c" />
|
||||||
<ClCompile Include="..\src\progress.c" />
|
<ClCompile Include="..\src\progress.c" />
|
||||||
<ClCompile Include="..\src\wav_reader.c" />
|
<ClCompile Include="..\src\wav_reader.c" />
|
||||||
@ -115,6 +117,7 @@ copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
|||||||
<ClInclude Include="..\src\m4af_endian.h" />
|
<ClInclude Include="..\src\m4af_endian.h" />
|
||||||
<ClInclude Include="..\src\metadata.h" />
|
<ClInclude Include="..\src\metadata.h" />
|
||||||
<ClInclude Include="..\src\parson.h" />
|
<ClInclude Include="..\src\parson.h" />
|
||||||
|
<ClInclude Include="..\src\pcm_reader.h" />
|
||||||
<ClInclude Include="..\src\progress.h" />
|
<ClInclude Include="..\src\progress.h" />
|
||||||
<ClInclude Include="..\src\wav_reader.h" />
|
<ClInclude Include="..\src\wav_reader.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
<ClCompile Include="..\src\aacenc.c">
|
<ClCompile Include="..\src\aacenc.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\caf_reader.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\src\compat_win32.c">
|
<ClCompile Include="..\src\compat_win32.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -30,6 +33,12 @@
|
|||||||
<ClCompile Include="..\src\main.c">
|
<ClCompile Include="..\src\main.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\pcm_readhelper.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\pcm_sint16_converter.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\src\progress.c">
|
<ClCompile Include="..\src\progress.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -44,6 +53,12 @@
|
|||||||
<ClInclude Include="..\src\aacenc.h">
|
<ClInclude Include="..\src\aacenc.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\caf_reader.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\catypes.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\compat.h">
|
<ClInclude Include="..\src\compat.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -5,11 +5,13 @@ bin_PROGRAMS = fdkaac
|
|||||||
|
|
||||||
fdkaac_SOURCES = \
|
fdkaac_SOURCES = \
|
||||||
src/aacenc.c \
|
src/aacenc.c \
|
||||||
|
src/caf_reader.c \
|
||||||
src/lpcm.c \
|
src/lpcm.c \
|
||||||
src/m4af.c \
|
src/m4af.c \
|
||||||
src/main.c \
|
src/main.c \
|
||||||
src/metadata.c \
|
src/metadata.c \
|
||||||
src/parson.c \
|
src/parson.c \
|
||||||
|
src/pcm_readhelper.c \
|
||||||
src/pcm_sint16_converter.c \
|
src/pcm_sint16_converter.c \
|
||||||
src/progress.c \
|
src/progress.c \
|
||||||
src/wav_reader.c
|
src/wav_reader.c
|
||||||
|
13
README
13
README
@ -34,9 +34,16 @@ MSVC solution for Visual Studio 2010 is under MSVC directory.
|
|||||||
|
|
||||||
Available input format
|
Available input format
|
||||||
----------------------
|
----------------------
|
||||||
WAV (or RF64), upto 32bit int / 64bit float format is supported.
|
WAV, RF64, CAF, RAW, upto 32bit int / 64bit float format is supported.
|
||||||
However, since FDK AAC encoder is implemented based on fixed point integer,
|
Metadata in CAF info chunk can be read and copied to the resulting m4a.
|
||||||
encoder itself treats 16bit input only.
|
This is especially useful and works well when you pipe from ffmpeg via CAF.
|
||||||
|
For example, you can copy tag from original "foo.flac" to "foo.m4a"
|
||||||
|
through the following pipeline:
|
||||||
|
|
||||||
|
$ ffmpeg -i foo.flac -f caf - | fdkaac -m3 - -o foo.m4a
|
||||||
|
|
||||||
|
Since FDK AAC encoder is implemented based on fixed point integer,
|
||||||
|
encoder itself handles 16bit input only.
|
||||||
Therefore, when feeding non-integer input, be careful so that input doesn't
|
Therefore, when feeding non-integer input, be careful so that input doesn't
|
||||||
exceed 0dBFS to avoid hard clips.
|
exceed 0dBFS to avoid hard clips.
|
||||||
You might also want to apply dither/noise shape beforehand when your input
|
You might also want to apply dither/noise shape beforehand when your input
|
||||||
|
63
src/aacenc.c
63
src/aacenc.c
@ -10,6 +10,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "aacenc.h"
|
#include "aacenc.h"
|
||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
||||||
@ -25,6 +26,68 @@ int aacenc_is_sbr_active(const aacenc_param_t *params)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const unsigned aacenc_sampling_freq_tab[] = {
|
||||||
|
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
||||||
|
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static
|
||||||
|
unsigned sampling_freq_index(unsigned rate)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; aacenc_sampling_freq_tab[i]; ++i)
|
||||||
|
if (aacenc_sampling_freq_tab[i] == rate)
|
||||||
|
return i;
|
||||||
|
return 0xf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append backward compatible SBR/PS signaling to implicit signaling ASC,
|
||||||
|
* if SBR/PS is present.
|
||||||
|
*/
|
||||||
|
int aacenc_mp4asc(const aacenc_param_t *params,
|
||||||
|
const uint8_t *asc, uint32_t ascsize,
|
||||||
|
uint8_t *outasc, uint32_t *outsize)
|
||||||
|
{
|
||||||
|
unsigned asc_sfreq = aacenc_sampling_freq_tab[(asc[0]&0x7)<<1 |asc[1]>>7];
|
||||||
|
|
||||||
|
switch (params->profile) {
|
||||||
|
case AOT_SBR:
|
||||||
|
case AOT_PS:
|
||||||
|
if (*outsize < ascsize + 3)
|
||||||
|
return -1;
|
||||||
|
memcpy(outasc, asc, ascsize);
|
||||||
|
/* syncExtensionType:11 (value:0x2b7) */
|
||||||
|
outasc[ascsize+0] = 0x2b << 1;
|
||||||
|
outasc[ascsize+1] = 0x7 << 5;
|
||||||
|
/* extensionAudioObjectType:5 (value:5)*/
|
||||||
|
outasc[ascsize+1] |= 5;
|
||||||
|
/* sbrPresentFlag:1 (value:1) */
|
||||||
|
outasc[ascsize+2] = 0x80;
|
||||||
|
/* extensionSamplingFrequencyIndex:4 */
|
||||||
|
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << 1) << 3;
|
||||||
|
if (params->profile == AOT_SBR) {
|
||||||
|
*outsize = ascsize + 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (*outsize < ascsize + 5)
|
||||||
|
return -1;
|
||||||
|
/* syncExtensionType:11 (value:0x548) */
|
||||||
|
outasc[ascsize+2] |= 0x5;
|
||||||
|
outasc[ascsize+3] = 0x48;
|
||||||
|
/* psPresentFlag:1 (value:1) */
|
||||||
|
outasc[ascsize+4] = 0x80;
|
||||||
|
*outsize = ascsize + 5;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (*outsize < ascsize)
|
||||||
|
return -1;
|
||||||
|
memcpy(outasc, asc, ascsize);
|
||||||
|
*outsize = ascsize;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int aacenc_channel_mode(const pcm_sample_description_t *format)
|
int aacenc_channel_mode(const pcm_sample_description_t *format)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,10 @@ typedef struct aacenc_param_t {
|
|||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
||||||
|
|
||||||
|
int aacenc_mp4asc(const aacenc_param_t *params,
|
||||||
|
const uint8_t *asc, uint32_t ascsize,
|
||||||
|
uint8_t *outasc, uint32_t *outsize);
|
||||||
|
|
||||||
int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
||||||
const pcm_sample_description_t *format,
|
const pcm_sample_description_t *format,
|
||||||
AACENC_InfoStruct *info);
|
AACENC_InfoStruct *info);
|
||||||
|
253
src/caf_reader.c
Normal file
253
src/caf_reader.c
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "caf_reader.h"
|
||||||
|
#include "m4af.h"
|
||||||
|
|
||||||
|
typedef struct caf_reader_t {
|
||||||
|
pcm_reader_vtbl_t *vtbl;
|
||||||
|
pcm_sample_description_t sample_format;
|
||||||
|
int64_t length;
|
||||||
|
int64_t position;
|
||||||
|
int64_t data_offset;
|
||||||
|
pcm_io_context_t io;
|
||||||
|
aacenc_tag_callback_t tag_callback;
|
||||||
|
void *tag_ctx;
|
||||||
|
uint8_t chanmap[8];
|
||||||
|
} caf_reader_t;
|
||||||
|
|
||||||
|
static const pcm_sample_description_t *caf_get_format(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return &((caf_reader_t *)reader)->sample_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int64_t caf_get_length(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return ((caf_reader_t *)reader)->length;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int64_t caf_get_position(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return ((caf_reader_t *)reader)->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void caf_teardown(pcm_reader_t **reader)
|
||||||
|
{
|
||||||
|
free(*reader);
|
||||||
|
*reader = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
uint32_t caf_next_chunk(caf_reader_t *reader, int64_t *chunk_size)
|
||||||
|
{
|
||||||
|
uint32_t fcc;
|
||||||
|
if (pcm_scanb(&reader->io, "LQ", &fcc, chunk_size) == 2)
|
||||||
|
return fcc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int caf_desc(caf_reader_t *reader, int64_t chunk_size)
|
||||||
|
{
|
||||||
|
double mSampleRate;
|
||||||
|
uint32_t mFormatID, mFormatFlags, mBytesPerPacket, mFramesPerPacket,
|
||||||
|
mChannelsPerFrame, mBitsPerChannel;
|
||||||
|
pcm_sample_description_t *desc = &reader->sample_format;
|
||||||
|
|
||||||
|
ENSURE(chunk_size >= 32);
|
||||||
|
TRY_IO(pcm_scanb(&reader->io, "QLLLLLL", &mSampleRate, &mFormatID,
|
||||||
|
&mFormatFlags, &mBytesPerPacket, &mFramesPerPacket,
|
||||||
|
&mChannelsPerFrame, &mBitsPerChannel) != 7);
|
||||||
|
|
||||||
|
ENSURE(mFormatID == M4AF_FOURCC('l','p','c','m'));
|
||||||
|
ENSURE(mSampleRate && mBytesPerPacket &&
|
||||||
|
mChannelsPerFrame >= 1 && mChannelsPerFrame <= 8 &&
|
||||||
|
mBitsPerChannel && mFramesPerPacket == 1 &&
|
||||||
|
mBytesPerPacket % mChannelsPerFrame == 0 &&
|
||||||
|
mBytesPerPacket >= mChannelsPerFrame * ((mBitsPerChannel + 7) / 8));
|
||||||
|
|
||||||
|
desc->sample_rate = mSampleRate;
|
||||||
|
desc->bits_per_channel = mBitsPerChannel;
|
||||||
|
desc->bytes_per_frame = mBytesPerPacket;
|
||||||
|
desc->channels_per_frame = mChannelsPerFrame;
|
||||||
|
|
||||||
|
switch (mFormatFlags) {
|
||||||
|
case 0: desc->sample_type = PCM_TYPE_SINT_BE; break;
|
||||||
|
case 1: desc->sample_type = PCM_TYPE_FLOAT_BE; break;
|
||||||
|
case 2: desc->sample_type = PCM_TYPE_SINT; break;
|
||||||
|
case 3: desc->sample_type = PCM_TYPE_FLOAT; break;
|
||||||
|
default: goto FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRY_IO(pcm_skip(&reader->io, chunk_size - 32));
|
||||||
|
return 0;
|
||||||
|
FAIL:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int caf_info(caf_reader_t *reader, int64_t chunk_size)
|
||||||
|
{
|
||||||
|
char *buf, *key, *val, *end;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (chunk_size < 4 || (buf = malloc(chunk_size)) == 0)
|
||||||
|
return -1;
|
||||||
|
pcm_read(&reader->io, buf, chunk_size);
|
||||||
|
key = buf + 4;
|
||||||
|
end = buf + chunk_size;
|
||||||
|
do {
|
||||||
|
if ((val = key + strlen(key) + 1) < end) {
|
||||||
|
len = strlen(val);
|
||||||
|
if (reader->tag_callback)
|
||||||
|
reader->tag_callback(reader->tag_ctx, key, val, len);
|
||||||
|
key = val + len + 1;
|
||||||
|
}
|
||||||
|
} while (key < end && val < end);
|
||||||
|
|
||||||
|
if (reader->tag_callback)
|
||||||
|
reader->tag_callback(reader->tag_ctx, 0, 0, 0);
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int caf_read_frames(pcm_reader_t *preader, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
unsigned i, j, nbytes;
|
||||||
|
caf_reader_t *reader = (caf_reader_t *)preader;
|
||||||
|
unsigned bpf = reader->sample_format.bytes_per_frame;
|
||||||
|
unsigned nchannels = reader->sample_format.channels_per_frame;
|
||||||
|
unsigned bpc = bpf / nchannels;
|
||||||
|
uint8_t tmp[64]; /* enough room for maximum bpf: 8ch float64 */
|
||||||
|
uint8_t *bp;
|
||||||
|
uint8_t *chanmap = reader->chanmap;
|
||||||
|
|
||||||
|
if (nframes > reader->length - reader->position)
|
||||||
|
nframes = reader->length - reader->position;
|
||||||
|
nbytes = nframes * bpf;
|
||||||
|
if (nbytes) {
|
||||||
|
if ((rc = pcm_read(&reader->io, buffer, nbytes)) < 0)
|
||||||
|
return -1;
|
||||||
|
nframes = rc / bpf;
|
||||||
|
for (bp = buffer, i = 0; i < nframes; ++i, bp += bpf) {
|
||||||
|
memcpy(tmp, bp, bpf);
|
||||||
|
for (j = 0; j < nchannels; ++j)
|
||||||
|
memcpy(bp + bpc * j, tmp + bpc * chanmap[j], bpc);
|
||||||
|
}
|
||||||
|
reader->position += nframes;
|
||||||
|
}
|
||||||
|
if (nframes == 0) {
|
||||||
|
/* fetch info after data chunk */
|
||||||
|
uint32_t fcc;
|
||||||
|
int64_t chunk_size;
|
||||||
|
while ((fcc = caf_next_chunk(reader, &chunk_size)) != 0) {
|
||||||
|
if (fcc == M4AF_FOURCC('i','n','f','o'))
|
||||||
|
TRY_IO(caf_info(reader, chunk_size));
|
||||||
|
else
|
||||||
|
TRY_IO(pcm_skip(&reader->io, chunk_size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nframes;
|
||||||
|
FAIL:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int caf_parse(caf_reader_t *reader, int64_t *data_length)
|
||||||
|
{
|
||||||
|
uint32_t fcc;
|
||||||
|
int64_t chunk_size;
|
||||||
|
|
||||||
|
*data_length = 0;
|
||||||
|
|
||||||
|
/* CAFFileHeader */
|
||||||
|
TRY_IO(pcm_read32be(&reader->io, &fcc));
|
||||||
|
ENSURE(fcc == M4AF_FOURCC('c','a','f','f'));
|
||||||
|
TRY_IO(pcm_skip(&reader->io, 4)); /* mFileVersion, mFileFlags */
|
||||||
|
|
||||||
|
while ((fcc = caf_next_chunk(reader, &chunk_size)) != 0) {
|
||||||
|
if (fcc == M4AF_FOURCC('d','e','s','c'))
|
||||||
|
TRY_IO(caf_desc(reader, chunk_size));
|
||||||
|
else if (fcc == M4AF_FOURCC('i','n','f','o'))
|
||||||
|
TRY_IO(caf_info(reader, chunk_size));
|
||||||
|
else if (fcc == M4AF_FOURCC('c','h','a','n')) {
|
||||||
|
ENSURE(reader->sample_format.channels_per_frame);
|
||||||
|
if (apple_chan_chunk(&reader->io, chunk_size,
|
||||||
|
&reader->sample_format, reader->chanmap) < 0)
|
||||||
|
goto FAIL;
|
||||||
|
} else if (fcc == M4AF_FOURCC('d','a','t','a')) {
|
||||||
|
TRY_IO(pcm_skip(&reader->io, 4)); /* mEditCount */
|
||||||
|
*data_length = (chunk_size == ~0ULL) ? chunk_size : chunk_size - 4;
|
||||||
|
reader->data_offset += 12;
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
TRY_IO(pcm_skip(&reader->io, chunk_size));
|
||||||
|
|
||||||
|
reader->data_offset += (chunk_size + 8);
|
||||||
|
}
|
||||||
|
ENSURE(reader->sample_format.channels_per_frame);
|
||||||
|
ENSURE(fcc == M4AF_FOURCC('d','a','t','a'));
|
||||||
|
return 0;
|
||||||
|
FAIL:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static pcm_reader_vtbl_t caf_vtable = {
|
||||||
|
caf_get_format,
|
||||||
|
caf_get_length,
|
||||||
|
caf_get_position,
|
||||||
|
caf_read_frames,
|
||||||
|
caf_teardown
|
||||||
|
};
|
||||||
|
|
||||||
|
pcm_reader_t *caf_open(pcm_io_context_t *io,
|
||||||
|
aacenc_tag_callback_t tag_callback, void *tag_ctx)
|
||||||
|
{
|
||||||
|
caf_reader_t *reader = 0;
|
||||||
|
int64_t data_length;
|
||||||
|
unsigned bpf;
|
||||||
|
|
||||||
|
if ((reader = calloc(1, sizeof(caf_reader_t))) == 0)
|
||||||
|
return 0;
|
||||||
|
memcpy(&reader->io, io, sizeof(pcm_io_context_t));
|
||||||
|
reader->tag_callback = tag_callback;
|
||||||
|
reader->tag_ctx = tag_ctx;
|
||||||
|
|
||||||
|
if (caf_parse(reader, &data_length) < 0) {
|
||||||
|
free(reader);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bpf = reader->sample_format.bytes_per_frame;
|
||||||
|
|
||||||
|
/* CAF uses -1 to indicate "unknown size" */
|
||||||
|
if (data_length < 0 || data_length % bpf)
|
||||||
|
reader->length = INT64_MAX;
|
||||||
|
else
|
||||||
|
reader->length = data_length / bpf;
|
||||||
|
|
||||||
|
if (reader->length == INT64_MAX) {
|
||||||
|
if (pcm_seek(&reader->io, 0, SEEK_END) >= 0) {
|
||||||
|
int64_t size = pcm_tell(&reader->io);
|
||||||
|
if (size > 0)
|
||||||
|
reader->length = (size - reader->data_offset) / bpf;
|
||||||
|
pcm_seek(&reader->io, reader->data_offset, SEEK_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader->vtbl = &caf_vtable;
|
||||||
|
return (pcm_reader_t *)reader;
|
||||||
|
}
|
15
src/caf_reader.h
Normal file
15
src/caf_reader.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
|
#ifndef CAF_READER_H
|
||||||
|
#define CAF_READER_H
|
||||||
|
|
||||||
|
#include "lpcm.h"
|
||||||
|
#include "pcm_reader.h"
|
||||||
|
#include "metadata.h"
|
||||||
|
|
||||||
|
pcm_reader_t *caf_open(pcm_io_context_t *io,
|
||||||
|
aacenc_tag_callback_t tag_callback, void *tag_ctx);
|
||||||
|
|
||||||
|
#endif
|
241
src/catypes.h
Normal file
241
src/catypes.h
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
#if !defined(__CoreAudioTypes_h__)
|
||||||
|
#define __CoreAudioTypes_h__
|
||||||
|
|
||||||
|
enum { kVariableLengthArray = 1 };
|
||||||
|
|
||||||
|
typedef uint32_t AudioChannelLabel;
|
||||||
|
typedef uint32_t AudioChannelLayoutTag;
|
||||||
|
|
||||||
|
struct AudioChannelDescription
|
||||||
|
{
|
||||||
|
AudioChannelLabel mChannelLabel;
|
||||||
|
uint32_t mChannelFlags;
|
||||||
|
float mCoordinates[3];
|
||||||
|
};
|
||||||
|
typedef struct AudioChannelDescription AudioChannelDescription;
|
||||||
|
|
||||||
|
struct AudioChannelLayout
|
||||||
|
{
|
||||||
|
AudioChannelLayoutTag mChannelLayoutTag;
|
||||||
|
uint32_t mChannelBitmap;
|
||||||
|
uint32_t mNumberChannelDescriptions;
|
||||||
|
AudioChannelDescription mChannelDescriptions[kVariableLengthArray];
|
||||||
|
};
|
||||||
|
typedef struct AudioChannelLayout AudioChannelLayout;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kAudioChannelLabel_Unknown = 0xFFFFFFFF, // unknown or unspecified other use
|
||||||
|
kAudioChannelLabel_Unused = 0, // channel is present, but has no intended use or destination
|
||||||
|
kAudioChannelLabel_UseCoordinates = 100, // channel is described by the mCoordinates fields.
|
||||||
|
|
||||||
|
kAudioChannelLabel_Left = 1,
|
||||||
|
kAudioChannelLabel_Right = 2,
|
||||||
|
kAudioChannelLabel_Center = 3,
|
||||||
|
kAudioChannelLabel_LFEScreen = 4,
|
||||||
|
kAudioChannelLabel_LeftSurround = 5, // WAVE: "Back Left"
|
||||||
|
kAudioChannelLabel_RightSurround = 6, // WAVE: "Back Right"
|
||||||
|
kAudioChannelLabel_LeftCenter = 7,
|
||||||
|
kAudioChannelLabel_RightCenter = 8,
|
||||||
|
kAudioChannelLabel_CenterSurround = 9, // WAVE: "Back Center" or plain "Rear Surround"
|
||||||
|
kAudioChannelLabel_LeftSurroundDirect = 10, // WAVE: "Side Left"
|
||||||
|
kAudioChannelLabel_RightSurroundDirect = 11, // WAVE: "Side Right"
|
||||||
|
kAudioChannelLabel_TopCenterSurround = 12,
|
||||||
|
kAudioChannelLabel_VerticalHeightLeft = 13, // WAVE: "Top Front Left"
|
||||||
|
kAudioChannelLabel_VerticalHeightCenter = 14, // WAVE: "Top Front Center"
|
||||||
|
kAudioChannelLabel_VerticalHeightRight = 15, // WAVE: "Top Front Right"
|
||||||
|
|
||||||
|
kAudioChannelLabel_TopBackLeft = 16,
|
||||||
|
kAudioChannelLabel_TopBackCenter = 17,
|
||||||
|
kAudioChannelLabel_TopBackRight = 18,
|
||||||
|
|
||||||
|
kAudioChannelLabel_RearSurroundLeft = 33,
|
||||||
|
kAudioChannelLabel_RearSurroundRight = 34,
|
||||||
|
kAudioChannelLabel_LeftWide = 35,
|
||||||
|
kAudioChannelLabel_RightWide = 36,
|
||||||
|
kAudioChannelLabel_LFE2 = 37,
|
||||||
|
kAudioChannelLabel_LeftTotal = 38, // matrix encoded 4 channels
|
||||||
|
kAudioChannelLabel_RightTotal = 39, // matrix encoded 4 channels
|
||||||
|
kAudioChannelLabel_HearingImpaired = 40,
|
||||||
|
kAudioChannelLabel_Narration = 41,
|
||||||
|
kAudioChannelLabel_Mono = 42,
|
||||||
|
kAudioChannelLabel_DialogCentricMix = 43,
|
||||||
|
|
||||||
|
kAudioChannelLabel_CenterSurroundDirect = 44, // back center, non diffuse
|
||||||
|
|
||||||
|
kAudioChannelLabel_Haptic = 45,
|
||||||
|
|
||||||
|
// first order ambisonic channels
|
||||||
|
kAudioChannelLabel_Ambisonic_W = 200,
|
||||||
|
kAudioChannelLabel_Ambisonic_X = 201,
|
||||||
|
kAudioChannelLabel_Ambisonic_Y = 202,
|
||||||
|
kAudioChannelLabel_Ambisonic_Z = 203,
|
||||||
|
|
||||||
|
// Mid/Side Recording
|
||||||
|
kAudioChannelLabel_MS_Mid = 204,
|
||||||
|
kAudioChannelLabel_MS_Side = 205,
|
||||||
|
|
||||||
|
// X-Y Recording
|
||||||
|
kAudioChannelLabel_XY_X = 206,
|
||||||
|
kAudioChannelLabel_XY_Y = 207,
|
||||||
|
|
||||||
|
// other
|
||||||
|
kAudioChannelLabel_HeadphonesLeft = 301,
|
||||||
|
kAudioChannelLabel_HeadphonesRight = 302,
|
||||||
|
kAudioChannelLabel_ClickTrack = 304,
|
||||||
|
kAudioChannelLabel_ForeignLanguage = 305,
|
||||||
|
|
||||||
|
// generic discrete channel
|
||||||
|
kAudioChannelLabel_Discrete = 400,
|
||||||
|
|
||||||
|
// numbered discrete channel
|
||||||
|
kAudioChannelLabel_Discrete_0 = (1L<<16) | 0,
|
||||||
|
kAudioChannelLabel_Discrete_1 = (1L<<16) | 1,
|
||||||
|
kAudioChannelLabel_Discrete_2 = (1L<<16) | 2,
|
||||||
|
kAudioChannelLabel_Discrete_3 = (1L<<16) | 3,
|
||||||
|
kAudioChannelLabel_Discrete_4 = (1L<<16) | 4,
|
||||||
|
kAudioChannelLabel_Discrete_5 = (1L<<16) | 5,
|
||||||
|
kAudioChannelLabel_Discrete_6 = (1L<<16) | 6,
|
||||||
|
kAudioChannelLabel_Discrete_7 = (1L<<16) | 7,
|
||||||
|
kAudioChannelLabel_Discrete_8 = (1L<<16) | 8,
|
||||||
|
kAudioChannelLabel_Discrete_9 = (1L<<16) | 9,
|
||||||
|
kAudioChannelLabel_Discrete_10 = (1L<<16) | 10,
|
||||||
|
kAudioChannelLabel_Discrete_11 = (1L<<16) | 11,
|
||||||
|
kAudioChannelLabel_Discrete_12 = (1L<<16) | 12,
|
||||||
|
kAudioChannelLabel_Discrete_13 = (1L<<16) | 13,
|
||||||
|
kAudioChannelLabel_Discrete_14 = (1L<<16) | 14,
|
||||||
|
kAudioChannelLabel_Discrete_15 = (1L<<16) | 15,
|
||||||
|
kAudioChannelLabel_Discrete_65535 = (1L<<16) | 65535
|
||||||
|
};
|
||||||
|
|
||||||
|
#define AudioChannelLayoutTag_GetNumberOfChannels(layoutTag) \
|
||||||
|
((uint32_t)((layoutTag) & 0x0000FFFF))
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kAudioChannelLayoutTag_UseChannelDescriptions = (0L<<16) | 0, // use the array of AudioChannelDescriptions to define the mapping.
|
||||||
|
kAudioChannelLayoutTag_UseChannelBitmap = (1L<<16) | 0, // use the bitmap to define the mapping.
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Mono = (100L<<16) | 1, // a standard mono stream
|
||||||
|
kAudioChannelLayoutTag_Stereo = (101L<<16) | 2, // a standard stereo stream (L R) - implied playback
|
||||||
|
kAudioChannelLayoutTag_StereoHeadphones = (102L<<16) | 2, // a standard stereo stream (L R) - implied headphone playbac
|
||||||
|
kAudioChannelLayoutTag_MatrixStereo = (103L<<16) | 2, // a matrix encoded stereo stream (Lt, Rt)
|
||||||
|
kAudioChannelLayoutTag_MidSide = (104L<<16) | 2, // mid/side recording
|
||||||
|
kAudioChannelLayoutTag_XY = (105L<<16) | 2, // coincident mic pair (often 2 figure 8's)
|
||||||
|
kAudioChannelLayoutTag_Binaural = (106L<<16) | 2, // binaural stereo (left, right)
|
||||||
|
kAudioChannelLayoutTag_Ambisonic_B_Format = (107L<<16) | 4, // W, X, Y, Z
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Quadraphonic = (108L<<16) | 4, // front left, front right, back left, back right
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Pentagonal = (109L<<16) | 5, // left, right, rear left, rear right, center
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Hexagonal = (110L<<16) | 6, // left, right, rear left, rear right, center, rear
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Octagonal = (111L<<16) | 8, // front left, front right, rear left, rear right,
|
||||||
|
// front center, rear center, side left, side right
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_Cube = (112L<<16) | 8, // left, right, rear left, rear right
|
||||||
|
// top left, top right, top rear left, top rear right
|
||||||
|
|
||||||
|
// MPEG defined layouts
|
||||||
|
kAudioChannelLayoutTag_MPEG_1_0 = kAudioChannelLayoutTag_Mono, // C
|
||||||
|
kAudioChannelLayoutTag_MPEG_2_0 = kAudioChannelLayoutTag_Stereo, // L R
|
||||||
|
kAudioChannelLayoutTag_MPEG_3_0_A = (113L<<16) | 3, // L R C
|
||||||
|
kAudioChannelLayoutTag_MPEG_3_0_B = (114L<<16) | 3, // C L R
|
||||||
|
kAudioChannelLayoutTag_MPEG_4_0_A = (115L<<16) | 4, // L R C Cs
|
||||||
|
kAudioChannelLayoutTag_MPEG_4_0_B = (116L<<16) | 4, // C L R Cs
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_0_A = (117L<<16) | 5, // L R C Ls Rs
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_0_B = (118L<<16) | 5, // L R Ls Rs C
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_0_C = (119L<<16) | 5, // L C R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_0_D = (120L<<16) | 5, // C L R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_1_A = (121L<<16) | 6, // L R C LFE Ls Rs
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_1_B = (122L<<16) | 6, // L R Ls Rs C LFE
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_1_C = (123L<<16) | 6, // L C R Ls Rs LFE
|
||||||
|
kAudioChannelLayoutTag_MPEG_5_1_D = (124L<<16) | 6, // C L R Ls Rs LFE
|
||||||
|
kAudioChannelLayoutTag_MPEG_6_1_A = (125L<<16) | 7, // L R C LFE Ls Rs Cs
|
||||||
|
kAudioChannelLayoutTag_MPEG_7_1_A = (126L<<16) | 8, // L R C LFE Ls Rs Lc Rc
|
||||||
|
kAudioChannelLayoutTag_MPEG_7_1_B = (127L<<16) | 8, // C Lc Rc L R Ls Rs LFE (doc: IS-13818-7 MPEG2-AAC Table 3.1)
|
||||||
|
kAudioChannelLayoutTag_MPEG_7_1_C = (128L<<16) | 8, // L R C LFE Ls Rs Rls Rrs
|
||||||
|
kAudioChannelLayoutTag_Emagic_Default_7_1 = (129L<<16) | 8, // L R Ls Rs C LFE Lc Rc
|
||||||
|
kAudioChannelLayoutTag_SMPTE_DTV = (130L<<16) | 8, // L R C LFE Ls Rs Lt Rt
|
||||||
|
// (kAudioChannelLayoutTag_ITU_5_1 plus a matrix encoded stereo mix)
|
||||||
|
|
||||||
|
// ITU defined layouts
|
||||||
|
kAudioChannelLayoutTag_ITU_1_0 = kAudioChannelLayoutTag_Mono, // C
|
||||||
|
kAudioChannelLayoutTag_ITU_2_0 = kAudioChannelLayoutTag_Stereo, // L R
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_ITU_2_1 = (131L<<16) | 3, // L R Cs
|
||||||
|
kAudioChannelLayoutTag_ITU_2_2 = (132L<<16) | 4, // L R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_ITU_3_0 = kAudioChannelLayoutTag_MPEG_3_0_A, // L R C
|
||||||
|
kAudioChannelLayoutTag_ITU_3_1 = kAudioChannelLayoutTag_MPEG_4_0_A, // L R C Cs
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_ITU_3_2 = kAudioChannelLayoutTag_MPEG_5_0_A, // L R C Ls Rs
|
||||||
|
kAudioChannelLayoutTag_ITU_3_2_1 = kAudioChannelLayoutTag_MPEG_5_1_A, // L R C LFE Ls Rs
|
||||||
|
kAudioChannelLayoutTag_ITU_3_4_1 = kAudioChannelLayoutTag_MPEG_7_1_C, // L R C LFE Ls Rs Rls Rrs
|
||||||
|
|
||||||
|
// DVD defined layouts
|
||||||
|
kAudioChannelLayoutTag_DVD_0 = kAudioChannelLayoutTag_Mono, // C (mono)
|
||||||
|
kAudioChannelLayoutTag_DVD_1 = kAudioChannelLayoutTag_Stereo, // L R
|
||||||
|
kAudioChannelLayoutTag_DVD_2 = kAudioChannelLayoutTag_ITU_2_1, // L R Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_3 = kAudioChannelLayoutTag_ITU_2_2, // L R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_DVD_4 = (133L<<16) | 3, // L R LFE
|
||||||
|
kAudioChannelLayoutTag_DVD_5 = (134L<<16) | 4, // L R LFE Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_6 = (135L<<16) | 5, // L R LFE Ls Rs
|
||||||
|
kAudioChannelLayoutTag_DVD_7 = kAudioChannelLayoutTag_MPEG_3_0_A, // L R C
|
||||||
|
kAudioChannelLayoutTag_DVD_8 = kAudioChannelLayoutTag_MPEG_4_0_A, // L R C Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_9 = kAudioChannelLayoutTag_MPEG_5_0_A, // L R C Ls Rs
|
||||||
|
kAudioChannelLayoutTag_DVD_10 = (136L<<16) | 4, // L R C LFE
|
||||||
|
kAudioChannelLayoutTag_DVD_11 = (137L<<16) | 5, // L R C LFE Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_12 = kAudioChannelLayoutTag_MPEG_5_1_A, // L R C LFE Ls Rs
|
||||||
|
// 13 through 17 are duplicates of 8 through 12.
|
||||||
|
kAudioChannelLayoutTag_DVD_13 = kAudioChannelLayoutTag_DVD_8, // L R C Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_14 = kAudioChannelLayoutTag_DVD_9, // L R C Ls Rs
|
||||||
|
kAudioChannelLayoutTag_DVD_15 = kAudioChannelLayoutTag_DVD_10, // L R C LFE
|
||||||
|
kAudioChannelLayoutTag_DVD_16 = kAudioChannelLayoutTag_DVD_11, // L R C LFE Cs
|
||||||
|
kAudioChannelLayoutTag_DVD_17 = kAudioChannelLayoutTag_DVD_12, // L R C LFE Ls Rs
|
||||||
|
kAudioChannelLayoutTag_DVD_18 = (138L<<16) | 5, // L R Ls Rs LFE
|
||||||
|
kAudioChannelLayoutTag_DVD_19 = kAudioChannelLayoutTag_MPEG_5_0_B, // L R Ls Rs C
|
||||||
|
kAudioChannelLayoutTag_DVD_20 = kAudioChannelLayoutTag_MPEG_5_1_B, // L R Ls Rs C LFE
|
||||||
|
|
||||||
|
// These layouts are recommended for AudioUnit usage
|
||||||
|
// These are the symmetrical layouts
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_4 = kAudioChannelLayoutTag_Quadraphonic,
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_5 = kAudioChannelLayoutTag_Pentagonal,
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_6 = kAudioChannelLayoutTag_Hexagonal,
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_8 = kAudioChannelLayoutTag_Octagonal,
|
||||||
|
// These are the surround-based layouts
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_5_0 = kAudioChannelLayoutTag_MPEG_5_0_B, // L R Ls Rs C
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_6_0 = (139L<<16) | 6, // L R Ls Rs C Cs
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_7_0 = (140L<<16) | 7, // L R Ls Rs C Rls Rrs
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_7_0_Front = (148L<<16) | 7, // L R Ls Rs C Lc Rc
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_5_1 = kAudioChannelLayoutTag_MPEG_5_1_A, // L R C LFE Ls Rs
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_6_1 = kAudioChannelLayoutTag_MPEG_6_1_A, // L R C LFE Ls Rs Cs
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_7_1 = kAudioChannelLayoutTag_MPEG_7_1_C, // L R C LFE Ls Rs Rls Rrs
|
||||||
|
kAudioChannelLayoutTag_AudioUnit_7_1_Front = kAudioChannelLayoutTag_MPEG_7_1_A, // L R C LFE Ls Rs Lc Rc
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_AAC_3_0 = kAudioChannelLayoutTag_MPEG_3_0_B, // C L R
|
||||||
|
kAudioChannelLayoutTag_AAC_Quadraphonic = kAudioChannelLayoutTag_Quadraphonic, // L R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_AAC_4_0 = kAudioChannelLayoutTag_MPEG_4_0_B, // C L R Cs
|
||||||
|
kAudioChannelLayoutTag_AAC_5_0 = kAudioChannelLayoutTag_MPEG_5_0_D, // C L R Ls Rs
|
||||||
|
kAudioChannelLayoutTag_AAC_5_1 = kAudioChannelLayoutTag_MPEG_5_1_D, // C L R Ls Rs Lfe
|
||||||
|
kAudioChannelLayoutTag_AAC_6_0 = (141L<<16) | 6, // C L R Ls Rs Cs
|
||||||
|
kAudioChannelLayoutTag_AAC_6_1 = (142L<<16) | 7, // C L R Ls Rs Cs Lfe
|
||||||
|
kAudioChannelLayoutTag_AAC_7_0 = (143L<<16) | 7, // C L R Ls Rs Rls Rrs
|
||||||
|
kAudioChannelLayoutTag_AAC_7_1 = kAudioChannelLayoutTag_MPEG_7_1_B, // C Lc Rc L R Ls Rs Lfe
|
||||||
|
kAudioChannelLayoutTag_AAC_Octagonal = (144L<<16) | 8, // C L R Ls Rs Rls Rrs Cs
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_TMH_10_2_std = (145L<<16) | 16, // L R C Vhc Lsd Rsd Ls Rs Vhl Vhr Lw Rw Csd Cs LFE1 LFE2
|
||||||
|
kAudioChannelLayoutTag_TMH_10_2_full = (146L<<16) | 21, // TMH_10_2_std plus: Lc Rc HI VI Haptic
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_AC3_1_0_1 = (149L<<16) | 2, // C LFE
|
||||||
|
kAudioChannelLayoutTag_AC3_3_0 = (150L<<16) | 3, // L C R
|
||||||
|
kAudioChannelLayoutTag_AC3_3_1 = (151L<<16) | 4, // L C R Cs
|
||||||
|
kAudioChannelLayoutTag_AC3_3_0_1 = (152L<<16) | 4, // L C R LFE
|
||||||
|
kAudioChannelLayoutTag_AC3_2_1_1 = (153L<<16) | 4, // L R Cs LFE
|
||||||
|
kAudioChannelLayoutTag_AC3_3_1_1 = (154L<<16) | 5, // L C R Cs LFE
|
||||||
|
|
||||||
|
kAudioChannelLayoutTag_DiscreteInOrder = (147L<<16) | 0, // needs to be ORed with the actual number of channels
|
||||||
|
kAudioChannelLayoutTag_Unknown = 0xFFFF0000 // needs to be ORed with the actual number of channels
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -13,8 +13,7 @@
|
|||||||
#include "lpcm.h"
|
#include "lpcm.h"
|
||||||
#include "m4af_endian.h"
|
#include "m4af_endian.h"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||||
# define inline __inline
|
|
||||||
# ifdef _M_IX86
|
# ifdef _M_IX86
|
||||||
inline int lrint(double x)
|
inline int lrint(double x)
|
||||||
{
|
{
|
||||||
|
@ -866,15 +866,14 @@ void m4af_write_sgpd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
{
|
{
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
m4af_write(ctx,
|
m4af_write(ctx,
|
||||||
"\0\0\0\032" /* size */
|
"\0\0\0\026" /* size: 22 */
|
||||||
"sgpd" /* type */
|
"sgpd" /* type */
|
||||||
"\001" /* version */
|
"\0" /* version */
|
||||||
"\0\0\0" /* flags */
|
"\0\0\0" /* flags */
|
||||||
"roll" /* grouping_type */
|
"roll" /* grouping_type */
|
||||||
"\0\0\0\002" /* default_length: 2 */
|
|
||||||
"\0\0\0\001" /* entry_count: 1 */
|
"\0\0\0\001" /* entry_count: 1 */
|
||||||
"\377\377" /* payload_data: -1 */
|
"\377\377" /* payload_data: -1 */
|
||||||
, 26);
|
, 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
133
src/main.c
133
src/main.c
@ -34,6 +34,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "wav_reader.h"
|
#include "wav_reader.h"
|
||||||
|
#include "caf_reader.h"
|
||||||
#include "aacenc.h"
|
#include "aacenc.h"
|
||||||
#include "m4af.h"
|
#include "m4af.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
@ -132,10 +133,6 @@ PROGNAME " %s\n"
|
|||||||
" 0: Off\n"
|
" 0: Off\n"
|
||||||
" 1: On(default)\n"
|
" 1: On(default)\n"
|
||||||
" -L, --lowdelay-sbr Enable ELD-SBR (AAC ELD only)\n"
|
" -L, --lowdelay-sbr Enable ELD-SBR (AAC ELD only)\n"
|
||||||
" -s, --sbr-signaling <n> SBR signaling mode\n"
|
|
||||||
" 0: Implicit, backward compatible(default)\n"
|
|
||||||
" 1: Explicit SBR and implicit PS\n"
|
|
||||||
" 2: Explicit hierarchical signaling\n"
|
|
||||||
" -f, --transport-format <n> Transport format\n"
|
" -f, --transport-format <n> Transport format\n"
|
||||||
" 0: RAW (default, muxed into M4A)\n"
|
" 0: RAW (default, muxed into M4A)\n"
|
||||||
" 1: ADIF\n"
|
" 1: ADIF\n"
|
||||||
@ -152,7 +149,10 @@ PROGNAME " %s\n"
|
|||||||
" 0: iTunSMPB (default)\n"
|
" 0: iTunSMPB (default)\n"
|
||||||
" 1: ISO standard (edts + sgpd)\n"
|
" 1: ISO standard (edts + sgpd)\n"
|
||||||
" 2: Both\n"
|
" 2: Both\n"
|
||||||
" --ignorelength Ignore length of WAV header\n"
|
" --include-sbr-delay Count SBR decoder delay in encoder delay\n"
|
||||||
|
" This is not iTunes compatible, but is default\n"
|
||||||
|
" behavior of FDK library.\n"
|
||||||
|
" -I, --ignorelength Ignore length of WAV header\n"
|
||||||
" -S, --silent Don't print progress messages\n"
|
" -S, --silent Don't print progress messages\n"
|
||||||
" --moov-before-mdat Place moov box before mdat box on m4a output\n"
|
" --moov-before-mdat Place moov box before mdat box on m4a output\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -207,6 +207,7 @@ typedef struct aacenc_param_ex_t {
|
|||||||
char *output_filename;
|
char *output_filename;
|
||||||
FILE *output_fp;
|
FILE *output_fp;
|
||||||
unsigned gapless_mode;
|
unsigned gapless_mode;
|
||||||
|
unsigned include_sbr_delay;
|
||||||
unsigned ignore_length;
|
unsigned ignore_length;
|
||||||
int silent;
|
int silent;
|
||||||
int moov_before_mdat;
|
int moov_before_mdat;
|
||||||
@ -216,7 +217,9 @@ typedef struct aacenc_param_ex_t {
|
|||||||
unsigned raw_rate;
|
unsigned raw_rate;
|
||||||
const char *raw_format;
|
const char *raw_format;
|
||||||
|
|
||||||
aacenc_tag_param_t tags;
|
aacenc_tag_store_t tags;
|
||||||
|
aacenc_tag_store_t source_tags;
|
||||||
|
aacenc_translate_generic_text_tag_ctx_t source_tag_ctx;
|
||||||
|
|
||||||
char *json_filename;
|
char *json_filename;
|
||||||
} aacenc_param_ex_t;
|
} aacenc_param_ex_t;
|
||||||
@ -227,6 +230,7 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
|
#define OPT_INCLUDE_SBR_DELAY M4AF_FOURCC('s','d','l','y')
|
||||||
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
||||||
#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
|
#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
|
||||||
#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
|
#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
|
||||||
@ -244,12 +248,12 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "bandwidth", required_argument, 0, 'w' },
|
{ "bandwidth", required_argument, 0, 'w' },
|
||||||
{ "afterburner", required_argument, 0, 'a' },
|
{ "afterburner", required_argument, 0, 'a' },
|
||||||
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
||||||
{ "sbr-signaling", required_argument, 0, 's' },
|
|
||||||
{ "transport-format", required_argument, 0, 'f' },
|
{ "transport-format", required_argument, 0, 'f' },
|
||||||
{ "adts-crc-check", no_argument, 0, 'C' },
|
{ "adts-crc-check", no_argument, 0, 'C' },
|
||||||
{ "header-period", required_argument, 0, 'P' },
|
{ "header-period", required_argument, 0, 'P' },
|
||||||
|
|
||||||
{ "gapless-mode", required_argument, 0, 'G' },
|
{ "gapless-mode", required_argument, 0, 'G' },
|
||||||
|
{ "include-sbr-delay", no_argument, 0, OPT_INCLUDE_SBR_DELAY },
|
||||||
{ "ignorelength", no_argument, 0, 'I' },
|
{ "ignorelength", no_argument, 0, 'I' },
|
||||||
{ "silent", no_argument, 0, 'S' },
|
{ "silent", no_argument, 0, 'S' },
|
||||||
{ "moov-before-mdat", no_argument, 0, OPT_MOOV_BEFORE_MDAT },
|
{ "moov-before-mdat", no_argument, 0, OPT_MOOV_BEFORE_MDAT },
|
||||||
@ -323,13 +327,6 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
case 'L':
|
case 'L':
|
||||||
params->lowdelay_sbr = 1;
|
params->lowdelay_sbr = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
|
||||||
if (sscanf(optarg, "%u", &n) != 1 || n > 2) {
|
|
||||||
fprintf(stderr, "invalid arg for sbr-signaling\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
params->sbr_signaling = n;
|
|
||||||
break;
|
|
||||||
case 'f':
|
case 'f':
|
||||||
if (sscanf(optarg, "%u", &n) != 1) {
|
if (sscanf(optarg, "%u", &n) != 1) {
|
||||||
fprintf(stderr, "invalid arg for transport-format\n");
|
fprintf(stderr, "invalid arg for transport-format\n");
|
||||||
@ -357,6 +354,9 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
}
|
}
|
||||||
params->gapless_mode = n;
|
params->gapless_mode = n;
|
||||||
break;
|
break;
|
||||||
|
case OPT_INCLUDE_SBR_DELAY:
|
||||||
|
params->include_sbr_delay = 1;
|
||||||
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
params->ignore_length = 1;
|
params->ignore_length = 1;
|
||||||
break;
|
break;
|
||||||
@ -398,8 +398,8 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
case M4AF_TAG_TRACK:
|
case M4AF_TAG_TRACK:
|
||||||
case M4AF_TAG_DISK:
|
case M4AF_TAG_DISK:
|
||||||
case M4AF_TAG_TEMPO:
|
case M4AF_TAG_TEMPO:
|
||||||
aacenc_param_add_itmf_entry(¶ms->tags, ch, 0, optarg,
|
aacenc_add_tag_to_store(¶ms->tags, ch, 0, optarg,
|
||||||
strlen(optarg), 0);
|
strlen(optarg), 0);
|
||||||
break;
|
break;
|
||||||
case OPT_SHORT_TAG:
|
case OPT_SHORT_TAG:
|
||||||
case OPT_SHORT_TAG_FILE:
|
case OPT_SHORT_TAG_FILE:
|
||||||
@ -432,9 +432,9 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
for (; *optarg; ++optarg)
|
for (; *optarg; ++optarg)
|
||||||
fcc = ((fcc << 8) | (*optarg & 0xff));
|
fcc = ((fcc << 8) | (*optarg & 0xff));
|
||||||
}
|
}
|
||||||
aacenc_param_add_itmf_entry(¶ms->tags, fcc, optarg,
|
aacenc_add_tag_to_store(¶ms->tags, fcc, optarg,
|
||||||
val, strlen(val),
|
val, strlen(val),
|
||||||
ch == OPT_SHORT_TAG_FILE);
|
ch == OPT_SHORT_TAG_FILE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OPT_TAG_FROM_JSON:
|
case OPT_TAG_FROM_JSON:
|
||||||
@ -570,13 +570,18 @@ int finalize_m4a(m4af_ctx_t *m4af, const aacenc_param_ex_t *params,
|
|||||||
HANDLE_AACENCODER encoder)
|
HANDLE_AACENCODER encoder)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
aacenc_tag_entry_t *tag = params->tags.tag_table;
|
aacenc_tag_entry_t *tag;
|
||||||
|
|
||||||
|
tag = params->source_tags.tag_table;
|
||||||
|
for (i = 0; i < params->source_tags.tag_count; ++i, ++tag)
|
||||||
|
aacenc_write_tag_entry(m4af, tag);
|
||||||
|
|
||||||
if (params->json_filename)
|
if (params->json_filename)
|
||||||
aacenc_put_tags_from_json(m4af, params->json_filename);
|
aacenc_write_tags_from_json(m4af, params->json_filename);
|
||||||
|
|
||||||
|
tag = params->tags.tag_table;
|
||||||
for (i = 0; i < params->tags.tag_count; ++i, ++tag)
|
for (i = 0; i < params->tags.tag_count; ++i, ++tag)
|
||||||
aacenc_put_tag_entry(m4af, tag);
|
aacenc_write_tag_entry(m4af, tag);
|
||||||
|
|
||||||
put_tool_tag(m4af, params, encoder);
|
put_tool_tag(m4af, params, encoder);
|
||||||
|
|
||||||
@ -643,12 +648,15 @@ int parse_raw_spec(const char *spec, pcm_sample_description_t *desc)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pcm_io_vtbl_t pcm_io_vtbl = {
|
||||||
|
read_callback, seek_callback, tell_callback
|
||||||
|
};
|
||||||
|
static pcm_io_vtbl_t pcm_io_vtbl_noseek = { read_callback, 0, 0 };
|
||||||
|
|
||||||
static
|
static
|
||||||
pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
||||||
{
|
{
|
||||||
wav_io_context_t wav_io = {
|
pcm_io_context_t io = { 0 };
|
||||||
read_callback, seek_callback, tell_callback
|
|
||||||
};
|
|
||||||
pcm_reader_t *reader = 0;
|
pcm_reader_t *reader = 0;
|
||||||
struct stat stb = { 0 };
|
struct stat stb = { 0 };
|
||||||
|
|
||||||
@ -657,11 +665,13 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
io.cookie = params->input_fp;
|
||||||
if (fstat(fileno(params->input_fp), &stb) == 0
|
if (fstat(fileno(params->input_fp), &stb) == 0
|
||||||
&& (stb.st_mode & S_IFMT) != S_IFREG) {
|
&& (stb.st_mode & S_IFMT) == S_IFREG)
|
||||||
wav_io.seek = 0;
|
io.vtbl = &pcm_io_vtbl;
|
||||||
wav_io.tell = 0;
|
else
|
||||||
}
|
io.vtbl = &pcm_io_vtbl_noseek;
|
||||||
|
|
||||||
if (params->is_raw) {
|
if (params->is_raw) {
|
||||||
int bytes_per_channel;
|
int bytes_per_channel;
|
||||||
pcm_sample_description_t desc = { 0 };
|
pcm_sample_description_t desc = { 0 };
|
||||||
@ -673,14 +683,32 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
|||||||
desc.channels_per_frame = params->raw_channels;
|
desc.channels_per_frame = params->raw_channels;
|
||||||
bytes_per_channel = (desc.bits_per_channel + 7) / 8;
|
bytes_per_channel = (desc.bits_per_channel + 7) / 8;
|
||||||
desc.bytes_per_frame = params->raw_channels * bytes_per_channel;
|
desc.bytes_per_frame = params->raw_channels * bytes_per_channel;
|
||||||
if ((reader = raw_open(&wav_io, params->input_fp, &desc)) == 0) {
|
if ((reader = raw_open(&io, &desc)) == 0) {
|
||||||
fprintf(stderr, "ERROR: failed to open raw input\n");
|
fprintf(stderr, "ERROR: failed to open raw input\n");
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((reader = wav_open(&wav_io, params->input_fp,
|
int c;
|
||||||
params->ignore_length)) == 0) {
|
ungetc(c = getc(params->input_fp), params->input_fp);
|
||||||
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
|
||||||
|
switch (c) {
|
||||||
|
case 'R':
|
||||||
|
if ((reader = wav_open(&io, params->ignore_length)) == 0) {
|
||||||
|
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
params->source_tag_ctx.add = aacenc_add_tag_entry_to_store;
|
||||||
|
params->source_tag_ctx.add_ctx = ¶ms->source_tags;
|
||||||
|
if ((reader = caf_open(&io,
|
||||||
|
aacenc_translate_generic_text_tag,
|
||||||
|
¶ms->source_tag_ctx)) == 0) {
|
||||||
|
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -705,6 +733,7 @@ int main(int argc, char **argv)
|
|||||||
const pcm_sample_description_t *sample_format;
|
const pcm_sample_description_t *sample_format;
|
||||||
int downsampled_timescale = 0;
|
int downsampled_timescale = 0;
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
|
int sbr_mode = 0;
|
||||||
|
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
setbuf(stderr, 0);
|
setbuf(stderr, 0);
|
||||||
@ -717,6 +746,17 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
sample_format = pcm_get_format(reader);
|
sample_format = pcm_get_format(reader);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We use explicit/hierarchical signaling for LOAS.
|
||||||
|
* Other than that, we request implicit signaling to FDK library, then
|
||||||
|
* append explicit/backward-compatible signaling to ASC in case of MP4FF.
|
||||||
|
*
|
||||||
|
* Explicit/backward-compatible signaling of SBR is the most recommended
|
||||||
|
* way in MPEG4 part3 spec, and seems the only way supported by iTunes.
|
||||||
|
* Since FDK library does not support it, we have to do it on our side.
|
||||||
|
*/
|
||||||
|
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
|
||||||
|
|
||||||
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
||||||
&aacinfo) < 0)
|
&aacinfo) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
@ -733,19 +773,21 @@ int main(int argc, char **argv)
|
|||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
handle_signals();
|
handle_signals();
|
||||||
|
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
||||||
if (!params.transport_format) {
|
if (!params.transport_format) {
|
||||||
uint32_t scale;
|
uint32_t scale;
|
||||||
|
uint8_t mp4asc[32];
|
||||||
|
uint32_t ascsize = sizeof(mp4asc);
|
||||||
unsigned framelen = aacinfo.frameLength;
|
unsigned framelen = aacinfo.frameLength;
|
||||||
int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
if (sbr_mode)
|
||||||
int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
|
|
||||||
if (sbr_mode && !sig_mode)
|
|
||||||
downsampled_timescale = 1;
|
downsampled_timescale = 1;
|
||||||
scale = sample_format->sample_rate >> downsampled_timescale;
|
scale = sample_format->sample_rate >> downsampled_timescale;
|
||||||
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
||||||
params.output_fp)) < 0)
|
params.output_fp)) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
m4af_set_decoder_specific_info(m4af, 0, aacinfo.confBuf,
|
aacenc_mp4asc((aacenc_param_t*)¶ms, aacinfo.confBuf,
|
||||||
aacinfo.confSize);
|
aacinfo.confSize, mp4asc, &ascsize);
|
||||||
|
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
|
||||||
m4af_set_fixed_frame_duration(m4af, 0,
|
m4af_set_fixed_frame_duration(m4af, 0,
|
||||||
framelen >> downsampled_timescale);
|
framelen >> downsampled_timescale);
|
||||||
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
||||||
@ -758,9 +800,15 @@ int main(int argc, char **argv)
|
|||||||
goto END;
|
goto END;
|
||||||
if (m4af) {
|
if (m4af) {
|
||||||
uint32_t delay = aacinfo.encoderDelay;
|
uint32_t delay = aacinfo.encoderDelay;
|
||||||
|
uint32_t padding;
|
||||||
int64_t frames_read = pcm_get_position(reader);
|
int64_t frames_read = pcm_get_position(reader);
|
||||||
uint32_t padding = frame_count * aacinfo.frameLength
|
|
||||||
- frames_read - aacinfo.encoderDelay;
|
if (sbr_mode && params.profile != AOT_ER_AAC_ELD &&
|
||||||
|
!params.include_sbr_delay)
|
||||||
|
delay -= 481 << 1;
|
||||||
|
if (sbr_mode && (delay & 1))
|
||||||
|
++delay;
|
||||||
|
padding = frame_count * aacinfo.frameLength - frames_read - delay;
|
||||||
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
||||||
padding >> downsampled_timescale);
|
padding >> downsampled_timescale);
|
||||||
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
||||||
@ -774,7 +822,10 @@ END:
|
|||||||
if (params.output_fp) fclose(params.output_fp);
|
if (params.output_fp) fclose(params.output_fp);
|
||||||
if (encoder) aacEncClose(&encoder);
|
if (encoder) aacEncClose(&encoder);
|
||||||
if (output_filename) free(output_filename);
|
if (output_filename) free(output_filename);
|
||||||
if (params.tags.tag_table) free(params.tags.tag_table);
|
if (params.tags.tag_table)
|
||||||
|
aacenc_free_tag_store(¶ms.tags);
|
||||||
|
if (params.source_tags.tag_table)
|
||||||
|
aacenc_free_tag_store(¶ms.source_tags);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
282
src/metadata.c
282
src/metadata.c
@ -50,12 +50,14 @@ static tag_key_mapping_t tag_mapping_table[] = {
|
|||||||
{ "copyright", M4AF_TAG_COPYRIGHT },
|
{ "copyright", M4AF_TAG_COPYRIGHT },
|
||||||
{ "date", M4AF_TAG_DATE },
|
{ "date", M4AF_TAG_DATE },
|
||||||
{ "disc", M4AF_TAG_DISK },
|
{ "disc", M4AF_TAG_DISK },
|
||||||
{ "disctotal", TAG_TOTAL_DISCS },
|
|
||||||
{ "discnumber", M4AF_TAG_DISK },
|
{ "discnumber", M4AF_TAG_DISK },
|
||||||
|
{ "disctotal", TAG_TOTAL_DISCS },
|
||||||
{ "genre", M4AF_TAG_GENRE },
|
{ "genre", M4AF_TAG_GENRE },
|
||||||
{ "grouping", M4AF_TAG_GROUPING },
|
{ "grouping", M4AF_TAG_GROUPING },
|
||||||
{ "itunescompilation", M4AF_TAG_COMPILATION },
|
{ "itunescompilation", M4AF_TAG_COMPILATION },
|
||||||
{ "lyrics", M4AF_TAG_LYRICS },
|
{ "lyrics", M4AF_TAG_LYRICS },
|
||||||
|
{ "tempo", M4AF_TAG_TEMPO },
|
||||||
|
{ "recordeddate", M4AF_TAG_DATE },
|
||||||
{ "title", M4AF_TAG_TITLE },
|
{ "title", M4AF_TAG_TITLE },
|
||||||
{ "titlesort", M4AF_FOURCC('s','o','n','m') },
|
{ "titlesort", M4AF_FOURCC('s','o','n','m') },
|
||||||
{ "titlesortorder", M4AF_FOURCC('s','o','n','m') },
|
{ "titlesortorder", M4AF_FOURCC('s','o','n','m') },
|
||||||
@ -95,6 +97,7 @@ uint32_t get_tag_fcc_from_name(const char *name)
|
|||||||
return ent ? ent->fcc : 0;
|
return ent ? ent->fcc : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
char *aacenc_load_tag_from_file(const char *path, uint32_t *data_size)
|
char *aacenc_load_tag_from_file(const char *path, uint32_t *data_size)
|
||||||
{
|
{
|
||||||
FILE *fp = 0;
|
FILE *fp = 0;
|
||||||
@ -121,48 +124,152 @@ END:
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aacenc_param_add_itmf_entry(aacenc_tag_param_t *params, uint32_t tag,
|
static
|
||||||
const char *key, const char *value,
|
int aacenc_is_string_tag(uint32_t tag)
|
||||||
uint32_t size, int is_file_name)
|
|
||||||
{
|
{
|
||||||
aacenc_tag_entry_t *entry;
|
switch (tag) {
|
||||||
|
case M4AF_TAG_TITLE:
|
||||||
|
case M4AF_TAG_ARTIST:
|
||||||
|
case M4AF_TAG_ALBUM:
|
||||||
|
case M4AF_TAG_GENRE:
|
||||||
|
case M4AF_TAG_DATE:
|
||||||
|
case M4AF_TAG_COMPOSER:
|
||||||
|
case M4AF_TAG_GROUPING:
|
||||||
|
case M4AF_TAG_COMMENT:
|
||||||
|
case M4AF_TAG_LYRICS:
|
||||||
|
case M4AF_TAG_TOOL:
|
||||||
|
case M4AF_TAG_ALBUM_ARTIST:
|
||||||
|
case M4AF_TAG_DESCRIPTION:
|
||||||
|
case M4AF_TAG_LONG_DESCRIPTION:
|
||||||
|
case M4AF_TAG_COPYRIGHT:
|
||||||
|
case M4AF_FOURCC('a','p','I','D'):
|
||||||
|
case M4AF_FOURCC('c','a','t','g'):
|
||||||
|
case M4AF_FOURCC('k','e','y','w'):
|
||||||
|
case M4AF_FOURCC('p','u','r','d'):
|
||||||
|
case M4AF_FOURCC('p','u','r','l'):
|
||||||
|
case M4AF_FOURCC('s','o','a','a'):
|
||||||
|
case M4AF_FOURCC('s','o','a','l'):
|
||||||
|
case M4AF_FOURCC('s','o','a','r'):
|
||||||
|
case M4AF_FOURCC('s','o','c','o'):
|
||||||
|
case M4AF_FOURCC('s','o','n','m'):
|
||||||
|
case M4AF_FOURCC('s','o','s','n'):
|
||||||
|
case M4AF_FOURCC('t','v','e','n'):
|
||||||
|
case M4AF_FOURCC('t','v','n','n'):
|
||||||
|
case M4AF_FOURCC('t','v','s','h'):
|
||||||
|
case M4AF_FOURCC('x','i','d',' '):
|
||||||
|
case M4AF_FOURCC('\xa9','e','n','c'):
|
||||||
|
case M4AF_FOURCC('\xa9','s','t','3'):
|
||||||
|
case M4AF_FOURCC('-','-','-','-'):
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_add_tag_to_store(aacenc_tag_store_t *store, uint32_t tag,
|
||||||
|
const char *key, const char *value,
|
||||||
|
uint32_t size, int is_file_name)
|
||||||
|
{
|
||||||
|
aacenc_tag_entry_t entry = { 0 };
|
||||||
|
char *dp = 0;
|
||||||
|
|
||||||
if (!is_file_name && !size)
|
if (!is_file_name && !size)
|
||||||
return;
|
return;
|
||||||
if (params->tag_count == params->tag_table_capacity) {
|
entry.tag = tag;
|
||||||
unsigned newsize = params->tag_table_capacity;
|
|
||||||
newsize = newsize ? newsize * 2 : 1;
|
|
||||||
params->tag_table =
|
|
||||||
realloc(params->tag_table, newsize * sizeof(aacenc_tag_entry_t));
|
|
||||||
params->tag_table_capacity = newsize;
|
|
||||||
}
|
|
||||||
entry = params->tag_table + params->tag_count;
|
|
||||||
entry->tag = tag;
|
|
||||||
if (tag == M4AF_FOURCC('-','-','-','-'))
|
if (tag == M4AF_FOURCC('-','-','-','-'))
|
||||||
entry->name = key;
|
entry.name = (char *)key;
|
||||||
entry->data = value;
|
|
||||||
entry->data_size = size;
|
if (is_file_name) {
|
||||||
entry->is_file_name = is_file_name;
|
entry.data = dp = aacenc_load_tag_from_file(value, &size);
|
||||||
params->tag_count++;
|
entry.data_size = size;
|
||||||
|
} else if (aacenc_is_string_tag(tag)) {
|
||||||
|
entry.data = dp = aacenc_to_utf8(value);
|
||||||
|
entry.data_size = strlen(entry.data);
|
||||||
|
} else {
|
||||||
|
entry.data = (char *)value;
|
||||||
|
entry.data_size = size;
|
||||||
|
}
|
||||||
|
aacenc_add_tag_entry_to_store(store, &entry);
|
||||||
|
free(dp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_add_tag_entry_to_store(void *ctx, const aacenc_tag_entry_t *tag)
|
||||||
|
{
|
||||||
|
aacenc_tag_store_t *store = ctx;
|
||||||
|
aacenc_tag_entry_t *entry;
|
||||||
|
if (store->tag_count == store->tag_table_capacity) {
|
||||||
|
unsigned newsize = store->tag_table_capacity;
|
||||||
|
newsize = newsize ? newsize * 2 : 1;
|
||||||
|
store->tag_table =
|
||||||
|
realloc(store->tag_table, newsize * sizeof(aacenc_tag_entry_t));
|
||||||
|
store->tag_table_capacity = newsize;
|
||||||
|
}
|
||||||
|
entry = store->tag_table + store->tag_count;
|
||||||
|
entry->tag = tag->tag;
|
||||||
|
entry->data_size = tag->data_size;
|
||||||
|
entry->name = tag->name ? strdup(tag->name) : 0;
|
||||||
|
entry->data = malloc(tag->data_size + 1);
|
||||||
|
memcpy(entry->data, tag->data, tag->data_size);
|
||||||
|
entry->data[tag->data_size] = 0;
|
||||||
|
store->tag_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void tag_put_number_pair(m4af_ctx_t *m4af, uint32_t fcc,
|
void tag_put_number_pair(aacenc_translate_generic_text_tag_ctx_t *ctx,
|
||||||
const char *snumber, const char *stotal)
|
uint32_t fcc, unsigned number, unsigned total)
|
||||||
{
|
{
|
||||||
unsigned number = 0, total = 0;
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
aacenc_tag_entry_t entry = { 0 };
|
aacenc_tag_entry_t entry = { 0 };
|
||||||
|
|
||||||
if (snumber) sscanf(snumber, "%u", &number);
|
|
||||||
if (stotal) sscanf(stotal, "%u", &total);
|
|
||||||
if (number) {
|
if (number) {
|
||||||
if (total) sprintf(buf, "%u/%u", number, total);
|
if (total) sprintf(buf, "%u/%u", number, total);
|
||||||
else sprintf(buf, "%u", number);
|
else sprintf(buf, "%u", number);
|
||||||
entry.tag = fcc;
|
entry.tag = fcc;
|
||||||
entry.data = buf;
|
entry.data = buf;
|
||||||
entry.data_size = strlen(buf);
|
entry.data_size = strlen(buf);
|
||||||
aacenc_put_tag_entry(m4af, &entry);
|
ctx->add(ctx->add_ctx, &entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_translate_generic_text_tag(void *pctx, const char *key,
|
||||||
|
const char *val, uint32_t size)
|
||||||
|
{
|
||||||
|
aacenc_translate_generic_text_tag_ctx_t *ctx = pctx;
|
||||||
|
aacenc_tag_entry_t entry = { 0 };
|
||||||
|
uint32_t fcc;
|
||||||
|
/*
|
||||||
|
* Since track/disc number pair (number and total) can be stored within
|
||||||
|
* either single tag or separately, we cannot instantly translate
|
||||||
|
* them in one-to-one manner.
|
||||||
|
* Instead, we keep and store them until all tags are processed,
|
||||||
|
* then finally submit.
|
||||||
|
*/
|
||||||
|
if (!key) {
|
||||||
|
/* use null key as flushing signal */
|
||||||
|
tag_put_number_pair(ctx, M4AF_TAG_TRACK, ctx->track, ctx->track_total);
|
||||||
|
tag_put_number_pair(ctx, M4AF_TAG_DISK, ctx->disc, ctx->disc_total);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!val || !size)
|
||||||
|
return;
|
||||||
|
if ((fcc = get_tag_fcc_from_name(key)) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (fcc) {
|
||||||
|
case TAG_TOTAL_DISCS:
|
||||||
|
sscanf(val, "%d", &ctx->disc_total); break;
|
||||||
|
case TAG_TOTAL_TRACKS:
|
||||||
|
sscanf(val, "%d", &ctx->track_total); break;
|
||||||
|
case M4AF_TAG_DISK:
|
||||||
|
sscanf(val, "%d/%d", &ctx->disc, &ctx->disc_total); break;
|
||||||
|
case M4AF_TAG_TRACK:
|
||||||
|
sscanf(val, "%d/%d", &ctx->track, &ctx->track_total); break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
entry.tag = fcc;
|
||||||
|
entry.data = (char *)val;
|
||||||
|
entry.data_size = (size == ~0U) ? strlen(val) : size;
|
||||||
|
ctx->add(ctx->add_ctx, &entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +295,7 @@ const char *aacenc_json_object_get_string(JSON_Object *obj, const char *key,
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
void aacenc_write_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
||||||
{
|
{
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
JSON_Value *json = 0;
|
JSON_Value *json = 0;
|
||||||
@ -197,11 +304,10 @@ void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
|||||||
uint32_t data_size;
|
uint32_t data_size;
|
||||||
char *json_dot_path;
|
char *json_dot_path;
|
||||||
char *filename = 0;
|
char *filename = 0;
|
||||||
char *disc = 0;
|
aacenc_translate_generic_text_tag_ctx_t ctx = { 0 };
|
||||||
char *track = 0;
|
|
||||||
char *total_discs = 0;
|
ctx.add = aacenc_write_tag_entry;
|
||||||
char *total_tracks = 0;
|
ctx.add_ctx = m4af;
|
||||||
aacenc_tag_entry_t entry = { 0 };
|
|
||||||
|
|
||||||
filename = strdup(json_filename);
|
filename = strdup(json_filename);
|
||||||
if ((json_dot_path = strchr(filename, '?')) != 0)
|
if ((json_dot_path = strchr(filename, '?')) != 0)
|
||||||
@ -226,59 +332,36 @@ void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
|||||||
char buf[256];
|
char buf[256];
|
||||||
const char *key = json_object_get_name(root, i);
|
const char *key = json_object_get_name(root, i);
|
||||||
const char *val = aacenc_json_object_get_string(root, key, buf);
|
const char *val = aacenc_json_object_get_string(root, key, buf);
|
||||||
uint32_t fcc = get_tag_fcc_from_name(key);
|
if (val) aacenc_translate_generic_text_tag(&ctx, key, val, ~0U);
|
||||||
if (!val || !fcc)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (fcc) {
|
|
||||||
case TAG_TOTAL_DISCS:
|
|
||||||
total_discs = realloc(total_discs, strlen(val) + 1);
|
|
||||||
strcpy(total_discs, val);
|
|
||||||
break;
|
|
||||||
case TAG_TOTAL_TRACKS:
|
|
||||||
total_tracks = realloc(total_tracks, strlen(val) + 1);
|
|
||||||
strcpy(total_tracks, val);
|
|
||||||
break;
|
|
||||||
case M4AF_TAG_DISK:
|
|
||||||
disc = realloc(disc, strlen(val) + 1);
|
|
||||||
strcpy(disc, val);
|
|
||||||
break;
|
|
||||||
case M4AF_TAG_TRACK:
|
|
||||||
track = realloc(track, strlen(val) + 1);
|
|
||||||
strcpy(track, val);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
entry.tag = fcc;
|
|
||||||
entry.data = val;
|
|
||||||
entry.data_size = strlen(val);
|
|
||||||
aacenc_put_tag_entry(m4af, &entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tag_put_number_pair(m4af, M4AF_TAG_TRACK, track, total_tracks);
|
aacenc_translate_generic_text_tag(&ctx, 0, 0, 0);
|
||||||
tag_put_number_pair(m4af, M4AF_TAG_DISK, disc, total_discs);
|
|
||||||
DONE:
|
DONE:
|
||||||
if (track) free(track);
|
|
||||||
if (disc) free(disc);
|
|
||||||
if (total_tracks) free(total_tracks);
|
|
||||||
if (total_discs) free(total_discs);
|
|
||||||
if (data) free(data);
|
if (data) free(data);
|
||||||
if (filename) free(filename);
|
if (filename) free(filename);
|
||||||
if (json) json_value_free(json);
|
if (json) json_value_free(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void aacenc_put_tag_entry(m4af_ctx_t *m4af, const aacenc_tag_entry_t *tag)
|
void aacenc_free_tag_store(aacenc_tag_store_t *store)
|
||||||
{
|
{
|
||||||
|
if (store->tag_table) {
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i < store->tag_count; ++i) {
|
||||||
|
aacenc_tag_entry_t *ent = &store->tag_table[i];
|
||||||
|
free(ent->name);
|
||||||
|
free(ent->data);
|
||||||
|
}
|
||||||
|
free(store->tag_table);
|
||||||
|
store->tag_table = 0;
|
||||||
|
store->tag_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_write_tag_entry(void *ctx, const aacenc_tag_entry_t *tag)
|
||||||
|
{
|
||||||
|
m4af_ctx_t *m4af = ctx;
|
||||||
unsigned m, n = 0;
|
unsigned m, n = 0;
|
||||||
const char *data = tag->data;
|
const char *data = tag->data;
|
||||||
uint32_t data_size = tag->data_size;
|
|
||||||
char *file_contents = 0;
|
|
||||||
|
|
||||||
if (tag->is_file_name) {
|
|
||||||
data = file_contents = aacenc_load_tag_from_file(tag->data, &data_size);
|
|
||||||
if (!data) return;
|
|
||||||
}
|
|
||||||
switch (tag->tag) {
|
switch (tag->tag) {
|
||||||
case M4AF_TAG_TRACK:
|
case M4AF_TAG_TRACK:
|
||||||
if (sscanf(data, "%u/%u", &m, &n) >= 1)
|
if (sscanf(data, "%u/%u", &m, &n) >= 1)
|
||||||
@ -334,59 +417,22 @@ void aacenc_put_tag_entry(m4af_ctx_t *m4af, const aacenc_tag_entry_t *tag)
|
|||||||
data_type = M4AF_PNG;
|
data_type = M4AF_PNG;
|
||||||
if (data_type)
|
if (data_type)
|
||||||
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
||||||
data, data_size);
|
data, tag->data_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M4AF_FOURCC('-','-','-','-'):
|
case M4AF_FOURCC('-','-','-','-'):
|
||||||
{
|
{
|
||||||
char *u8 = aacenc_to_utf8(data);
|
m4af_add_itmf_long_tag(m4af, tag->name, data);
|
||||||
m4af_add_itmf_long_tag(m4af, tag->name, u8);
|
|
||||||
free(u8);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case M4AF_TAG_TITLE:
|
|
||||||
case M4AF_TAG_ARTIST:
|
|
||||||
case M4AF_TAG_ALBUM:
|
|
||||||
case M4AF_TAG_GENRE:
|
|
||||||
case M4AF_TAG_DATE:
|
|
||||||
case M4AF_TAG_COMPOSER:
|
|
||||||
case M4AF_TAG_GROUPING:
|
|
||||||
case M4AF_TAG_COMMENT:
|
|
||||||
case M4AF_TAG_LYRICS:
|
|
||||||
case M4AF_TAG_TOOL:
|
|
||||||
case M4AF_TAG_ALBUM_ARTIST:
|
|
||||||
case M4AF_TAG_DESCRIPTION:
|
|
||||||
case M4AF_TAG_LONG_DESCRIPTION:
|
|
||||||
case M4AF_TAG_COPYRIGHT:
|
|
||||||
case M4AF_FOURCC('a','p','I','D'):
|
|
||||||
case M4AF_FOURCC('c','a','t','g'):
|
|
||||||
case M4AF_FOURCC('k','e','y','w'):
|
|
||||||
case M4AF_FOURCC('p','u','r','d'):
|
|
||||||
case M4AF_FOURCC('p','u','r','l'):
|
|
||||||
case M4AF_FOURCC('s','o','a','a'):
|
|
||||||
case M4AF_FOURCC('s','o','a','l'):
|
|
||||||
case M4AF_FOURCC('s','o','a','r'):
|
|
||||||
case M4AF_FOURCC('s','o','c','o'):
|
|
||||||
case M4AF_FOURCC('s','o','n','m'):
|
|
||||||
case M4AF_FOURCC('s','o','s','n'):
|
|
||||||
case M4AF_FOURCC('t','v','e','n'):
|
|
||||||
case M4AF_FOURCC('t','v','n','n'):
|
|
||||||
case M4AF_FOURCC('t','v','s','h'):
|
|
||||||
case M4AF_FOURCC('x','i','d',' '):
|
|
||||||
case M4AF_FOURCC('\xa9','e','n','c'):
|
|
||||||
case M4AF_FOURCC('\xa9','s','t','3'):
|
|
||||||
{
|
|
||||||
char *u8 = aacenc_to_utf8(data);
|
|
||||||
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
|
||||||
free(u8);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "WARNING: unknown/unsupported tag: %c%c%c%c\n",
|
if (aacenc_is_string_tag(tag->tag))
|
||||||
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
m4af_add_itmf_string_tag(m4af, tag->tag, data);
|
||||||
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
else
|
||||||
|
fprintf(stderr, "WARNING: unknown/unsupported tag: %c%c%c%c\n",
|
||||||
|
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
||||||
|
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
||||||
}
|
}
|
||||||
if (file_contents) free(file_contents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,44 @@
|
|||||||
#ifndef METADATA_H
|
#ifndef METADATA_H
|
||||||
#define METADATA_H
|
#define METADATA_H
|
||||||
|
|
||||||
|
#include "m4af.h"
|
||||||
|
|
||||||
typedef struct aacenc_tag_entry_t {
|
typedef struct aacenc_tag_entry_t {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *name;
|
char *name;
|
||||||
const char *data;
|
char *data;
|
||||||
uint32_t data_size;
|
uint32_t data_size;
|
||||||
int is_file_name;
|
|
||||||
} aacenc_tag_entry_t;
|
} aacenc_tag_entry_t;
|
||||||
|
|
||||||
typedef struct aacenc_tag_param_t {
|
typedef struct aacenc_tag_store_t {
|
||||||
aacenc_tag_entry_t *tag_table;
|
aacenc_tag_entry_t *tag_table;
|
||||||
unsigned tag_count;
|
unsigned tag_count;
|
||||||
unsigned tag_table_capacity;
|
unsigned tag_table_capacity;
|
||||||
} aacenc_tag_param_t;
|
} aacenc_tag_store_t;
|
||||||
|
|
||||||
char *aacenc_load_tag_from_file(const char *path, uint32_t *data_size);
|
typedef struct aacenc_translate_generic_text_tag_ctx_t {
|
||||||
|
unsigned track, track_total, disc, disc_total;
|
||||||
|
void (*add)(void *, const aacenc_tag_entry_t *);
|
||||||
|
void *add_ctx;
|
||||||
|
} aacenc_translate_generic_text_tag_ctx_t;
|
||||||
|
|
||||||
void aacenc_param_add_itmf_entry(aacenc_tag_param_t *params, uint32_t tag,
|
typedef void (*aacenc_tag_callback_t)(void *ctx, const char *key,
|
||||||
const char *key, const char *value,
|
const char *value, uint32_t size);
|
||||||
uint32_t size, int is_file_name);
|
|
||||||
|
|
||||||
void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename);
|
void aacenc_translate_generic_text_tag(void *ctx, const char *key,
|
||||||
|
const char *val, uint32_t size);
|
||||||
|
|
||||||
void aacenc_put_tag_entry(m4af_ctx_t *m4af, const aacenc_tag_entry_t *tag);
|
|
||||||
|
void aacenc_add_tag_to_store(aacenc_tag_store_t *store, uint32_t tag,
|
||||||
|
const char *key, const char *value,
|
||||||
|
uint32_t size, int is_file_name);
|
||||||
|
|
||||||
|
void aacenc_add_tag_entry_to_store(void *store, const aacenc_tag_entry_t *tag);
|
||||||
|
|
||||||
|
void aacenc_free_tag_store(aacenc_tag_store_t *store);
|
||||||
|
|
||||||
|
void aacenc_write_tags_from_json(m4af_ctx_t *m4af, const char *json_filename);
|
||||||
|
|
||||||
|
void aacenc_write_tag_entry(void *m4af, const aacenc_tag_entry_t *tag);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,6 +17,21 @@ struct pcm_reader_t {
|
|||||||
pcm_reader_vtbl_t *vtbl;
|
pcm_reader_vtbl_t *vtbl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef int (*pcm_read_callback)(void *cookie, void *data, uint32_t count);
|
||||||
|
typedef int (*pcm_seek_callback)(void *cookie, int64_t off, int whence);
|
||||||
|
typedef int64_t (*pcm_tell_callback)(void *cookie);
|
||||||
|
|
||||||
|
typedef struct pcm_io_vtbl_t {
|
||||||
|
pcm_read_callback read;
|
||||||
|
pcm_seek_callback seek;
|
||||||
|
pcm_tell_callback tell;
|
||||||
|
} pcm_io_vtbl_t;
|
||||||
|
|
||||||
|
typedef struct pcm_io_context_t {
|
||||||
|
pcm_io_vtbl_t *vtbl;
|
||||||
|
void *cookie;
|
||||||
|
} pcm_io_context_t;
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
const pcm_sample_description_t *pcm_get_format(pcm_reader_t *r)
|
const pcm_sample_description_t *pcm_get_format(pcm_reader_t *r)
|
||||||
{
|
{
|
||||||
@ -47,6 +62,51 @@ void pcm_teardown(pcm_reader_t **r)
|
|||||||
(*r)->vtbl->teardown(r);
|
(*r)->vtbl->teardown(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
uint32_t bitcount(uint32_t bits)
|
||||||
|
{
|
||||||
|
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
|
||||||
|
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
|
||||||
|
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
|
||||||
|
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
|
||||||
|
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TRY_IO(expr) \
|
||||||
|
do { \
|
||||||
|
if ((expr)) goto FAIL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ENSURE(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) goto FAIL;\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size);
|
||||||
|
int pcm_skip(pcm_io_context_t *io, int64_t count);
|
||||||
|
|
||||||
|
static int pcm_seek(pcm_io_context_t *io, int64_t off, int whence)
|
||||||
|
{
|
||||||
|
return io->vtbl->seek ? io->vtbl->seek(io->cookie, off, whence) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int64_t pcm_tell(pcm_io_context_t *io)
|
||||||
|
{
|
||||||
|
return io->vtbl->tell ? io->vtbl->tell(io->cookie) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read16le(pcm_io_context_t *io, uint16_t *value);
|
||||||
|
int pcm_read16be(pcm_io_context_t *io, uint16_t *value);
|
||||||
|
int pcm_read32le(pcm_io_context_t *io, uint32_t *value);
|
||||||
|
int pcm_read32be(pcm_io_context_t *io, uint32_t *value);
|
||||||
|
int pcm_read64le(pcm_io_context_t *io, uint64_t *value);
|
||||||
|
int pcm_read64be(pcm_io_context_t *io, uint64_t *value);
|
||||||
|
int pcm_scanl(pcm_io_context_t *io, const char *fmt, ...);
|
||||||
|
int pcm_scanb(pcm_io_context_t *io, const char *fmt, ...);
|
||||||
|
|
||||||
|
int apple_chan_chunk(pcm_io_context_t *io, uint32_t chunk_size,
|
||||||
|
pcm_sample_description_t *fmt, uint8_t *mapping);
|
||||||
|
|
||||||
pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader);
|
pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
356
src/pcm_readhelper.c
Normal file
356
src/pcm_readhelper.c
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "pcm_reader.h"
|
||||||
|
#include "m4af_endian.h"
|
||||||
|
#include "catypes.h"
|
||||||
|
|
||||||
|
int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
uint32_t count = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rc = io->vtbl->read(io->cookie, buffer, size - count);
|
||||||
|
if (rc > 0)
|
||||||
|
count += rc;
|
||||||
|
} while (rc > 0 && count < size);
|
||||||
|
return count > 0 ? count : rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_skip(pcm_io_context_t *io, int64_t count)
|
||||||
|
{
|
||||||
|
char buff[8192];
|
||||||
|
int rc;
|
||||||
|
pcm_io_vtbl_t *vp = io->vtbl;
|
||||||
|
|
||||||
|
if (count == 0 || pcm_seek(io, count, SEEK_CUR) >= 0)
|
||||||
|
return 0;
|
||||||
|
do {
|
||||||
|
if ((rc = vp->read(io->cookie, buff, count > 8192 ? 8192 : count)) > 0)
|
||||||
|
count -= rc;
|
||||||
|
} while (rc > 0 && count > 0);
|
||||||
|
|
||||||
|
return count == 0 ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read16le(pcm_io_context_t *io, uint16_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 2) == 2) {
|
||||||
|
*value = m4af_ltoh16(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read16be(pcm_io_context_t *io, uint16_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 2) == 2) {
|
||||||
|
*value = m4af_btoh16(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read32le(pcm_io_context_t *io, uint32_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 4) == 4) {
|
||||||
|
*value = m4af_ltoh32(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read32be(pcm_io_context_t *io, uint32_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 4) == 4) {
|
||||||
|
*value = m4af_btoh32(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read64le(pcm_io_context_t *io, uint64_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 8) == 8) {
|
||||||
|
*value = m4af_ltoh64(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_read64be(pcm_io_context_t *io, uint64_t *value)
|
||||||
|
{
|
||||||
|
if (pcm_read(io, value, 8) == 8) {
|
||||||
|
*value = m4af_btoh64(*value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_scanl(pcm_io_context_t *io, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int c, count = 0;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
while ((c = *fmt++)) {
|
||||||
|
switch (c) {
|
||||||
|
case 'S':
|
||||||
|
TRY_IO(pcm_read16le(io, va_arg(ap, uint16_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
TRY_IO(pcm_read32le(io, va_arg(ap, uint32_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
TRY_IO(pcm_read64le(io, va_arg(ap, uint64_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FAIL:
|
||||||
|
va_end(ap);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pcm_scanb(pcm_io_context_t *io, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int c, count = 0;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
while ((c = *fmt++)) {
|
||||||
|
switch (c) {
|
||||||
|
case 'S':
|
||||||
|
TRY_IO(pcm_read16be(io, va_arg(ap, uint16_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
TRY_IO(pcm_read32be(io, va_arg(ap, uint32_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
TRY_IO(pcm_read64be(io, va_arg(ap, uint64_t*)));
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FAIL:
|
||||||
|
va_end(ap);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int channel_compare(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return (*(const uint8_t **)a)[0] - (*(const uint8_t **)b)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void apple_translate_channel_labels(uint8_t *channels, unsigned n)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
char *has_side = strpbrk((char*)channels, "\x0A\x0B");
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
switch (channels[i]) {
|
||||||
|
case kAudioChannelLabel_LeftSurround:
|
||||||
|
case kAudioChannelLabel_RightSurround:
|
||||||
|
if (!has_side) channels[i] += 5; // map to SL/SR
|
||||||
|
break;
|
||||||
|
case kAudioChannelLabel_RearSurroundLeft:
|
||||||
|
case kAudioChannelLabel_RearSurroundRight:
|
||||||
|
if (!has_side) channels[i] -= 28; // map to BL/BR
|
||||||
|
break;
|
||||||
|
case kAudioChannelLabel_Mono:
|
||||||
|
channels[i] = kAudioChannelLabel_Center;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int apple_chan_chunk(pcm_io_context_t *io, uint32_t chunk_size,
|
||||||
|
pcm_sample_description_t *fmt, uint8_t *mapping)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Although FDK encoder supports upto 5.1ch, we handle upto
|
||||||
|
* 8 channels here.
|
||||||
|
*/
|
||||||
|
uint32_t i, mChannelLayoutTag, mChannelBitmap, mNumberChannelDescriptions;
|
||||||
|
uint32_t mask = 0;
|
||||||
|
const uint32_t nchannels = fmt->channels_per_frame;
|
||||||
|
uint8_t channels[9] = { 0 };
|
||||||
|
uint8_t *index[8] = { 0 };
|
||||||
|
const char *layout = 0;
|
||||||
|
|
||||||
|
ENSURE(chunk_size >= 12);
|
||||||
|
TRY_IO(pcm_scanb(io, "LLL", &mChannelLayoutTag, &mChannelBitmap,
|
||||||
|
&mNumberChannelDescriptions) != 3);
|
||||||
|
|
||||||
|
switch (mChannelLayoutTag) {
|
||||||
|
case kAudioChannelLayoutTag_UseChannelBitmap:
|
||||||
|
ENSURE(bitcount(mask) == nchannels);
|
||||||
|
TRY_IO(pcm_skip(io, chunk_size - 12));
|
||||||
|
fmt->channel_mask = mChannelBitmap;
|
||||||
|
for (i = 0; i < nchannels; ++i)
|
||||||
|
mapping[i] = i;
|
||||||
|
return 0;
|
||||||
|
case kAudioChannelLayoutTag_UseChannelDescriptions:
|
||||||
|
ENSURE(mNumberChannelDescriptions == nchannels);
|
||||||
|
ENSURE(chunk_size >= 12 + nchannels * 20);
|
||||||
|
for (i = 0; i < mNumberChannelDescriptions; ++i) {
|
||||||
|
uint32_t mChannelLabel;
|
||||||
|
TRY_IO(pcm_read32be(io, &mChannelLabel));
|
||||||
|
ENSURE(mChannelLabel && mChannelLabel <= 0xff);
|
||||||
|
channels[i] = mChannelLabel;
|
||||||
|
TRY_IO(pcm_skip(io, 16));
|
||||||
|
}
|
||||||
|
TRY_IO(pcm_skip(io, chunk_size - 12 - nchannels * 20));
|
||||||
|
apple_translate_channel_labels(channels, nchannels);
|
||||||
|
for (i = 0; i < nchannels; ++i)
|
||||||
|
if (channels[i] > kAudioChannelLabel_TopBackLeft)
|
||||||
|
goto FAIL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ENSURE((mChannelLayoutTag & 0xffff) == nchannels);
|
||||||
|
TRY_IO(pcm_skip(io, chunk_size - 12));
|
||||||
|
|
||||||
|
switch (mChannelLayoutTag) {
|
||||||
|
/* 1ch */
|
||||||
|
case kAudioChannelLayoutTag_Mono:
|
||||||
|
layout = "\x03"; break;
|
||||||
|
/* 1.1ch */
|
||||||
|
case kAudioChannelLayoutTag_AC3_1_0_1:
|
||||||
|
layout = "\x03\x04"; break;
|
||||||
|
/* 2ch */
|
||||||
|
case kAudioChannelLayoutTag_Stereo:
|
||||||
|
case kAudioChannelLayoutTag_MatrixStereo:
|
||||||
|
case kAudioChannelLayoutTag_Binaural:
|
||||||
|
layout = "\x01\x02"; break;
|
||||||
|
/* 2.1ch */
|
||||||
|
case kAudioChannelLayoutTag_DVD_4:
|
||||||
|
layout = "\x01\x02\x04"; break;
|
||||||
|
/* 3ch */
|
||||||
|
case kAudioChannelLayoutTag_MPEG_3_0_A:
|
||||||
|
layout = "\x01\x02\x03"; break;
|
||||||
|
case kAudioChannelLayoutTag_AC3_3_0:
|
||||||
|
layout = "\x01\x03\x02"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_3_0_B:
|
||||||
|
layout = "\x03\x01\x02"; break;
|
||||||
|
case kAudioChannelLayoutTag_ITU_2_1:
|
||||||
|
layout = "\x01\x02\x09"; break;
|
||||||
|
/* 3.1ch */
|
||||||
|
case kAudioChannelLayoutTag_DVD_10:
|
||||||
|
layout = "\x01\x02\x03\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_AC3_3_0_1:
|
||||||
|
layout = "\x01\x03\x02\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_DVD_5:
|
||||||
|
layout = "\x01\x02\x04\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_AC3_2_1_1:
|
||||||
|
layout = "\x01\x02\x09\x04"; break;
|
||||||
|
/* 4ch */
|
||||||
|
case kAudioChannelLayoutTag_Quadraphonic:
|
||||||
|
case kAudioChannelLayoutTag_ITU_2_2:
|
||||||
|
layout = "\x01\x02\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_4_0_A:
|
||||||
|
layout = "\x01\x02\x03\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_4_0_B:
|
||||||
|
layout = "\x03\x01\x02\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_AC3_3_1:
|
||||||
|
layout = "\x01\x03\x02\x09"; break;
|
||||||
|
/* 4.1ch */
|
||||||
|
case kAudioChannelLayoutTag_DVD_6:
|
||||||
|
layout = "\x01\x02\x04\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_DVD_18:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_DVD_11:
|
||||||
|
layout = "\x01\x02\x03\x04\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_AC3_3_1_1:
|
||||||
|
layout = "\x01\x03\x02\x09\x04"; break;
|
||||||
|
/* 5ch */
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_0_A:
|
||||||
|
layout = "\x01\x02\x03\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_Pentagonal:
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_0_B:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_0_C:
|
||||||
|
layout = "\x01\x03\x02\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_0_D:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B"; break;
|
||||||
|
/* 5.1ch */
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_1_A:
|
||||||
|
layout = "\x01\x02\x03\x04\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_1_B:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_1_C:
|
||||||
|
layout = "\x01\x03\x02\x0A\x0B\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_5_1_D:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B\x04"; break;
|
||||||
|
/* 6ch */
|
||||||
|
case kAudioChannelLayoutTag_Hexagonal:
|
||||||
|
case kAudioChannelLayoutTag_AudioUnit_6_0:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_AAC_6_0:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B\x09"; break;
|
||||||
|
/* 6.1ch */
|
||||||
|
case kAudioChannelLayoutTag_MPEG_6_1_A:
|
||||||
|
layout = "\x01\x02\x03\x04\x0A\x0B\x09"; break;
|
||||||
|
case kAudioChannelLayoutTag_AAC_6_1:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B\x09\x04"; break;
|
||||||
|
/* 7ch */
|
||||||
|
case kAudioChannelLayoutTag_AudioUnit_7_0:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03\x05\x06"; break;
|
||||||
|
case kAudioChannelLayoutTag_AudioUnit_7_0_Front:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03\x07\x08"; break;
|
||||||
|
case kAudioChannelLayoutTag_AAC_7_0:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B\x05\x06"; break;
|
||||||
|
/* 7.1ch */
|
||||||
|
case kAudioChannelLayoutTag_MPEG_7_1_A:
|
||||||
|
layout = "\x01\x02\x03\x04\x0A\x0B\x07\x08"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_7_1_B:
|
||||||
|
layout = "\x03\x07\x08\x01\x02\x05\x06\x04"; break;
|
||||||
|
case kAudioChannelLayoutTag_MPEG_7_1_C:
|
||||||
|
layout = "\x01\x02\x03\x04\x0A\x0B\x05\x06"; break;
|
||||||
|
case kAudioChannelLayoutTag_Emagic_Default_7_1:
|
||||||
|
layout = "\x01\x02\x0A\x0B\x03\x04\x07\x08"; break;
|
||||||
|
/* 8ch */
|
||||||
|
case kAudioChannelLayoutTag_Octagonal:
|
||||||
|
layout = "\x01\x02\x05\x06\x03\x09\x0A\x0B"; break;
|
||||||
|
case kAudioChannelLayoutTag_AAC_Octagonal:
|
||||||
|
layout = "\x03\x01\x02\x0A\x0B\x05\x06\x09"; break;
|
||||||
|
default:
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
|
strcpy((char*)channels, layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < nchannels; ++i)
|
||||||
|
mask |= 1 << (channels[i] - 1);
|
||||||
|
fmt->channel_mask = mask;
|
||||||
|
ENSURE(bitcount(mask) == nchannels);
|
||||||
|
|
||||||
|
for (i = 0; i < nchannels; ++i)
|
||||||
|
index[i] = channels + i;
|
||||||
|
qsort(index, nchannels, sizeof(char*), channel_compare);
|
||||||
|
for (i = 0; i < nchannels; ++i)
|
||||||
|
mapping[i] = index[i] - channels;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
FAIL:
|
||||||
|
return -1;
|
||||||
|
}
|
248
src/wav_reader.c
248
src/wav_reader.c
@ -15,36 +15,18 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "wav_reader.h"
|
#include "wav_reader.h"
|
||||||
#include "m4af_endian.h"
|
|
||||||
|
|
||||||
#define RIFF_FOURCC(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
|
#define RIFF_FOURCC(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
|
||||||
|
|
||||||
#define TRY_IO(expr) \
|
typedef struct wav_reader_t {
|
||||||
do { \
|
|
||||||
if (expr) \
|
|
||||||
goto FAIL; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define ASSERT_FORMAT(ctx, expr) \
|
|
||||||
do { \
|
|
||||||
if (!expr) { \
|
|
||||||
if (!ctx->last_error) \
|
|
||||||
ctx->last_error = WAV_INVALID_FORMAT; \
|
|
||||||
goto FAIL;\
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
struct wav_reader_t {
|
|
||||||
pcm_reader_vtbl_t *vtbl;
|
pcm_reader_vtbl_t *vtbl;
|
||||||
pcm_sample_description_t sample_format;
|
pcm_sample_description_t sample_format;
|
||||||
int64_t length;
|
int64_t length;
|
||||||
int64_t position;
|
int64_t position;
|
||||||
int32_t data_offset;
|
int32_t data_offset;
|
||||||
int ignore_length;
|
int ignore_length;
|
||||||
int last_error;
|
pcm_io_context_t io;
|
||||||
wav_io_context_t io;
|
} wav_reader_t;
|
||||||
void *io_cookie;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t WAV_GUID_PCM[] = {
|
static const uint8_t WAV_GUID_PCM[] = {
|
||||||
1, 0, 0, 0, 0, 0, 0x10, 0, 0x80, 0, 0, 0xaa, 0, 0x38, 0x9b, 0x71
|
1, 0, 0, 0, 0, 0, 0x10, 0, 0x80, 0, 0, 0xaa, 0, 0x38, 0x9b, 0x71
|
||||||
@ -74,144 +56,11 @@ static void wav_teardown(pcm_reader_t **reader)
|
|||||||
*reader = 0;
|
*reader = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
int riff_read(wav_reader_t *reader, void *buffer, uint32_t size)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
uint32_t count = 0;
|
|
||||||
|
|
||||||
if (reader->last_error)
|
|
||||||
return -1;
|
|
||||||
do {
|
|
||||||
rc = reader->io.read(reader->io_cookie, buffer, size - count);
|
|
||||||
if (rc > 0)
|
|
||||||
count += rc;
|
|
||||||
else if (rc < 0)
|
|
||||||
reader->last_error = WAV_IO_ERROR;
|
|
||||||
} while (rc > 0 && count < size);
|
|
||||||
return count > 0 ? count : rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_skip(wav_reader_t *reader, int64_t count)
|
|
||||||
{
|
|
||||||
char buff[8192];
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (reader->last_error)
|
|
||||||
return -1;
|
|
||||||
if (count == 0)
|
|
||||||
return 0;
|
|
||||||
if (reader->io.seek &&
|
|
||||||
reader->io.seek(reader->io_cookie, count, SEEK_CUR) >= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if ((rc = riff_read(reader, buff, count > 8192 ? 8192 : count)) > 0)
|
|
||||||
count -= rc;
|
|
||||||
} while (rc > 0 && count > 0);
|
|
||||||
|
|
||||||
if (count > 0)
|
|
||||||
reader->last_error = WAV_IO_ERROR;
|
|
||||||
return reader->last_error ? -1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_seek(wav_reader_t *reader, int64_t off, int whence)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
if (reader->last_error)
|
|
||||||
return -1;
|
|
||||||
if (!reader->io.seek)
|
|
||||||
goto FAIL;
|
|
||||||
if ((rc = reader->io.seek(reader->io_cookie, off, whence)) < 0)
|
|
||||||
goto FAIL;
|
|
||||||
return 0;
|
|
||||||
FAIL:
|
|
||||||
reader->last_error = WAV_IO_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int64_t riff_tell(wav_reader_t *reader)
|
|
||||||
{
|
|
||||||
int64_t off;
|
|
||||||
|
|
||||||
if (reader->last_error || !reader->io.tell)
|
|
||||||
return -1;
|
|
||||||
off = reader->io.tell(reader->io_cookie);
|
|
||||||
if (off < 0) {
|
|
||||||
reader->last_error = WAV_IO_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return off;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_read16(wav_reader_t *reader, uint16_t *value)
|
|
||||||
{
|
|
||||||
TRY_IO(riff_read(reader, value, 2) != 2);
|
|
||||||
*value = m4af_ltoh16(*value);
|
|
||||||
return 0;
|
|
||||||
FAIL:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_read32(wav_reader_t *reader, uint32_t *value)
|
|
||||||
{
|
|
||||||
TRY_IO(riff_read(reader, value, 4) != 4);
|
|
||||||
*value = m4af_ltoh32(*value);
|
|
||||||
return 0;
|
|
||||||
FAIL:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_read64(wav_reader_t *reader, uint64_t *value)
|
|
||||||
{
|
|
||||||
TRY_IO(riff_read(reader, value, 8) != 8);
|
|
||||||
*value = m4af_ltoh64(*value);
|
|
||||||
return 0;
|
|
||||||
FAIL:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
int riff_scan(wav_reader_t *reader, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
int c, count = 0;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
while ((c = *fmt++)) {
|
|
||||||
switch (c) {
|
|
||||||
case 'S':
|
|
||||||
TRY_IO(riff_read16(reader, va_arg(ap, uint16_t*)));
|
|
||||||
++count;
|
|
||||||
break;
|
|
||||||
case 'L':
|
|
||||||
TRY_IO(riff_read32(reader, va_arg(ap, uint32_t*)));
|
|
||||||
++count;
|
|
||||||
break;
|
|
||||||
case 'Q':
|
|
||||||
TRY_IO(riff_read64(reader, va_arg(ap, uint64_t*)));
|
|
||||||
++count;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FAIL:
|
|
||||||
va_end(ap);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
uint32_t riff_next_chunk(wav_reader_t *reader, uint32_t *chunk_size)
|
uint32_t riff_next_chunk(wav_reader_t *reader, uint32_t *chunk_size)
|
||||||
{
|
{
|
||||||
uint32_t fcc;
|
uint32_t fcc;
|
||||||
if (riff_scan(reader, "LL", &fcc, chunk_size) == 2)
|
return (pcm_scanl(&reader->io, "LL", &fcc, chunk_size) == 2) ? fcc : 0;
|
||||||
return fcc;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -225,7 +74,7 @@ int wav_read_frames(pcm_reader_t *preader, void *buffer, unsigned nframes)
|
|||||||
nframes = reader->length - reader->position;
|
nframes = reader->length - reader->position;
|
||||||
nbytes = nframes * reader->sample_format.bytes_per_frame;
|
nbytes = nframes * reader->sample_format.bytes_per_frame;
|
||||||
if (nbytes) {
|
if (nbytes) {
|
||||||
if ((rc = riff_read(reader, buffer, nbytes)) < 0)
|
if ((rc = pcm_read(&reader->io, buffer, nbytes)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
nframes = rc / reader->sample_format.bytes_per_frame;
|
nframes = rc / reader->sample_format.bytes_per_frame;
|
||||||
reader->position += nframes;
|
reader->position += nframes;
|
||||||
@ -240,11 +89,10 @@ int riff_ds64(wav_reader_t *reader, int64_t *length)
|
|||||||
uint64_t riff_size, sample_count;
|
uint64_t riff_size, sample_count;
|
||||||
|
|
||||||
fcc = riff_next_chunk(reader, &chunk_size);
|
fcc = riff_next_chunk(reader, &chunk_size);
|
||||||
ASSERT_FORMAT(reader,
|
ENSURE(fcc == RIFF_FOURCC('d','s','6','4') && chunk_size >= 28);
|
||||||
fcc == RIFF_FOURCC('d','s','6','4') && chunk_size >= 28);
|
TRY_IO(pcm_scanl(&reader->io, "QQQL",
|
||||||
TRY_IO(riff_scan(reader, "QQQL",
|
|
||||||
&riff_size, length, &sample_count, &table_size) != 4);
|
&riff_size, length, &sample_count, &table_size) != 4);
|
||||||
TRY_IO(riff_skip(reader, (chunk_size - 27) & ~1));
|
TRY_IO(pcm_skip(&reader->io, (chunk_size - 27) & ~1));
|
||||||
reader->data_offset += (chunk_size + 9) & ~1;
|
reader->data_offset += (chunk_size + 9) & ~1;
|
||||||
FAIL:
|
FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
@ -259,41 +107,34 @@ int wav_fmt(wav_reader_t *reader, uint32_t size)
|
|||||||
uint8_t guid[16];
|
uint8_t guid[16];
|
||||||
int is_float = 0;
|
int is_float = 0;
|
||||||
|
|
||||||
ASSERT_FORMAT(reader, size >= 16);
|
ENSURE(size >= 16);
|
||||||
TRY_IO(riff_scan(reader, "SSLLSS", &wFormatTag, &nChannels,
|
TRY_IO(pcm_scanl(&reader->io, "SSLLSS", &wFormatTag, &nChannels,
|
||||||
&nSamplesPerSec, &nAvgBytesPerSec, &nBlockAlign,
|
&nSamplesPerSec, &nAvgBytesPerSec, &nBlockAlign,
|
||||||
&wBitsPerSample) != 6);
|
&wBitsPerSample) != 6);
|
||||||
wValidBitsPerSample = wBitsPerSample;
|
wValidBitsPerSample = wBitsPerSample;
|
||||||
|
|
||||||
if (wFormatTag != 1 && wFormatTag != 3 && wFormatTag != 0xfffe) {
|
ENSURE(wFormatTag == 1 || wFormatTag == 3 || wFormatTag == 0xfffe);
|
||||||
reader->last_error = WAV_UNSUPPORTED_FORMAT;
|
ENSURE(nChannels && nSamplesPerSec && nAvgBytesPerSec &&
|
||||||
goto FAIL;
|
nBlockAlign && wBitsPerSample && !(wBitsPerSample & 7) &&
|
||||||
}
|
nBlockAlign == nChannels * wBitsPerSample / 8);
|
||||||
ASSERT_FORMAT(reader,
|
|
||||||
nChannels && nSamplesPerSec && nAvgBytesPerSec &&
|
|
||||||
nBlockAlign && wBitsPerSample && !(wBitsPerSample & 7) &&
|
|
||||||
nBlockAlign == nChannels * wBitsPerSample / 8);
|
|
||||||
if (wFormatTag == 3)
|
if (wFormatTag == 3)
|
||||||
is_float = 1;
|
is_float = 1;
|
||||||
|
|
||||||
if (wFormatTag != 0xfffe)
|
if (wFormatTag != 0xfffe)
|
||||||
TRY_IO(riff_skip(reader, (size - 15) & ~1));
|
TRY_IO(pcm_skip(&reader->io, (size - 15) & ~1));
|
||||||
else {
|
else {
|
||||||
ASSERT_FORMAT(reader, size >= 40);
|
ENSURE(size >= 40);
|
||||||
TRY_IO(riff_scan(reader, "SSL",
|
TRY_IO(pcm_scanl(&reader->io, "SSL",
|
||||||
&cbSize, &wValidBitsPerSample, &dwChannelMask) != 3);
|
&cbSize, &wValidBitsPerSample, &dwChannelMask) != 3);
|
||||||
TRY_IO(riff_read(reader, guid, 16) != 16);
|
TRY_IO(pcm_read(&reader->io, guid, 16) != 16);
|
||||||
|
|
||||||
if (memcmp(guid, WAV_GUID_FLOAT, 16) == 0)
|
if (memcmp(guid, WAV_GUID_FLOAT, 16) == 0)
|
||||||
is_float = 1;
|
is_float = 1;
|
||||||
else if (memcmp(guid, WAV_GUID_PCM, 16) != 0) {
|
else if (memcmp(guid, WAV_GUID_PCM, 16) != 0)
|
||||||
reader->last_error = WAV_UNSUPPORTED_FORMAT;
|
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
ENSURE(wValidBitsPerSample && wValidBitsPerSample <= wBitsPerSample);
|
||||||
ASSERT_FORMAT(reader,
|
TRY_IO(pcm_skip(&reader->io, (size - 39) & ~1));
|
||||||
wValidBitsPerSample &&
|
|
||||||
wValidBitsPerSample <= wBitsPerSample);
|
|
||||||
TRY_IO(riff_skip(reader, (size - 39) & ~1));
|
|
||||||
}
|
}
|
||||||
reader->sample_format.sample_rate = nSamplesPerSec;
|
reader->sample_format.sample_rate = nSamplesPerSec;
|
||||||
reader->sample_format.bits_per_channel = wValidBitsPerSample;
|
reader->sample_format.bits_per_channel = wValidBitsPerSample;
|
||||||
@ -318,12 +159,10 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
|
|
||||||
*data_length = 0;
|
*data_length = 0;
|
||||||
container = riff_next_chunk(reader, &chunk_size);
|
container = riff_next_chunk(reader, &chunk_size);
|
||||||
if (container != RIFF_FOURCC('R','I','F','F') &&
|
ENSURE(container == RIFF_FOURCC('R','I','F','F') ||
|
||||||
container != RIFF_FOURCC('R','F','6','4'))
|
container == RIFF_FOURCC('R','F','6','4'));
|
||||||
goto FAIL;
|
TRY_IO(pcm_read32le(&reader->io, &fcc));
|
||||||
TRY_IO(riff_read32(reader, &fcc));
|
ENSURE(fcc == RIFF_FOURCC('W','A','V','E'));
|
||||||
if (fcc != RIFF_FOURCC('W','A','V','E'))
|
|
||||||
goto FAIL;
|
|
||||||
reader->data_offset = 12;
|
reader->data_offset = 12;
|
||||||
|
|
||||||
if (container == RIFF_FOURCC('R','F','6','4'))
|
if (container == RIFF_FOURCC('R','F','6','4'))
|
||||||
@ -338,7 +177,7 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
reader->data_offset += 8;
|
reader->data_offset += 8;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
TRY_IO(riff_skip(reader, (chunk_size + 1) & ~1));
|
TRY_IO(pcm_skip(&reader->io, (chunk_size + 1) & ~1));
|
||||||
}
|
}
|
||||||
reader->data_offset += (chunk_size + 9) & ~1;
|
reader->data_offset += (chunk_size + 9) & ~1;
|
||||||
}
|
}
|
||||||
@ -356,8 +195,7 @@ static pcm_reader_vtbl_t wav_vtable = {
|
|||||||
wav_teardown
|
wav_teardown
|
||||||
};
|
};
|
||||||
|
|
||||||
pcm_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
pcm_reader_t *wav_open(pcm_io_context_t *io, int ignore_length)
|
||||||
int ignore_length)
|
|
||||||
{
|
{
|
||||||
wav_reader_t *reader = 0;
|
wav_reader_t *reader = 0;
|
||||||
int64_t data_length;
|
int64_t data_length;
|
||||||
@ -365,8 +203,7 @@ pcm_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
|||||||
|
|
||||||
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
memcpy(&reader->io, io_ctx, sizeof(wav_io_context_t));
|
memcpy(&reader->io, io, sizeof(pcm_io_context_t));
|
||||||
reader->io_cookie = io_cookie;
|
|
||||||
reader->ignore_length = ignore_length;
|
reader->ignore_length = ignore_length;
|
||||||
if (wav_parse(reader, &data_length) < 0) {
|
if (wav_parse(reader, &data_length) < 0) {
|
||||||
free(reader);
|
free(reader);
|
||||||
@ -378,39 +215,34 @@ pcm_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
|||||||
else
|
else
|
||||||
reader->length = data_length / bpf;
|
reader->length = data_length / bpf;
|
||||||
|
|
||||||
if (reader->length == INT64_MAX && reader->io.seek && reader->io.tell) {
|
if (reader->length == INT64_MAX) {
|
||||||
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
if (pcm_seek(&reader->io, 0, SEEK_END) >= 0) {
|
||||||
int64_t size = reader->io.tell(reader->io_cookie);
|
int64_t size = pcm_tell(&reader->io);
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
reader->length = (size - reader->data_offset) / bpf;
|
reader->length = (size - reader->data_offset) / bpf;
|
||||||
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
pcm_seek(&reader->io, reader->data_offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader->vtbl = &wav_vtable;
|
reader->vtbl = &wav_vtable;
|
||||||
return (pcm_reader_t *)reader;
|
return (pcm_reader_t *)reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcm_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
pcm_reader_t *raw_open(pcm_io_context_t *io,
|
||||||
const pcm_sample_description_t *desc)
|
const pcm_sample_description_t *desc)
|
||||||
{
|
{
|
||||||
wav_reader_t *reader = 0;
|
wav_reader_t *reader = 0;
|
||||||
|
|
||||||
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
memcpy(&reader->io, io_ctx, sizeof(wav_io_context_t));
|
memcpy(&reader->io, io, sizeof(pcm_io_context_t));
|
||||||
memcpy(&reader->sample_format, desc, sizeof(pcm_sample_description_t));
|
memcpy(&reader->sample_format, desc, sizeof(pcm_sample_description_t));
|
||||||
reader->io_cookie = io_cookie;
|
if (pcm_seek(&reader->io, 0, SEEK_END) >= 0) {
|
||||||
if (io_ctx->seek && io_ctx->tell) {
|
int64_t size = pcm_tell(&reader->io);
|
||||||
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
if (size > 0)
|
||||||
int64_t size = reader->io.tell(reader->io_cookie);
|
reader->length = size / reader->sample_format.bytes_per_frame;
|
||||||
if (size > 0)
|
pcm_seek(&reader->io, 0, SEEK_SET);
|
||||||
reader->length = size / desc->bytes_per_frame;
|
|
||||||
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
reader->length = INT64_MAX;
|
reader->length = INT64_MAX;
|
||||||
reader->vtbl = &wav_vtable;
|
reader->vtbl = &wav_vtable;
|
||||||
return (pcm_reader_t *)reader;
|
return (pcm_reader_t *)reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,28 +8,8 @@
|
|||||||
#include "lpcm.h"
|
#include "lpcm.h"
|
||||||
#include "pcm_reader.h"
|
#include "pcm_reader.h"
|
||||||
|
|
||||||
enum wav_error_code {
|
pcm_reader_t *wav_open(pcm_io_context_t *io, int ignore_length);
|
||||||
WAV_IO_ERROR = 1,
|
pcm_reader_t *raw_open(pcm_io_context_t *io,
|
||||||
WAV_NO_MEMORY,
|
|
||||||
WAV_INVALID_FORMAT,
|
|
||||||
WAV_UNSUPPORTED_FORMAT
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef int (*wav_read_callback)(void *cookie, void *data, uint32_t size);
|
|
||||||
typedef int (*wav_seek_callback)(void *cookie, int64_t off, int whence);
|
|
||||||
typedef int64_t (*wav_tell_callback)(void *cookie);
|
|
||||||
|
|
||||||
typedef struct wav_io_context_t {
|
|
||||||
wav_read_callback read;
|
|
||||||
wav_seek_callback seek;
|
|
||||||
wav_tell_callback tell;
|
|
||||||
} wav_io_context_t;
|
|
||||||
|
|
||||||
typedef struct wav_reader_t wav_reader_t;
|
|
||||||
|
|
||||||
pcm_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
|
||||||
int ignore_length);
|
|
||||||
pcm_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
|
||||||
const pcm_sample_description_t *desc);
|
const pcm_sample_description_t *desc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user