X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfsound.c;h=d76baec513275bd69f53906d29e331ed0f85f3f2;hb=3d73649bf0e39778e715a07da902d0a858065a43;hp=935814cedf27b20feb7205e9fc5e68edb91d2838;hpb=4526077c616861018cfb3dc8a1cb4b7811148986;p=swftools.git diff --git a/lib/modules/swfsound.c b/lib/modules/swfsound.c index 935814c..d76baec 100644 --- a/lib/modules/swfsound.c +++ b/lib/modules/swfsound.c @@ -60,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; @@ -73,10 +73,17 @@ 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); +} + /* TODO: find a better way to set these from the outside */ int swf_mp3_in_samplerate = 44100; @@ -88,7 +95,7 @@ int swf_mp3_bitrate = 32; #define HAVE_SOUND #include -#include "../lame/lame.h" +#include static lame_global_flags*lame_flags; @@ -164,7 +171,7 @@ void swf_SetSoundStreamBlock(TAG*tag, S16*samples, int seek, char first) 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; @@ -184,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) @@ -192,12 +199,6 @@ 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; @@ -226,7 +227,7 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) ((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate)) // account for resampling ); - buf = malloc(bufsize); + buf = rfx_alloc(bufsize); if(!buf) return; @@ -243,7 +244,7 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) len = 0; } - free(buf); + rfx_free(buf); } #endif @@ -256,23 +257,19 @@ void swf_SetSoundDefine(TAG*tag, S16*samples, int num) void swf_SetSoundStreamHead(TAG*tag, int avgnumsamples) { - fprintf(stderr, "Error: no sound support compiled in.\n");exit(1); + 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 sound support compiled in.\n");exit(1); + fprintf(stderr, "Error: no mp3 soundstream support compiled in.\n");exit(1); } void swf_SetSoundStreamEnd(TAG*tag) { - fprintf(stderr, "Error: no sound support compiled in.\n");exit(1); -} -void swf_SetSoundDefineRaw(TAG*tag, S16*samples, int num, int samplerate) -{ - fprintf(stderr, "Error: no sound support compiled in.\n");exit(1); + fprintf(stderr, "Error: no mp3 soundstream support compiled in.\n");exit(1); } void swf_SetSoundDefine(TAG*tag, S16*samples, int num) { - fprintf(stderr, "Error: no sound support compiled in.\n");exit(1); + swf_SetSoundDefineRaw(tag, samples,num); } #endif @@ -312,3 +309,25 @@ void swf_SetSoundInfo(TAG*tag, SOUNDINFO*info) } +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); +}