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 #ifndef RFXSWF_DISABLESOUND
16 #include "../rfxswf.h"
18 CodecInitOut * init = 0;
19 void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples)
21 U8 playbackrate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
22 U8 playbacksize = 1; // 0 = 8 bit, 1 = 16 bit
23 U8 playbacktype = 0; // 0 = mono, 1 = stereo
24 U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3
25 U8 rate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
26 U8 size = 1; // 0 = 8 bit, 1 = 16 bit
27 U8 type = 0; // 0 = mono, 1 = stereo
30 memset(¶ms, 0, sizeof(params));
31 params.frequency = 44100; //48000, 44100 or 32000
32 params.mode = 3; //0 = Stereo, 2 = Dual Channel, 3 = Mono
33 params.emphasis = 0; //0 = None, 1 = 50/15 microsec, 3 = CCITT J.17
34 params.bitrate = 128; //default is 128 (64 for mono)
35 init = codecInit(¶ms);
37 swf_SetU8(tag,(playbackrate<<2)|(playbacksize<<1)|playbacktype);
38 swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type);
39 swf_SetU16(tag,avgnumsamples);
41 printf("numSamples:%d\n",init->nSamples);
42 printf("bufferSize:%d\n",init->bufferSize);
45 void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int numsamples, char first)
50 buf = malloc(init->bufferSize);
54 len = codecEncodeChunk (numsamples, samples, buf);
55 len += codecFlush (&buf[len]);
56 len += codecExit (&buf[len]);
59 swf_SetU16(tag, numsamples); // number of samples
60 swf_SetU16(tag, 0); // seek
62 swf_SetBlock(tag, buf, len);
66 #endif // RFXSWF_DISABLESOUND