FS#6760 - Stereo Speex files produce only silence in Rockbox

Attached to Project: Rockbox
Opened by Bryan Childs (GodEater) - Thursday, 08 March 2007, 07:26 GMT
Last edited by Thom Johansen (preglow) - Saturday, 10 November 2007, 15:28 GMT
Task Type Bugs
Category Codecs
Status Closed
Assigned To No-one
Operating System Gigabeat F/X
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


When ripping direct from CD and converting immediately to speex, the resulting files appear to playback in Rockbox fine (i.e. the progress bar moves, and the time remaining changes) however you can't actually hear any audio. Converting the wav file from the CD rip to mono, and then re-encoding resolves the issue.
This task depends upon

Closed by  Thom Johansen (preglow)
Saturday, 10 November 2007, 15:28 GMT
Reason for closing:  Fixed
Comment by Dan Everton (safetydan) - Thursday, 08 March 2007, 22:32 GMT
Yeah actually this is something silly. Turns out to produce stereo in Speex you need to do two passes over the file. So the decoding loop should look something like

speex_decode_int(st, &bits, output);

if (channels == 2)
speex_decode_stereo_int(output, frame_size, &stereo);

ci->pcmbuf_insert(output, NULL, frame_size * channels)

or something like that anyway. I'll take a look again when I get a chance.
Comment by Dan Everton (safetydan) - Friday, 09 March 2007, 08:33 GMT
Yeah okay, that's not it. The code is already like that.
Comment by Frederik (freqmod) - Friday, 16 March 2007, 15:05 GMT
When i tried to debug speex (when implementing the codec) i got this problem, which was caused by faulty (not good enough accuracy) sqrt and exp functions.

To debug it i would try to use real (floating point) sqrt&exp functions in the emulator, and if that not works look at
void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState *stereo)
and int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data) in stereo.c
Comment by Frederik (freqmod) - Friday, 16 March 2007, 16:24 GMT
Currently sqrt and exp returns 0 (placeholder functions). I haven't found good enough integer replacements to give noise-free sound. If you want to play sereo files in mono replace
e_left = sqrt(e_left/(e_tot+.01));
e_right = sqrt(e_right/(e_tot+.01));
in speex_decode_stereo_int (stereo.c:~166)
Comment by Bryan Childs (GodEater) - Friday, 16 March 2007, 16:32 GMT
I don't think we use that code at all - we use speex_decode_stereo_int(), not speex_decode_stereo()
Comment by Dan Everton (safetydan) - Saturday, 17 March 2007, 01:07 GMT
No, I think freqmod is right. speex_decode_stereo_int does actually use a floating point sqrt() function. See line 163 and 164 of apps/codecs/libspeex/stereo.c. Don't know why I didn't see that before. Should probably just disable stereo decoding until that's made fixed point.