diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-24 01:25:21 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-03-18 12:00:39 +0100 |
commit | b5716df4cb2837bbbc42195cf1aefcf03e21d6a6 (patch) | |
tree | 130cd712e2e00893b6df9959a375a8d9523a1aca /lib/rbcodec/metadata/tta.c | |
parent | 24bd9d5393dbe39a5c6194877bc00ede669b1d5d (diff) | |
download | rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.tar.gz rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.zip |
Build librbcodec with DSP and metadata.
All associated files are moved to /lib/rbcodec.
Change-Id: I572ddd2b8a996aae1e98c081d06b1ed356dce222
Diffstat (limited to 'lib/rbcodec/metadata/tta.c')
-rw-r--r-- | lib/rbcodec/metadata/tta.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/tta.c b/lib/rbcodec/metadata/tta.c new file mode 100644 index 0000000000..1d3d95f118 --- /dev/null +++ b/lib/rbcodec/metadata/tta.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Yoshihisa Uchida | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <inttypes.h> | ||
26 | |||
27 | #include "system.h" | ||
28 | #include "metadata.h" | ||
29 | #include "metadata_common.h" | ||
30 | #include "metadata_parsers.h" | ||
31 | #include "logf.h" | ||
32 | |||
33 | #define TTA1_SIGN 0x31415454 | ||
34 | |||
35 | #define TTA_HEADER_ID 0 | ||
36 | #define TTA_HEADER_AUDIO_FORMAT (TTA_HEADER_ID + sizeof(unsigned int)) | ||
37 | #define TTA_HEADER_NUM_CHANNELS (TTA_HEADER_AUDIO_FORMAT + sizeof(unsigned short)) | ||
38 | #define TTA_HEADER_BITS_PER_SAMPLE (TTA_HEADER_NUM_CHANNELS + sizeof(unsigned short)) | ||
39 | #define TTA_HEADER_SAMPLE_RATE (TTA_HEADER_BITS_PER_SAMPLE + sizeof(unsigned short)) | ||
40 | #define TTA_HEADER_DATA_LENGTH (TTA_HEADER_SAMPLE_RATE + sizeof(unsigned int)) | ||
41 | #define TTA_HEADER_CRC32 (TTA_HEADER_DATA_LENGTH + sizeof(unsigned int)) | ||
42 | #define TTA_HEADER_SIZE (TTA_HEADER_CRC32 + sizeof(unsigned int)) | ||
43 | |||
44 | #define TTA_HEADER_GETTER_ID(x) get_long_le(x) | ||
45 | #define TTA_HEADER_GETTER_AUDIO_FORMAT(x) get_short_le(x) | ||
46 | #define TTA_HEADER_GETTER_NUM_CHANNELS(x) get_short_le(x) | ||
47 | #define TTA_HEADER_GETTER_BITS_PER_SAMPLE(x) get_short_le(x) | ||
48 | #define TTA_HEADER_GETTER_SAMPLE_RATE(x) get_long_le(x) | ||
49 | #define TTA_HEADER_GETTER_DATA_LENGTH(x) get_long_le(x) | ||
50 | #define TTA_HEADER_GETTER_CRC32(x) get_long_le(x) | ||
51 | |||
52 | #define GET_HEADER(x, tag) TTA_HEADER_GETTER_ ## tag((x) + TTA_HEADER_ ## tag) | ||
53 | |||
54 | static void read_id3_tags(int fd, struct mp3entry* id3) | ||
55 | { | ||
56 | id3->title = NULL; | ||
57 | id3->filesize = filesize(fd); | ||
58 | id3->id3v2len = getid3v2len(fd); | ||
59 | id3->tracknum = 0; | ||
60 | id3->discnum = 0; | ||
61 | id3->vbr = false; /* All TTA files are CBR */ | ||
62 | |||
63 | /* first get id3v2 tags. if no id3v2 tags ware found, get id3v1 tags */ | ||
64 | if (id3->id3v2len) | ||
65 | { | ||
66 | setid3v2title(fd, id3); | ||
67 | id3->first_frame_offset = id3->id3v2len; | ||
68 | return; | ||
69 | } | ||
70 | setid3v1title(fd, id3); | ||
71 | } | ||
72 | |||
73 | bool get_tta_metadata(int fd, struct mp3entry* id3) | ||
74 | { | ||
75 | unsigned char ttahdr[TTA_HEADER_SIZE]; | ||
76 | unsigned int datasize; | ||
77 | unsigned int origsize; | ||
78 | int bps; | ||
79 | |||
80 | lseek(fd, 0, SEEK_SET); | ||
81 | |||
82 | /* read id3 tags */ | ||
83 | read_id3_tags(fd, id3); | ||
84 | lseek(fd, id3->id3v2len, SEEK_SET); | ||
85 | |||
86 | /* read TTA header */ | ||
87 | if (read(fd, ttahdr, TTA_HEADER_SIZE) < 0) | ||
88 | return false; | ||
89 | |||
90 | /* check for TTA3 signature */ | ||
91 | if ((GET_HEADER(ttahdr, ID)) != TTA1_SIGN) | ||
92 | return false; | ||
93 | |||
94 | /* skip check CRC */ | ||
95 | |||
96 | id3->channels = (GET_HEADER(ttahdr, NUM_CHANNELS)); | ||
97 | id3->frequency = (GET_HEADER(ttahdr, SAMPLE_RATE)); | ||
98 | id3->length = ((GET_HEADER(ttahdr, DATA_LENGTH)) / id3->frequency) * 1000LL; | ||
99 | bps = (GET_HEADER(ttahdr, BITS_PER_SAMPLE)); | ||
100 | |||
101 | datasize = id3->filesize - id3->first_frame_offset; | ||
102 | origsize = (GET_HEADER(ttahdr, DATA_LENGTH)) * ((bps + 7) / 8) * id3->channels; | ||
103 | |||
104 | id3->bitrate = (int) ((uint64_t) datasize * id3->frequency * id3->channels * bps | ||
105 | / (origsize * 1000LL)); | ||
106 | |||
107 | /* output header info (for debug) */ | ||
108 | DEBUGF("TTA header info ----\n"); | ||
109 | DEBUGF("id: %x\n", (unsigned int)(GET_HEADER(ttahdr, ID))); | ||
110 | DEBUGF("channels: %d\n", id3->channels); | ||
111 | DEBUGF("frequency: %ld\n", id3->frequency); | ||
112 | DEBUGF("length: %ld\n", id3->length); | ||
113 | DEBUGF("bitrate: %d\n", id3->bitrate); | ||
114 | DEBUGF("bits per sample: %d\n", bps); | ||
115 | DEBUGF("compressed size: %d\n", datasize); | ||
116 | DEBUGF("original size: %d\n", origsize); | ||
117 | DEBUGF("id3----\n"); | ||
118 | DEBUGF("artist: %s\n", id3->artist); | ||
119 | DEBUGF("title: %s\n", id3->title); | ||
120 | DEBUGF("genre: %s\n", id3->genre_string); | ||
121 | |||
122 | return true; | ||
123 | } | ||