diff options
Diffstat (limited to 'apps/codecs')
-rw-r--r-- | apps/codecs/mpc.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index b9ae558c67..afda2871f9 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c | |||
@@ -69,8 +69,9 @@ static mpc_bool_t canseek_impl(mpc_reader *reader) | |||
69 | enum codec_status codec_main(void) | 69 | enum codec_status codec_main(void) |
70 | { | 70 | { |
71 | mpc_int64_t samplesdone; | 71 | mpc_int64_t samplesdone; |
72 | uint32_t frequency; /* 0.1 kHz accuracy */ | 72 | uint32_t frequency; /* 0.1 kHz accuracy */ |
73 | uint32_t elapsed_time; /* milliseconds */ | 73 | uint32_t elapsed_time; /* milliseconds */ |
74 | uint32_t byterate; /* bytes per second */ | ||
74 | mpc_status status; | 75 | mpc_status status; |
75 | mpc_reader reader; | 76 | mpc_reader reader; |
76 | mpc_streaminfo info; | 77 | mpc_streaminfo info; |
@@ -102,8 +103,6 @@ next_track: | |||
102 | while (!*ci->taginfo_ready && !ci->stop_codec) | 103 | while (!*ci->taginfo_ready && !ci->stop_codec) |
103 | ci->sleep(1); | 104 | ci->sleep(1); |
104 | 105 | ||
105 | samplesdone = ci->id3->offset; | ||
106 | |||
107 | /* initialize demux/decoder */ | 106 | /* initialize demux/decoder */ |
108 | demux = mpc_demux_init(&reader); | 107 | demux = mpc_demux_init(&reader); |
109 | if (NULL == demux) | 108 | if (NULL == demux) |
@@ -114,9 +113,15 @@ next_track: | |||
114 | /* read file's streaminfo data */ | 113 | /* read file's streaminfo data */ |
115 | mpc_demux_get_info(demux, &info); | 114 | mpc_demux_get_info(demux, &info); |
116 | 115 | ||
117 | 116 | byterate = (mpc_uint32_t)(info.average_bitrate) / 8; | |
118 | frequency = info.sample_freq / 100; /* 0.1 kHz accuracy */ | 117 | frequency = info.sample_freq / 100; /* 0.1 kHz accuracy */ |
119 | ci->configure(DSP_SWITCH_FREQUENCY, info.sample_freq); | 118 | ci->configure(DSP_SWITCH_FREQUENCY, info.sample_freq); |
119 | |||
120 | /* Remark: rockbox offset is the file offset in bytes. So, estimate the | ||
121 | * sample seek position from the file offset, the sampling frequency and | ||
122 | * the bitrate. As the saved position is exactly calculated the reverse way | ||
123 | * there is no loss of information except rounding. */ | ||
124 | samplesdone = 100 * ((mpc_uint64_t)(ci->id3->offset * frequency) / byterate); | ||
120 | 125 | ||
121 | /* set playback engine up for correct number of channels */ | 126 | /* set playback engine up for correct number of channels */ |
122 | /* NOTE: current musepack format only allows for stereo files | 127 | /* NOTE: current musepack format only allows for stereo files |
@@ -181,7 +186,9 @@ next_track: | |||
181 | samplesdone += frame.samples; | 186 | samplesdone += frame.samples; |
182 | elapsed_time = (samplesdone*10)/frequency; | 187 | elapsed_time = (samplesdone*10)/frequency; |
183 | ci->set_elapsed(elapsed_time); | 188 | ci->set_elapsed(elapsed_time); |
184 | ci->set_offset(samplesdone); | 189 | /* Remark: rockbox offset is the file offset in bytes. So estimate |
190 | * this offset from the samples, sampling frequency and bitrate */ | ||
191 | ci->set_offset( (samplesdone * byterate)/(frequency*100) ); | ||
185 | } | 192 | } |
186 | } while (true); | 193 | } while (true); |
187 | 194 | ||