diff options
Diffstat (limited to 'apps/codecs/shorten.c')
-rw-r--r-- | apps/codecs/shorten.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index 83a9c34da8..db66991679 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c | |||
@@ -37,7 +37,19 @@ static int32_t offset1[MAX_OFFSET_SIZE] IBSS_ATTR; | |||
37 | static int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR; | 37 | static int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR; |
38 | 38 | ||
39 | /* this is the codec entry point */ | 39 | /* this is the codec entry point */ |
40 | enum codec_status codec_main(void) | 40 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
41 | { | ||
42 | if (reason == CODEC_LOAD) { | ||
43 | /* Generic codec initialisation */ | ||
44 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); | ||
45 | ci->configure(DSP_SET_SAMPLE_DEPTH, SHN_OUTPUT_DEPTH-1); | ||
46 | } | ||
47 | |||
48 | return CODEC_OK; | ||
49 | } | ||
50 | |||
51 | /* this is called for each file to process */ | ||
52 | enum codec_status codec_run(void) | ||
41 | { | 53 | { |
42 | ShortenContext sc; | 54 | ShortenContext sc; |
43 | uint32_t samplesdone; | 55 | uint32_t samplesdone; |
@@ -45,21 +57,14 @@ enum codec_status codec_main(void) | |||
45 | int8_t *buf; | 57 | int8_t *buf; |
46 | int consumed, res, nsamples; | 58 | int consumed, res, nsamples; |
47 | size_t bytesleft; | 59 | size_t bytesleft; |
60 | intptr_t param; | ||
48 | 61 | ||
49 | /* Generic codec initialisation */ | ||
50 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); | ||
51 | ci->configure(DSP_SET_SAMPLE_DEPTH, SHN_OUTPUT_DEPTH-1); | ||
52 | |||
53 | next_track: | ||
54 | /* Codec initialization */ | 62 | /* Codec initialization */ |
55 | if (codec_init()) { | 63 | if (codec_init()) { |
56 | LOGF("Shorten: codec_init error\n"); | 64 | LOGF("Shorten: codec_init error\n"); |
57 | return CODEC_ERROR; | 65 | return CODEC_ERROR; |
58 | } | 66 | } |
59 | 67 | ||
60 | if (codec_wait_taginfo() != 0) | ||
61 | goto request_next_track; | ||
62 | |||
63 | codec_set_replaygain(ci->id3); | 68 | codec_set_replaygain(ci->id3); |
64 | 69 | ||
65 | /* Shorten decoder initialization */ | 70 | /* Shorten decoder initialization */ |
@@ -103,14 +108,15 @@ seek_start: | |||
103 | samplesdone = 0; | 108 | samplesdone = 0; |
104 | buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE); | 109 | buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE); |
105 | while (bytesleft) { | 110 | while (bytesleft) { |
106 | ci->yield(); | 111 | enum codec_command_action action = ci->get_command(¶m); |
107 | if (ci->stop_codec || ci->new_track) { | 112 | |
113 | if (action == CODEC_ACTION_HALT) | ||
108 | break; | 114 | break; |
109 | } | ||
110 | 115 | ||
111 | /* Seek to start of track */ | 116 | /* Seek to start of track */ |
112 | if (ci->seek_time == 1) { | 117 | if (action == CODEC_ACTION_SEEK_TIME) { |
113 | if (ci->seek_buffer(sc.header_bits/8 + ci->id3->first_frame_offset)) { | 118 | if (param == 0 && |
119 | ci->seek_buffer(sc.header_bits/8 + ci->id3->first_frame_offset)) { | ||
114 | sc.bitindex = sc.header_bits - 8*(sc.header_bits/8); | 120 | sc.bitindex = sc.header_bits - 8*(sc.header_bits/8); |
115 | ci->set_elapsed(0); | 121 | ci->set_elapsed(0); |
116 | ci->seek_complete(); | 122 | ci->seek_complete(); |
@@ -128,7 +134,7 @@ seek_start: | |||
128 | if (res == FN_ERROR) { | 134 | if (res == FN_ERROR) { |
129 | LOGF("Shorten: shorten_decode_frames error (%lu)\n", | 135 | LOGF("Shorten: shorten_decode_frames error (%lu)\n", |
130 | (unsigned long)samplesdone); | 136 | (unsigned long)samplesdone); |
131 | break; | 137 | return CODEC_ERROR; |
132 | } else { | 138 | } else { |
133 | /* Insert decoded samples in pcmbuf */ | 139 | /* Insert decoded samples in pcmbuf */ |
134 | if (nsamples) { | 140 | if (nsamples) { |
@@ -153,9 +159,5 @@ seek_start: | |||
153 | sc.bitindex = sc.gb.index - 8*consumed; | 159 | sc.bitindex = sc.gb.index - 8*consumed; |
154 | } | 160 | } |
155 | 161 | ||
156 | request_next_track: | ||
157 | if (ci->request_next_track()) | ||
158 | goto next_track; | ||
159 | |||
160 | return CODEC_OK; | 162 | return CODEC_OK; |
161 | } | 163 | } |