diff options
author | Yoshihisa Uchida <uchida@rockbox.org> | 2010-02-20 02:04:56 +0000 |
---|---|---|
committer | Yoshihisa Uchida <uchida@rockbox.org> | 2010-02-20 02:04:56 +0000 |
commit | 3716abba9274f544dd31cdf4e6c83a845bf2a801 (patch) | |
tree | 07bca7cdd3e40bb176e938fcb5ea8eb2f7c3e9cb /apps/codecs/libpcm/adpcm_seek.c | |
parent | 93caf52db5e0afe826278c148936bdfa563724f1 (diff) | |
download | rockbox-3716abba9274f544dd31cdf4e6c83a845bf2a801.tar.gz rockbox-3716abba9274f544dd31cdf4e6c83a845bf2a801.zip |
commit FS#10424 and FS#10425
- wav(RIFF) supports Microsoft ADPCM, Dialogic OKI ADPCM, YAMAHA ADPCM, Adobe SWF ADPCM.
- AIFF supports QuickTime IMA ADPCM.
- DVI ADPCM(IMA ADPCM) reworks.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24782 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libpcm/adpcm_seek.c')
-rw-r--r-- | apps/codecs/libpcm/adpcm_seek.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/apps/codecs/libpcm/adpcm_seek.c b/apps/codecs/libpcm/adpcm_seek.c new file mode 100644 index 0000000000..ce49d5fcd3 --- /dev/null +++ b/apps/codecs/libpcm/adpcm_seek.c | |||
@@ -0,0 +1,101 @@ | |||
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 "adpcm_seek.h" | ||
22 | #include "codeclib.h" | ||
23 | |||
24 | /* | ||
25 | * The helper functions in order to seek for the adpcm codec | ||
26 | * which does not include the header each the data block. | ||
27 | */ | ||
28 | |||
29 | #define MAX_STORE_COUNT 1000 | ||
30 | |||
31 | static struct adpcm_data seek_table[MAX_STORE_COUNT]; | ||
32 | static int seek_count; | ||
33 | static int cur_count; | ||
34 | static int max_ratio; | ||
35 | static int cur_ratio; | ||
36 | |||
37 | void init_seek_table(uint32_t max_count) | ||
38 | { | ||
39 | int i = 0; | ||
40 | |||
41 | for ( ; i < MAX_STORE_COUNT; i++) | ||
42 | { | ||
43 | seek_table[i].is_valid = false; | ||
44 | } | ||
45 | seek_count = max_count / MAX_STORE_COUNT + 1; | ||
46 | max_ratio = max_count / seek_count + 1; | ||
47 | cur_count = 0; | ||
48 | cur_ratio = -1; | ||
49 | } | ||
50 | |||
51 | void add_adpcm_data(struct adpcm_data *data) | ||
52 | { | ||
53 | if (--cur_count <= 0) | ||
54 | { | ||
55 | cur_count = seek_count; | ||
56 | if (++cur_ratio >= max_ratio) | ||
57 | cur_ratio = max_ratio - 1; | ||
58 | |||
59 | if (!seek_table[cur_ratio].is_valid) | ||
60 | { | ||
61 | seek_table[cur_ratio].pcmdata[0] = data->pcmdata[0]; | ||
62 | seek_table[cur_ratio].pcmdata[1] = data->pcmdata[1]; | ||
63 | seek_table[cur_ratio].step[0] = data->step[0]; | ||
64 | seek_table[cur_ratio].step[1] = data->step[1]; | ||
65 | seek_table[cur_ratio].is_valid = true; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | uint32_t seek(uint32_t count, struct adpcm_data *seek_data, | ||
71 | uint8_t *(*read_buffer)(size_t *realsize), | ||
72 | int (*decode)(const uint8_t *inbuf, size_t inbufsize)) | ||
73 | { | ||
74 | int new_ratio = count / seek_count; | ||
75 | |||
76 | if (new_ratio >= max_ratio) | ||
77 | new_ratio = max_ratio - 1; | ||
78 | |||
79 | if (!seek_table[new_ratio].is_valid) | ||
80 | { | ||
81 | uint8_t *buffer; | ||
82 | size_t n; | ||
83 | |||
84 | do | ||
85 | { | ||
86 | buffer = read_buffer(&n); | ||
87 | if (n == 0) | ||
88 | break; | ||
89 | decode(buffer, n); | ||
90 | } while (cur_ratio < new_ratio); | ||
91 | } | ||
92 | |||
93 | seek_data->pcmdata[0] = seek_table[new_ratio].pcmdata[0]; | ||
94 | seek_data->pcmdata[1] = seek_table[new_ratio].pcmdata[1]; | ||
95 | seek_data->step[0] = seek_table[new_ratio].step[0]; | ||
96 | seek_data->step[1] = seek_table[new_ratio].step[1]; | ||
97 | |||
98 | cur_ratio = new_ratio; | ||
99 | cur_count = seek_count; | ||
100 | return cur_ratio * seek_count; | ||
101 | } | ||