Generated from configure.in
[swftools.git] / lib / example / sound.c
1 /* sound.c
2
3    Generates a sine wave and tries to create an swf which
4    plays it as mp3 sound.
5    
6    Part of the swftools package.
7
8    Copyright (c) 2002 Matthias Kramm <kramm@quiss.org>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <math.h>
27 #include "../rfxswf.h"
28
29 int main (int argc,char ** argv)
30 { SWF swf;
31   RGBA rgb;
32   SRECT r;
33   int blocksize = 2304;
34   S32 width=300,height = 300;
35   U16 block[blocksize];
36   TAG * tag;
37   
38   int f,i,ls1,fs1;
39   int count;
40   int t;
41
42   memset(&swf,0x00,sizeof(SWF));        // set global movie parameters
43
44   swf.fileVersion    = 4;               // make flash 4 compatible swf
45   swf.frameRate      = 18*256;          // about 18 frames per second
46   
47   swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units ("twips")
48   swf.movieSize.ymax = 20*height;
49
50   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
51   tag = swf.firstTag;
52   rgb.r = 0xff;
53   rgb.g = 0xff;
54   rgb.b = 0xff;
55   swf_SetRGB(tag,&rgb);
56   
57   tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD2);
58   swf_SetSoundStreamHead(tag, 11025/18);
59
60   for(t=256;t>=0;t--) {
61       int s;
62       tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
63       for(s=0;s<blocksize;s++) {
64           block[s] = (int)(32767*sin(s*8*3.14159/blocksize));
65           if(t==0) block[s] = 0;
66       }
67       swf_SetSoundStreamBlock(tag, block, 1, 0);
68       tag = swf_InsertTag(tag, ST_SHOWFRAME);
69   }
70   
71   tag = swf_InsertTag(tag, ST_END);
72
73   f = open("sound.swf",O_WRONLY|O_CREAT|O_TRUNC, 0644);
74   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
75   close(f);
76
77   swf_FreeTags(&swf);                       // cleanup
78   return 0;
79 }
80
81