3 SWF Sound handling routines
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2001, 2002 Matthias Kramm <kramm@quiss.org>
10 This file is distributed under the GPL, see file COPYING for details
14 #include "../rfxswf.h"
16 CodecInitOut * init = 0;
17 void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples)
19 U8 playbackrate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
20 U8 playbacksize = 1; // 0 = 8 bit, 1 = 16 bit
21 U8 playbacktype = 0; // 0 = mono, 1 = stereo
22 U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3
23 U8 rate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
24 U8 size = 1; // 0 = 8 bit, 1 = 16 bit
25 U8 type = 0; // 0 = mono, 1 = stereo
28 memset(¶ms, 0, sizeof(params));
29 params.frequency = 44100; //48000, 44100 or 32000
30 params.mode = 3; //0 = Stereo, 2 = Dual Channel, 3 = Mono
31 params.emphasis = 0; //0 = None, 1 = 50/15 microsec, 3 = CCITT J.17
32 params.bitrate = 128; //default is 128 (64 for mono)
33 init = codecInit(¶ms);
35 swf_SetU8(tag,(playbackrate<<2)|(playbacksize<<1)|playbacktype);
36 swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type);
37 swf_SetU16(tag,avgnumsamples);
39 printf("numSamples:%d\n",init->nSamples);
40 printf("bufferSize:%d\n",init->bufferSize);
43 void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int numsamples, char first)
51 buf = malloc(init->bufferSize);
53 len = codecEncodeChunk (numsamples, samples, buf);
54 len += codecFlush (&buf[len]);
55 len += codecExit (&buf[len]);
58 swf_SetU16(tag, numsamples); // number of samples
59 swf_SetU16(tag, 0); // seek
61 swf_SetBlock(tag, buf, len);