initial revision
authorkramm <kramm>
Thu, 10 Jan 2002 19:29:14 +0000 (19:29 +0000)
committerkramm <kramm>
Thu, 10 Jan 2002 19:29:14 +0000 (19:29 +0000)
lib/modules/swfsound.c [new file with mode: 0644]

diff --git a/lib/modules/swfsound.c b/lib/modules/swfsound.c
new file mode 100644 (file)
index 0000000..5ccc756
--- /dev/null
@@ -0,0 +1,60 @@
+/* swfaction.c
+
+   SWF Sound handling routines
+   
+   Extension module for the rfxswf library.
+   Part of the swftools package.
+
+   Copyright (c) 2001, 2002 Matthias Kramm <kramm@quiss.org>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
+
+#include "../rfxswf.h"
+
+void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples)
+{
+    U8 playbackrate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
+    U8 playbacksize = 0; // 0 = 8 bit, 1 = 16 bit
+    U8 playbacktype = 1; // 0 = mono, 1 = stereo
+    U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3
+    U8 rate = 3; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
+    U8 size = 0; // 0 = 8 bit, 1 = 16 bit
+    U8 type = 1; // 0 = mono, 1 = stereo
+
+    swf_SetU8(tag,(playbackrate<<2)|(playbacksize<<1)|playbacktype);
+    swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type);
+    swf_SetU16(tag,avgnumsamples);
+}
+
+void swf_SetSoundStreamBlock(TAG*tag, U16*samples, int numsamples)
+{
+    CodecInitOut * init;
+    CodecInitIn params;
+    char*buf;
+    int len = 0;
+
+    if(!buf)
+       return;
+
+    memset(&params, 0, sizeof(params));
+    params.frequency = 44100;  //48000, 44100 or 32000
+    params.mode = 0;     //0 = Stereo, 2 = Dual Channel, 3 = Mono
+    params.emphasis = 0;  //0 = None, 1 = 50/15 microsec, 3 = CCITT J.17
+    params.bitrate = 128;        //default is 128 (64 for mono)
+
+    init = codecInit(&params);
+    printf("nSamples:%d\n", init->nSamples);
+    printf("bufferSize:%d\n", init->bufferSize);
+    
+    buf = malloc(init->bufferSize);
+    
+    len = codecEncodeChunk(numsamples, samples, buf);
+    len += codecFlush (&buf[len]);
+    len += codecExit(&buf[len]);
+
+    swf_SetBlock(tag, buf, len);
+    free(buf);
+}
+