initial revision
[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 #include "../rfxswf.h"
15
16 void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples)
17 {
18     U8 playbackrate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
19     U8 playbacksize = 0; // 0 = 8 bit, 1 = 16 bit
20     U8 playbacktype = 1; // 0 = mono, 1 = stereo
21     U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3
22     U8 rate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
23     U8 size = 0; // 0 = 8 bit, 1 = 16 bit
24     U8 type = 1; // 0 = mono, 1 = stereo
25
26     swf_SetU8(tag,(playbackrate<<2)|(playbacksize<<1)|playbacktype);
27     swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type);
28     swf_SetU16(tag,avgnumsamples);
29 }
30
31 void swf_SetSoundStreamBlock(TAG*tag, U16*samples, int numsamples)
32 {
33     CodecInitOut * init;
34     CodecInitIn params;
35     char*buf;
36     int len = 0;
37
38     if(!buf)
39         return;
40
41     memset(&params, 0, sizeof(params));
42     params.frequency = 44100;  //48000, 44100 or 32000
43     params.mode = 0;      //0 = Stereo, 2 = Dual Channel, 3 = Mono
44     params.emphasis = 0;  //0 = None, 1 = 50/15 microsec, 3 = CCITT J.17
45     params.bitrate = 128;         //default is 128 (64 for mono)
46
47     init = codecInit(&params);
48     printf("nSamples:%d\n", init->nSamples);
49     printf("bufferSize:%d\n", init->bufferSize);
50     
51     buf = malloc(init->bufferSize);
52     
53     len = codecEncodeChunk(numsamples, samples, buf);
54     len += codecFlush (&buf[len]);
55     len += codecExit(&buf[len]);
56
57     swf_SetBlock(tag, buf, len);
58     free(buf);
59 }
60