X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfsound.c;h=d76baec513275bd69f53906d29e331ed0f85f3f2;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hp=8b2f6319be76a709ebebfb9c9faba3d7e9affae3;hpb=056d35e804cf89bf4bc85fe89c9b0a910e4b23f3;p=swftools.git diff --git a/lib/modules/swfsound.c b/lib/modules/swfsound.c index 8b2f631..d76baec 100644 --- a/lib/modules/swfsound.c +++ b/lib/modules/swfsound.c @@ -21,12 +21,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef RFXSWF_DISABLESOUND +#ifndef NO_MP3 #include "../rfxswf.h" #ifdef BLADEENC -fjokjklj +#define HAVE_SOUND + CodecInitOut * init = 0; void swf_SetSoundStreamHead(TAG*tag, U16 avgnumsamples) { @@ -59,7 +60,7 @@ void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int numsamples, char first) char*buf; int len = 0; - buf = malloc(init->bufferSize); + buf = rfx_alloc(init->bufferSize); if(!buf) return; @@ -72,23 +73,36 @@ void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int numsamples, char first) swf_SetU16(tag, 0); // seek } swf_SetBlock(tag, buf, len); - free(buf); + rfx_free(buf); } #endif +void swf_SetSoundDefineRaw(TAG*tag, S16*samples, int numsamples) +{ + swf_SetU8(tag,(/*compression*/0<<4)|(/*rate*/3<<2)|(/*size*/1<<1)|/*mono*/0); + swf_SetU32(tag, numsamples); // 44100 -> 11025 + swf_SetBlock(tag, (U8*)samples, numsamples*2); +} -#ifdef LAME - -#include "../lame/lame.h" +/* TODO: find a better way to set these from the outside */ -/* TODO: find a way to set these from the outside */ int swf_mp3_in_samplerate = 44100; int swf_mp3_out_samplerate = 11025; int swf_mp3_channels = 1; int swf_mp3_bitrate = 32; +#ifdef HAVE_LAME +#define HAVE_SOUND + +#include +#include + static lame_global_flags*lame_flags; +void null_errorf(const char *format, va_list ap) +{ +} + static void initlame() { unsigned char buf[4096]; @@ -114,12 +128,14 @@ static void initlame() lame_init_params(lame_flags); lame_init_bitstream(lame_flags); + lame_set_errorf(lame_flags, null_errorf); /* The first two flush calls to lame always fail, for some reason. Do them here where they cause no damage. */ lame_encode_flush_nogap(lame_flags, buf, bufsize); //printf("init:flush_nogap():%d\n", len); lame_encode_flush(lame_flags, buf, bufsize); //printf("init:flush():%d\n", len); + lame_set_errorf(lame_flags, 0); } void swf_SetSoundStreamHead(TAG*tag, int avgnumsamples) @@ -152,10 +168,10 @@ void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int seek, char first) char*buf; int len = 0; int bufsize = 16384; - int numsamples = ((swf_mp3_out_samplerate > 22050) ? 1152 : 576) * (swf_mp3_in_samplerate/swf_mp3_out_samplerate); + int numsamples = (int)(((swf_mp3_out_samplerate > 22050) ? 1152 : 576) * ((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate)); int fs = 0; - buf = malloc(bufsize); + buf = rfx_alloc(bufsize); if(!buf) return; @@ -175,7 +191,7 @@ void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int seek, char first) fprintf(stderr, "ok: mp3 nonempty block, %d samples, first:%d, framesize:%d\n", numsamples, first, fs); }*/ - free(buf); + rfx_free(buf); } void swf_SetSoundStreamEnd(TAG*tag) @@ -183,18 +199,12 @@ void swf_SetSoundStreamEnd(TAG*tag) lame_close (lame_flags); } -void swf_SetSoundDefineRaw(TAG*tag, S16*samples, int num, int samplerate) -{ - //swf_SetU8(tag,(/*compression*/0<<4)|(/*rate*/3<<2)|(/*size*/1<<1)|/*mono*/0); - //swf_SetU32(tag, numsamples); // 44100 -> 11025 - //swf_SetBlock(tag, wav2.data, numsamples*2); -} void swf_SetSoundDefine(TAG*tag, S16*samples, int num) { char*buf; int oldlen=0,len = 0; int bufsize = 16384; - int blocksize = ((swf_mp3_out_samplerate > 22050) ? 1152 : 576) * (swf_mp3_in_samplerate/swf_mp3_out_samplerate); + int blocksize = (int)(((swf_mp3_out_samplerate > 22050) ? 1152 : 576) * ((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate)); int t; int blocks; @@ -213,11 +223,11 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type); - swf_SetU32(tag,blocks*blocksize / - (swf_mp3_in_samplerate/swf_mp3_out_samplerate) // account for resampling + swf_SetU32(tag, (int)(tag,blocks*blocksize / + ((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate)) // account for resampling ); - buf = malloc(bufsize); + buf = rfx_alloc(bufsize); if(!buf) return; @@ -234,9 +244,36 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) len = 0; } - free(buf); + rfx_free(buf); +} + +#endif + +#endif + +#ifndef HAVE_SOUND + +// supply stubs + +void swf_SetSoundStreamHead(TAG*tag, int avgnumsamples) +{ + fprintf(stderr, "Error: no mp3 soundstream support compiled in.\n");exit(1); +} +void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int seek, char first) +{ + fprintf(stderr, "Error: no mp3 soundstream support compiled in.\n");exit(1); +} +void swf_SetSoundStreamEnd(TAG*tag) +{ + fprintf(stderr, "Error: no mp3 soundstream support compiled in.\n");exit(1); +} +void swf_SetSoundDefine(TAG*tag, S16*samples, int num) +{ + swf_SetSoundDefineRaw(tag, samples,num); } +#endif + #define SOUNDINFO_STOP 32 #define SOUNDINFO_NOMULTIPLE 16 #define SOUNDINFO_HASENVELOPE 8 @@ -244,6 +281,7 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) #define SOUNDINFO_HASOUTPOINT 2 #define SOUNDINFO_HASINPOINT 1 + void swf_SetSoundInfo(TAG*tag, SOUNDINFO*info) { U8 flags = (info->stop?SOUNDINFO_STOP:0) @@ -270,6 +308,26 @@ void swf_SetSoundInfo(TAG*tag, SOUNDINFO*info) } } -#endif -#endif // RFXSWF_DISABLESOUND +void swf_SetSoundDefineMP3(TAG*tag, U8* data, unsigned length, + unsigned SampRate, + unsigned Channels, + unsigned NumFrames) +{ + U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3, 3 = raw le, 6 = nellymoser + U8 rate; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz + U8 size = 1; // 0 = 8 bit, 1 = 16 bit + U8 type = Channels==2; // 0=mono, 1=stereo + + rate = (SampRate >= 40000) ? 3 + : (SampRate >= 19000) ? 2 + : (SampRate >= 8000) ? 1 + : 0; + + swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type); + + swf_SetU32(tag, NumFrames * 576); + + swf_SetU16(tag, 0); //delayseek + swf_SetBlock(tag, data, length); +}