summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/atrac3_oma.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/atrac3_oma.c')
-rw-r--r--lib/rbcodec/codecs/atrac3_oma.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/rbcodec/codecs/atrac3_oma.c b/lib/rbcodec/codecs/atrac3_oma.c
index 50f7c8f163..65d9ed8b38 100644
--- a/lib/rbcodec/codecs/atrac3_oma.c
+++ b/lib/rbcodec/codecs/atrac3_oma.c
@@ -50,13 +50,15 @@ enum codec_status codec_run(void)
50 int elapsed = 0; 50 int elapsed = 0;
51 size_t resume_offset; 51 size_t resume_offset;
52 intptr_t param; 52 intptr_t param;
53 enum codec_command_action action = CODEC_ACTION_NULL; 53 enum codec_command_action action;
54 54
55 if (codec_init()) { 55 if (codec_init()) {
56 DEBUGF("codec init failed\n"); 56 DEBUGF("codec init failed\n");
57 return CODEC_ERROR; 57 return CODEC_ERROR;
58 } 58 }
59 59
60 action = CODEC_ACTION_NULL;
61 param = ci->id3->elapsed;
60 resume_offset = ci->id3->offset; 62 resume_offset = ci->id3->offset;
61 63
62 codec_set_replaygain(ci->id3); 64 codec_set_replaygain(ci->id3);
@@ -79,11 +81,13 @@ enum codec_status codec_run(void)
79 frame_counter = 0; 81 frame_counter = 0;
80 82
81 /* check for a mid-track resume and force a seek time accordingly */ 83 /* check for a mid-track resume and force a seek time accordingly */
82 if(resume_offset > ci->id3->first_frame_offset) { 84 if (resume_offset) {
83 resume_offset -= ci->id3->first_frame_offset; 85 resume_offset -= MIN(resume_offset, ci->id3->first_frame_offset);
84 /* calculate resume_offset in frames */ 86 /* calculate resume_offset in frames */
85 resume_offset = (int)resume_offset / FRAMESIZE; 87 param = (resume_offset/FRAMESIZE) * ((FRAMESIZE * 8)/BITRATE);
86 param = (int)resume_offset * ((FRAMESIZE * 8)/BITRATE); 88 }
89
90 if ((unsigned long)param) {
87 action = CODEC_ACTION_SEEK_TIME; 91 action = CODEC_ACTION_SEEK_TIME;
88 } 92 }
89 else { 93 else {
@@ -100,11 +104,9 @@ enum codec_status codec_run(void)
100 if (action == CODEC_ACTION_HALT) 104 if (action == CODEC_ACTION_HALT)
101 break; 105 break;
102 106
103 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, FRAMESIZE);
104
105 if (action == CODEC_ACTION_SEEK_TIME) { 107 if (action == CODEC_ACTION_SEEK_TIME) {
106 /* Do not allow seeking beyond the file's length */ 108 /* Do not allow seeking beyond the file's length */
107 if ((unsigned) param > ci->id3->length) { 109 if ((unsigned long) param > ci->id3->length) {
108 ci->set_elapsed(ci->id3->length); 110 ci->set_elapsed(ci->id3->length);
109 ci->seek_complete(); 111 ci->seek_complete();
110 break; 112 break;
@@ -123,7 +125,6 @@ enum codec_status codec_run(void)
123 seek_frame_offset = (param * BITRATE) / (8 * FRAMESIZE); 125 seek_frame_offset = (param * BITRATE) / (8 * FRAMESIZE);
124 frame_counter = seek_frame_offset; 126 frame_counter = seek_frame_offset;
125 ci->seek_buffer(ci->id3->first_frame_offset + seek_frame_offset* FRAMESIZE); 127 ci->seek_buffer(ci->id3->first_frame_offset + seek_frame_offset* FRAMESIZE);
126 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, FRAMESIZE);
127 elapsed = param; 128 elapsed = param;
128 ci->set_elapsed(elapsed); 129 ci->set_elapsed(elapsed);
129 ci->seek_complete(); 130 ci->seek_complete();
@@ -131,6 +132,8 @@ enum codec_status codec_run(void)
131 132
132 action = CODEC_ACTION_NULL; 133 action = CODEC_ACTION_NULL;
133 134
135 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, FRAMESIZE);
136
134 res = atrac3_decode_frame(FRAMESIZE, &q, &datasize, bit_buffer, FRAMESIZE); 137 res = atrac3_decode_frame(FRAMESIZE, &q, &datasize, bit_buffer, FRAMESIZE);
135 138
136 if(res != (int)FRAMESIZE) { 139 if(res != (int)FRAMESIZE) {