Bugfix #4135
Mixdown option (blending sequence audio strips) didn't write proper WAV. - file length in header chunk was too short (potential crasher) - endian switch code used swab(), which wasn't defined to work when src and target is identical - cleaned up some code too... like removing timecursor() for core loop.
This commit is contained in:
@@ -163,6 +163,11 @@
|
||||
s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
|
||||
s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
|
||||
|
||||
#define SWITCH_SHORT(a) { \
|
||||
char s_i, *p_i; \
|
||||
p_i= (char *)&(a); \
|
||||
s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
|
||||
|
||||
|
||||
/* Bit operations */
|
||||
#define BTST(a,b) ( ( (a) & 1<<(b) )!=0 )
|
||||
|
||||
@@ -215,12 +215,6 @@ READ
|
||||
s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
|
||||
s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
|
||||
s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }
|
||||
// only used here in readfile.c
|
||||
#define SWITCH_SHORT(a) { \
|
||||
char s_i, *p_i; \
|
||||
p_i= (char *)&(a); \
|
||||
s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
|
||||
|
||||
|
||||
/***/
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ static void sound_panel_sequencer(void)
|
||||
uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");
|
||||
|
||||
yco -= 35;
|
||||
uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN", xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio");
|
||||
uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN", xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio (output goes to render output dir)");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -314,12 +314,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
|
||||
readPackedFile(pf, &shortbuf, 2);
|
||||
if(G.order==B_ENDIAN)
|
||||
{
|
||||
/* was SWITCH_SHORT before */
|
||||
char s_i, *p_i;
|
||||
p_i= (char *)&(shortbuf);
|
||||
s_i= p_i[0];
|
||||
p_i[0]= p_i[1];
|
||||
p_i[1]= s_i;
|
||||
SWITCH_SHORT(shortbuf);
|
||||
}
|
||||
|
||||
/* read the number of channels */
|
||||
@@ -327,12 +322,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
|
||||
|
||||
if(G.order==B_ENDIAN)
|
||||
{
|
||||
/* was SWITCH_SHORT before */
|
||||
char s_i, *p_i;
|
||||
p_i= (char *)&(shortbuf);
|
||||
s_i= p_i[0];
|
||||
p_i[0]= p_i[1];
|
||||
p_i[1]= s_i;
|
||||
SWITCH_SHORT(shortbuf);
|
||||
}
|
||||
|
||||
/* check the number of channels */
|
||||
@@ -367,12 +357,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
|
||||
readPackedFile(pf, &shortbuf, 2);
|
||||
if(G.order==B_ENDIAN)
|
||||
{
|
||||
/* was SWITCH_SHORT before */
|
||||
char s_i, *p_i;
|
||||
p_i= (char *)&(shortbuf);
|
||||
s_i= p_i[0];
|
||||
p_i[0]= p_i[1];
|
||||
p_i[1]= s_i;
|
||||
SWITCH_SHORT(shortbuf);
|
||||
}
|
||||
bits = shortbuf;
|
||||
|
||||
|
||||
@@ -131,9 +131,9 @@ static void do_sound_ipos(Sequence * seq)
|
||||
|
||||
void audio_mixdown()
|
||||
{
|
||||
int file, c, totlen, totframe, i, oldcfra, cfra2=0;
|
||||
int file, c, totlen, totframe, i, oldcfra;
|
||||
char *buf;
|
||||
Editing *ed;
|
||||
Editing *ed= G.scene->ed;
|
||||
|
||||
buf = MEM_mallocN(65536, "audio_mixdown");
|
||||
makewavstring(buf);
|
||||
@@ -145,12 +145,20 @@ void audio_mixdown()
|
||||
error("Can't open output file");
|
||||
return;
|
||||
}
|
||||
|
||||
waitcursor(1);
|
||||
|
||||
printf("Saving: %s ", buf);
|
||||
|
||||
strcpy(buf, "RIFFlengWAVEfmt fmln01ccRATEbsecBP16dataDLEN");
|
||||
totframe = (EFRA - SFRA + 1);
|
||||
totlen = (int) ( ((float)totframe / (float)G.scene->r.frs_sec) * (float)G.scene->audio.mixrate * 4.0);
|
||||
printf("totlen %x\n", totlen);
|
||||
printf(" totlen %d\n", totlen+36+8);
|
||||
|
||||
totlen+= 36; /* len is filesize-8 in WAV spec, total header is 44 bytes */
|
||||
memcpy(buf+4, &totlen, 4);
|
||||
totlen-= 36;
|
||||
|
||||
buf[16] = 0x10; buf[17] = buf[18] = buf[19] = 0; buf[20] = 1; buf[21] = 0;
|
||||
buf[22] = 2; buf[23]= 0;
|
||||
memcpy(buf+24, &G.scene->audio.mixrate, 4);
|
||||
@@ -165,7 +173,7 @@ void audio_mixdown()
|
||||
|
||||
/* length */
|
||||
SWITCH_INT(buf[4]);
|
||||
|
||||
|
||||
/* audio rate */
|
||||
SWITCH_INT(buf[24]);
|
||||
|
||||
@@ -180,29 +188,34 @@ void audio_mixdown()
|
||||
|
||||
oldcfra = CFRA;
|
||||
audiostream_play(SFRA, 0, 1);
|
||||
for (CFRA = SFRA, i = 0; (CFRA<=EFRA);
|
||||
CFRA=(int) ( ((float)(audio_pos-64)
|
||||
/( G.scene->audio.mixrate*4 ))
|
||||
*(float)G.scene->r.frs_sec )) {
|
||||
if (cfra2 != CFRA) {
|
||||
cfra2 = CFRA;
|
||||
set_timecursor(CFRA);
|
||||
}
|
||||
|
||||
i= 0;
|
||||
while ( totlen > 0 ) {
|
||||
totlen -= 64;
|
||||
|
||||
memset(buf+i, 0, 64);
|
||||
ed= G.scene->ed;
|
||||
|
||||
if (ed) {
|
||||
/* retrieve current frame for ipos */
|
||||
CFRA=(int) ( ((float)(audio_pos-64)/( G.scene->audio.mixrate*4 ))*(float)G.scene->r.frs_sec );
|
||||
|
||||
do_sound_ipos(ed->seqbasep->first);
|
||||
}
|
||||
}
|
||||
|
||||
audio_fill(buf+i, NULL, 64);
|
||||
if (G.order == B_ENDIAN) {
|
||||
swab(buf+i, buf+i, 64);
|
||||
char tbuf[64];
|
||||
memcpy(tbuf, buf+i, 64);
|
||||
swab(tbuf, buf+i, 64);
|
||||
}
|
||||
if (i == (65536-64)) {
|
||||
i=0;
|
||||
write(file, buf, 65536);
|
||||
} else i+=64;
|
||||
}
|
||||
else i+=64;
|
||||
}
|
||||
write(file, buf, i);
|
||||
|
||||
waitcursor(0);
|
||||
CFRA = oldcfra;
|
||||
close(file);
|
||||
|
||||
Reference in New Issue
Block a user