New compile option: RFXSWF_DISABLESOUND
[swftools.git] / lib / modules / swfsound.c
1 /* swfaction.c
2
3    SWF Sound handling routines
4    
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2001, 2002 Matthias Kramm <kramm@quiss.org>
9  
10    This file is distributed under the GPL, see file COPYING for details 
11
12 */
13
14 #ifndef RFXSWF_DISABLESOUND
15
16 #include "../rfxswf.h"
17
18 CodecInitOut * init = 0;
19 void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples)
20 {
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
28
29     CodecInitIn params;
30     memset(&params, 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(&params);
36
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);
40
41     printf("numSamples:%d\n",init->nSamples);
42     printf("bufferSize:%d\n",init->bufferSize);
43 }
44
45 void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int numsamples, char first)
46 {
47     char*buf;
48     int len = 0;
49
50     if(!buf)
51         return;
52     
53     buf = malloc(init->bufferSize);
54     
55     len = codecEncodeChunk (numsamples, samples, buf);
56     len += codecFlush (&buf[len]);
57     len += codecExit (&buf[len]);
58
59     if(first) {
60         swf_SetU16(tag, numsamples); // number of samples
61         swf_SetU16(tag, 0); // seek
62     }
63     swf_SetBlock(tag, buf, len);
64     free(buf);
65 }
66
67 #endif // RFXSWF_DISABLESOUND