mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
Remove ATRAC3 specific fields (channels, extradata_size) from mp3entry
Also fixes typo of using never initialized id3->channels in wav metadata (introduced in 2d1937a1
)
Change-Id: I28cddec2b9d9bd1e756ffaa004b4f6e8528a7566
This commit is contained in:
parent
be16edc94b
commit
76ec55cc49
11 changed files with 22 additions and 35 deletions
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include "logf.h"
|
#include "logf.h"
|
||||||
#include "codeclib.h"
|
#include "codeclib.h"
|
||||||
#include "inttypes.h"
|
|
||||||
#include "libatrac/atrac3.h"
|
#include "libatrac/atrac3.h"
|
||||||
|
|
||||||
CODEC_HEADER
|
CODEC_HEADER
|
||||||
|
@ -66,12 +65,16 @@ enum codec_status codec_run(void)
|
||||||
|
|
||||||
ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
|
ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
|
||||||
ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */
|
ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */
|
||||||
ci->configure(DSP_SET_STEREO_MODE, ci->id3->channels == 1 ?
|
const uint8_t channels = 2;
|
||||||
|
ci->configure(DSP_SET_STEREO_MODE, channels == 1 ?
|
||||||
STEREO_MONO : STEREO_NONINTERLEAVED);
|
STEREO_MONO : STEREO_NONINTERLEAVED);
|
||||||
|
|
||||||
ci->seek_buffer(0);
|
ci->seek_buffer(0);
|
||||||
|
|
||||||
res = atrac3_decode_init(&q, ci->id3);
|
/* fake the atrac3 extradata (wav format, makes stream copy to wav work) */
|
||||||
|
/* ATRAC3 expects and extra-data size of 14 bytes for wav format, and *
|
||||||
|
* looks for that in the id3v2buf. */
|
||||||
|
res = atrac3_decode_init(&q, ci->id3, channels, 14);
|
||||||
if(res < 0) {
|
if(res < 0) {
|
||||||
DEBUGF("failed to initialize OMA atrac decoder\n");
|
DEBUGF("failed to initialize OMA atrac decoder\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
|
@ -143,7 +146,7 @@ enum codec_status codec_run(void)
|
||||||
|
|
||||||
if(datasize)
|
if(datasize)
|
||||||
ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024,
|
ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024,
|
||||||
q.samples_per_frame / ci->id3->channels);
|
q.samples_per_frame / channels);
|
||||||
|
|
||||||
elapsed += (FRAMESIZE * 8) / BITRATE;
|
elapsed += (FRAMESIZE * 8) / BITRATE;
|
||||||
ci->set_elapsed(elapsed);
|
ci->set_elapsed(elapsed);
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "codeclib.h"
|
#include "codeclib.h"
|
||||||
#include "inttypes.h"
|
|
||||||
#include "libatrac/atrac3.h"
|
#include "libatrac/atrac3.h"
|
||||||
|
|
||||||
CODEC_HEADER
|
CODEC_HEADER
|
||||||
|
@ -109,7 +108,7 @@ enum codec_status codec_run(void)
|
||||||
scrambling_unit_size = h * (fs + packet_header_size);
|
scrambling_unit_size = h * (fs + packet_header_size);
|
||||||
spn = h * fs / sps;
|
spn = h * fs / sps;
|
||||||
|
|
||||||
res = atrac3_decode_init(&q, ci->id3);
|
res = atrac3_decode_init(&q, ci->id3, rmctx.nb_channels, rmctx.extradata_size);
|
||||||
if(res < 0) {
|
if(res < 0) {
|
||||||
DEBUGF("failed to initialize RM atrac decoder\n");
|
DEBUGF("failed to initialize RM atrac decoder\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
|
|
|
@ -1157,7 +1157,7 @@ int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q,
|
||||||
*
|
*
|
||||||
* @param rmctx pointer to the RMContext
|
* @param rmctx pointer to the RMContext
|
||||||
*/
|
*/
|
||||||
int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3)
|
int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3, uint16_t channels, uint32_t extradata_size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t *edata_ptr = (uint8_t*)&id3->id3v2buf;
|
uint8_t *edata_ptr = (uint8_t*)&id3->id3v2buf;
|
||||||
|
@ -1168,14 +1168,14 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3)
|
||||||
|
|
||||||
/* Take data from the RM container. */
|
/* Take data from the RM container. */
|
||||||
q->sample_rate = id3->frequency;
|
q->sample_rate = id3->frequency;
|
||||||
q->channels = id3->channels;
|
q->channels = channels;
|
||||||
q->bit_rate = id3->bitrate * 1000;
|
q->bit_rate = id3->bitrate * 1000;
|
||||||
q->bits_per_frame = id3->bytesperframe * 8;
|
q->bits_per_frame = id3->bytesperframe * 8;
|
||||||
q->bytes_per_frame = id3->bytesperframe;
|
q->bytes_per_frame = id3->bytesperframe;
|
||||||
|
|
||||||
/* Take care of the codec-specific extradata. */
|
/* Take care of the codec-specific extradata. */
|
||||||
|
|
||||||
if (id3->extradata_size == 14) {
|
if (extradata_size == 14) {
|
||||||
/* Parse the extradata, WAV format */
|
/* Parse the extradata, WAV format */
|
||||||
DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */
|
DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */
|
||||||
q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]);
|
q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]);
|
||||||
|
@ -1200,7 +1200,7 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (id3->extradata_size == 10) {
|
} else if (extradata_size == 10) {
|
||||||
/* Parse the extradata, RM format. */
|
/* Parse the extradata, RM format. */
|
||||||
q->atrac3version = rm_get_uint32be(&edata_ptr[0]);
|
q->atrac3version = rm_get_uint32be(&edata_ptr[0]);
|
||||||
q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]);
|
q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]);
|
||||||
|
@ -1239,7 +1239,7 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id3->channels <= 0 || id3->channels > 2 ) {
|
if (channels <= 0 || channels > 2 ) {
|
||||||
DEBUGF("Channel configuration error!\n");
|
DEBUGF("Channel configuration error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ typedef struct {
|
||||||
//@}
|
//@}
|
||||||
} ATRAC3Context;
|
} ATRAC3Context;
|
||||||
|
|
||||||
int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3);
|
int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3, uint16_t channels, uint32_t extradata_size);
|
||||||
|
|
||||||
int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q,
|
int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q,
|
||||||
int *data_size, const uint8_t *buf, int buf_size);
|
int *data_size, const uint8_t *buf, int buf_size);
|
||||||
|
|
|
@ -272,10 +272,6 @@ struct mp3entry {
|
||||||
bool has_toc; /* True if there is a VBR header in the file */
|
bool has_toc; /* True if there is a VBR header in the file */
|
||||||
unsigned char toc[100]; /* table of contents */
|
unsigned char toc[100]; /* table of contents */
|
||||||
|
|
||||||
/* Added for ATRAC3 */
|
|
||||||
unsigned int channels; /* Number of channels in the stream */
|
|
||||||
unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
|
|
||||||
|
|
||||||
/* Added for AAC HE SBR */
|
/* Added for AAC HE SBR */
|
||||||
bool needs_upsampling_correction; /* flag used by aac codec */
|
bool needs_upsampling_correction; /* flag used by aac codec */
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ bool get_musepack_metadata(int fd, struct mp3entry *id3)
|
||||||
id3->frequency = sfreqs[(sv8_header[k++] >> 5) & 0x0003];
|
id3->frequency = sfreqs[(sv8_header[k++] >> 5) & 0x0003];
|
||||||
|
|
||||||
/* Number of channels */
|
/* Number of channels */
|
||||||
id3->channels = (sv8_header[k++] >> 4) + 1;
|
//uint8_t channels = (sv8_header[k++] >> 4) + 1;
|
||||||
|
|
||||||
/* Skip to next tag: k = size -2 */
|
/* Skip to next tag: k = size -2 */
|
||||||
k = size - 2;
|
k = size - 2;
|
||||||
|
|
|
@ -149,10 +149,6 @@ static int oma_read_header(int fd, struct mp3entry* id3)
|
||||||
|
|
||||||
id3->bitrate = id3->frequency * id3->bytesperframe * 8 / (1024 * 1000);
|
id3->bitrate = id3->frequency * id3->bytesperframe * 8 / (1024 * 1000);
|
||||||
|
|
||||||
/* fake the atrac3 extradata (wav format, makes stream copy to wav work) */
|
|
||||||
/* ATRAC3 expects and extra-data size of 14 bytes for wav format, and *
|
|
||||||
* looks for that in the id3v2buf. */
|
|
||||||
id3->extradata_size = 14;
|
|
||||||
AV_WL16(&id3->id3v2buf[0], 1); // always 1
|
AV_WL16(&id3->id3v2buf[0], 1); // always 1
|
||||||
AV_WL32(&id3->id3v2buf[2], id3->frequency); // samples rate
|
AV_WL32(&id3->id3v2buf[2], id3->frequency); // samples rate
|
||||||
AV_WL16(&id3->id3v2buf[6], jsflag); // coding mode
|
AV_WL16(&id3->id3v2buf[6], jsflag); // coding mode
|
||||||
|
@ -160,7 +156,6 @@ static int oma_read_header(int fd, struct mp3entry* id3)
|
||||||
AV_WL16(&id3->id3v2buf[10], 1); // always 1
|
AV_WL16(&id3->id3v2buf[10], 1); // always 1
|
||||||
AV_WL16(&id3->id3v2buf[12], 0); // always 0
|
AV_WL16(&id3->id3v2buf[12], 0); // always 0
|
||||||
|
|
||||||
id3->channels = 2;
|
|
||||||
DEBUGF("sample_rate = %d\n", id3->frequency);
|
DEBUGF("sample_rate = %d\n", id3->frequency);
|
||||||
DEBUGF("frame_size = %d\n", id3->bytesperframe);
|
DEBUGF("frame_size = %d\n", id3->bytesperframe);
|
||||||
DEBUGF("stereo_coding_mode = %d\n", jsflag);
|
DEBUGF("stereo_coding_mode = %d\n", jsflag);
|
||||||
|
|
|
@ -502,8 +502,6 @@ bool get_rm_metadata(int fd, struct mp3entry* id3)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
id3->channels = rmctx->nb_channels;
|
|
||||||
id3->extradata_size = rmctx->extradata_size;
|
|
||||||
id3->bitrate = (rmctx->bit_rate + 500) / 1000;
|
id3->bitrate = (rmctx->bit_rate + 500) / 1000;
|
||||||
id3->frequency = rmctx->sample_rate;
|
id3->frequency = rmctx->sample_rate;
|
||||||
id3->length = rmctx->duration;
|
id3->length = rmctx->duration;
|
||||||
|
|
|
@ -93,21 +93,21 @@ bool get_tta_metadata(int fd, struct mp3entry* id3)
|
||||||
|
|
||||||
/* skip check CRC */
|
/* skip check CRC */
|
||||||
|
|
||||||
id3->channels = (GET_HEADER(ttahdr, NUM_CHANNELS));
|
unsigned short channels = (GET_HEADER(ttahdr, NUM_CHANNELS));
|
||||||
id3->frequency = (GET_HEADER(ttahdr, SAMPLE_RATE));
|
id3->frequency = (GET_HEADER(ttahdr, SAMPLE_RATE));
|
||||||
id3->length = ((GET_HEADER(ttahdr, DATA_LENGTH)) / id3->frequency) * 1000LL;
|
id3->length = ((GET_HEADER(ttahdr, DATA_LENGTH)) / id3->frequency) * 1000LL;
|
||||||
bps = (GET_HEADER(ttahdr, BITS_PER_SAMPLE));
|
bps = (GET_HEADER(ttahdr, BITS_PER_SAMPLE));
|
||||||
|
|
||||||
datasize = id3->filesize - id3->first_frame_offset;
|
datasize = id3->filesize - id3->first_frame_offset;
|
||||||
origsize = (GET_HEADER(ttahdr, DATA_LENGTH)) * ((bps + 7) / 8) * id3->channels;
|
origsize = (GET_HEADER(ttahdr, DATA_LENGTH)) * ((bps + 7) / 8) * channels;
|
||||||
|
|
||||||
id3->bitrate = (int) ((uint64_t) datasize * id3->frequency * id3->channels * bps
|
id3->bitrate = (int) ((uint64_t) datasize * id3->frequency * channels * bps
|
||||||
/ (origsize * 1000LL));
|
/ (origsize * 1000LL));
|
||||||
|
|
||||||
/* output header info (for debug) */
|
/* output header info (for debug) */
|
||||||
DEBUGF("TTA header info ----\n");
|
DEBUGF("TTA header info ----\n");
|
||||||
DEBUGF("id: %x\n", (unsigned int)(GET_HEADER(ttahdr, ID)));
|
DEBUGF("id: %x\n", (unsigned int)(GET_HEADER(ttahdr, ID)));
|
||||||
DEBUGF("channels: %d\n", id3->channels);
|
DEBUGF("channels: %d\n", channels);
|
||||||
DEBUGF("frequency: %ld\n", id3->frequency);
|
DEBUGF("frequency: %ld\n", id3->frequency);
|
||||||
DEBUGF("length: %ld\n", id3->length);
|
DEBUGF("length: %ld\n", id3->length);
|
||||||
DEBUGF("bitrate: %d\n", id3->bitrate);
|
DEBUGF("bitrate: %d\n", id3->bitrate);
|
||||||
|
|
|
@ -160,7 +160,7 @@ static void set_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3)
|
||||||
fmt->samplesperblock = 1;
|
fmt->samplesperblock = 1;
|
||||||
break;
|
break;
|
||||||
case WAVE_FORMAT_YAMAHA_ADPCM:
|
case WAVE_FORMAT_YAMAHA_ADPCM:
|
||||||
if (id3->channels != 0)
|
if (fmt->channels != 0)
|
||||||
{
|
{
|
||||||
fmt->samplesperblock =
|
fmt->samplesperblock =
|
||||||
(fmt->blockalign == ((id3->frequency / 60) + 4) * fmt->channels)?
|
(fmt->blockalign == ((id3->frequency / 60) + 4) * fmt->channels)?
|
||||||
|
@ -172,7 +172,7 @@ static void set_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3)
|
||||||
fmt->samplesperblock = 2;
|
fmt->samplesperblock = 2;
|
||||||
break;
|
break;
|
||||||
case WAVE_FORMAT_SWF_ADPCM:
|
case WAVE_FORMAT_SWF_ADPCM:
|
||||||
if (fmt->bitspersample != 0 && id3->channels != 0)
|
if (fmt->bitspersample != 0 && fmt->channels != 0)
|
||||||
{
|
{
|
||||||
fmt->samplesperblock
|
fmt->samplesperblock
|
||||||
= (((fmt->blockalign << 3) - 2) / fmt->channels - 22)
|
= (((fmt->blockalign << 3) - 2) / fmt->channels - 22)
|
||||||
|
@ -226,8 +226,6 @@ static void parse_riff_format(unsigned char* buf, int fmtsize, struct wave_fmt *
|
||||||
if(id3->bitrate == 66 || id3->bitrate == 94)
|
if(id3->bitrate == 66 || id3->bitrate == 94)
|
||||||
jsflag = 1;
|
jsflag = 1;
|
||||||
|
|
||||||
id3->extradata_size = 14;
|
|
||||||
id3->channels = 2;
|
|
||||||
id3->codectype = AFMT_OMA_ATRAC3;
|
id3->codectype = AFMT_OMA_ATRAC3;
|
||||||
id3->bytesperframe = fmt->blockalign;
|
id3->bytesperframe = fmt->blockalign;
|
||||||
|
|
||||||
|
|
|
@ -749,8 +749,6 @@ static void print_mp3entry(const struct mp3entry *id3, FILE *f)
|
||||||
if (id3->bytesperframe) fprintf(f, "Bytes per frame: %lu\n", id3->bytesperframe);
|
if (id3->bytesperframe) fprintf(f, "Bytes per frame: %lu\n", id3->bytesperframe);
|
||||||
if (id3->vbr) fprintf(f, "VBR: true\n");
|
if (id3->vbr) fprintf(f, "VBR: true\n");
|
||||||
if (id3->has_toc) fprintf(f, "Has TOC: true\n");
|
if (id3->has_toc) fprintf(f, "Has TOC: true\n");
|
||||||
if (id3->channels) fprintf(f, "Number of channels: %u\n", id3->channels);
|
|
||||||
if (id3->extradata_size) fprintf(f, "Size of extra data: %u\n", id3->extradata_size);
|
|
||||||
if (id3->needs_upsampling_correction) fprintf(f, "Needs upsampling correction: true\n");
|
if (id3->needs_upsampling_correction) fprintf(f, "Needs upsampling correction: true\n");
|
||||||
/* TODO: replaygain; albumart; cuesheet */
|
/* TODO: replaygain; albumart; cuesheet */
|
||||||
if (id3->mb_track_id) fprintf(f, "Musicbrainz track ID: %s\n", id3->mb_track_id);
|
if (id3->mb_track_id) fprintf(f, "Musicbrainz track ID: %s\n", id3->mb_track_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue