summaryrefslogtreecommitdiff
path: root/apps/codecs/mpc.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/mpc.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/mpc.c')
-rw-r--r--apps/codecs/mpc.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c
index 187c37e597..bbe2d9943b 100644
--- a/apps/codecs/mpc.c
+++ b/apps/codecs/mpc.c
@@ -52,8 +52,20 @@ static mpc_int32_t get_size_impl(mpc_reader *reader)
52 return ci->filesize; 52 return ci->filesize;
53} 53}
54 54
55/* This is the codec entry point. */ 55/* this is the codec entry point */
56enum codec_status codec_main(void) 56enum codec_status codec_main(enum codec_entry_call_reason reason)
57{
58 if (reason == CODEC_LOAD) {
59 /* musepack's sample representation is 18.14
60 * DSP_SET_SAMPLE_DEPTH = 14 (FRACT) + 16 (NATIVE) - 1 (SIGN) = 29 */
61 ci->configure(DSP_SET_SAMPLE_DEPTH, 29);
62 }
63
64 return CODEC_OK;
65}
66
67/* this is called for each file to process */
68enum codec_status codec_run(void)
57{ 69{
58 mpc_int64_t samplesdone; 70 mpc_int64_t samplesdone;
59 uint32_t frequency; /* 0.1 kHz accuracy */ 71 uint32_t frequency; /* 0.1 kHz accuracy */
@@ -64,39 +76,27 @@ enum codec_status codec_main(void)
64 mpc_streaminfo info; 76 mpc_streaminfo info;
65 mpc_frame_info frame; 77 mpc_frame_info frame;
66 mpc_demux *demux = NULL; 78 mpc_demux *demux = NULL;
67 int retval; 79 intptr_t param;
68 80
69 frame.buffer = sample_buffer; 81 frame.buffer = sample_buffer;
70 82
71 /* musepack's sample representation is 18.14
72 * DSP_SET_SAMPLE_DEPTH = 14 (FRACT) + 16 (NATIVE) - 1 (SIGN) = 29 */
73 ci->configure(DSP_SET_SAMPLE_DEPTH, 29);
74
75 /* Create a decoder instance */ 83 /* Create a decoder instance */
76 reader.read = read_impl; 84 reader.read = read_impl;
77 reader.seek = seek_impl; 85 reader.seek = seek_impl;
78 reader.tell = tell_impl; 86 reader.tell = tell_impl;
79 reader.get_size = get_size_impl; 87 reader.get_size = get_size_impl;
80 88
81next_track:
82 retval = CODEC_OK;
83
84 if (codec_init()) 89 if (codec_init())
85 { 90 return CODEC_ERROR;
86 retval = CODEC_ERROR;
87 goto exit;
88 }
89 91
90 if (codec_wait_taginfo() != 0) 92 /* Prep position */
91 goto done; 93 ci->seek_buffer(0);
92 94
93 /* Initialize demux/decoder. */ 95 /* Initialize demux/decoder. */
94 demux = mpc_demux_init(&reader); 96 demux = mpc_demux_init(&reader);
95 if (NULL == demux) 97 if (NULL == demux)
96 { 98 return CODEC_ERROR;
97 retval = CODEC_ERROR; 99
98 goto done;
99 }
100 /* Read file's streaminfo data. */ 100 /* Read file's streaminfo data. */
101 mpc_demux_get_info(demux, &info); 101 mpc_demux_get_info(demux, &info);
102 102
@@ -117,11 +117,8 @@ next_track:
117 ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); 117 ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
118 else if (info.channels == 1) 118 else if (info.channels == 1)
119 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); 119 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
120 else 120 else
121 { 121 return CODEC_ERROR;
122 retval = CODEC_ERROR;
123 goto done;
124 }
125 122
126 codec_set_replaygain(ci->id3); 123 codec_set_replaygain(ci->id3);
127 124
@@ -142,21 +139,24 @@ next_track:
142 /* This is the decoding loop. */ 139 /* This is the decoding loop. */
143 do 140 do
144 { 141 {
142 enum codec_command_action action = ci->get_command(&param);
143
144 if (action == CODEC_ACTION_HALT)
145 return CODEC_OK;
146
145 /* Complete seek handler. */ 147 /* Complete seek handler. */
146 if (ci->seek_time) 148 if (action == CODEC_ACTION_SEEK_TIME)
147 { 149 {
148 mpc_int64_t new_offset = ((ci->seek_time - 1)/10)*frequency; 150 mpc_int64_t new_offset = (param/10)*frequency;
149 if (mpc_demux_seek_sample(demux, new_offset) == MPC_STATUS_OK) 151 if (mpc_demux_seek_sample(demux, new_offset) == MPC_STATUS_OK)
150 { 152 {
151 samplesdone = new_offset; 153 samplesdone = new_offset;
152 ci->set_elapsed(ci->seek_time);
153 } 154 }
155
156 elapsed_time = (samplesdone*10)/frequency;
157 ci->set_elapsed(elapsed_time);
154 ci->seek_complete(); 158 ci->seek_complete();
155 } 159 }
156
157 /* Stop or skip occured, exit decoding loop. */
158 if (ci->stop_codec || ci->new_track)
159 break;
160 160
161 /* Decode one frame. */ 161 /* Decode one frame. */
162 status = mpc_demux_decode(demux, &frame); 162 status = mpc_demux_decode(demux, &frame);
@@ -164,8 +164,7 @@ next_track:
164 if (frame.bits == -1) 164 if (frame.bits == -1)
165 { 165 {
166 /* Decoding error, exit decoding loop. */ 166 /* Decoding error, exit decoding loop. */
167 retval = (status == MPC_STATUS_OK) ? CODEC_OK : CODEC_ERROR; 167 return (status == MPC_STATUS_OK) ? CODEC_OK : CODEC_ERROR;
168 goto done;
169 } 168 }
170 else 169 else
171 { 170 {
@@ -181,11 +180,4 @@ next_track:
181 ci->set_offset( (samplesdone * byterate)/(frequency*100) ); 180 ci->set_offset( (samplesdone * byterate)/(frequency*100) );
182 } 181 }
183 } while (true); 182 } while (true);
184
185done:
186 if (ci->request_next_track())
187 goto next_track;
188
189exit:
190 return retval;
191} 183}