Re: [Bluez-devel] SBC packer done, kind of

Henryk Plötz
2004-11-23T06:48:29Z

[-- Attachment #1: Type: text/plain, Size: 2173 bytes --]

Moin,

Am Tue, 23 Nov 2004 07:27:40 +0100 schrieb Marcel Holtmann:

> these are good news. So I really must code the sbcenc tool now. In
> what fields do I have to put the PCM stream and what other things must
> I set?

You'll have to get yourself a shiny new struct sbc_frame, fill in the
metadata and then put the pcm samples in the pcm_sample member. Then do
the regular init (only once), analyze, pack (which do the reverse of
their decoding counterparts).

My test code looked kind of like this:

struct sbc_frame frame;
struct sbc_encoder_state estate;

frame.sampling_frequency = 44.1;
frame.blocks = 16;
frame.channel_mode = DUAL_CHANNEL;
frame.channels = 2;
frame.allocation_method = SNR;
frame.subbands = 8;
frame.bitpool = 64;

for(int i = 0; i < frame.subbands*frame.blocks; i++) {
frame.pcm_sample[0][i] = ((double)i /
(double)(frame.subbands*frame.blocks))* (1<<15);
frame.pcm_sample[1][i] = ((double)i /
(double)(frame.subbands*frame.blocks))* (1<<15) * (-1);
}

sbc_encoder_init(&estate, &frame);
sbc_analyze_audio(&estate, &frame);
framelen = sbc_pack_frame(stream+pos, &frame, streamlength-pos-1);

I'm not sure to which value the pcm samples should be normalized. For
starters I'd recommend keeping them between -2^15 and 2^15.

> Actually that is the main point behind using tabs with the size of 8
> spaces. Code that uses too much nested structures become unreadable
> and you start thinking of how you can make this easier and make it
> looking a little bit nicer. In most cases the answer is inline
> functions.

Well yes. For most programs that's entirely true but in this special
case of only a few ever recurring tight loops (some of them even copied
literally from the spec) I don't see how littering the otherwise linear
functionality all over the file would make it easier to read. I'd rather
say the opposite was true.

Oh why, I'll do my very best ...

--
Henryk Plötz
Grüße aus Berlin
~~~~~~~ Un-CDs, nein danke! http://www.heise.de/ct/cd-register/ ~~~~~~~
~ Help Microsoft fight software piracy: Give Linux to a friend today! ~

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]