void BMPVideoEncoder::SetAudioFormat(const tWAVEFORMATEX *fmt) { if(params.CaptureAudio && !intn->wave) { char filename[512]; strcpy_s(filename,prefix); strcat_s(filename,".wav"); delete intn->wfx; intn->wfx = CopyFormat(fmt); intn->wave = fopen(filename,"wb"); if(intn->wave) { static unsigned char header[] = "RIFF\0\0\0\0WAVEfmt "; static unsigned char data[] = "data\0\0\0\0"; fwrite(header,1,sizeof(header)-1,intn->wave); DWORD len = fmt->cbSize ? sizeof(WAVEFORMATEX)+fmt->cbSize : sizeof(WAVEFORMATEX)-2; fwrite(&len,1,sizeof(DWORD),intn->wave); fwrite(fmt,1,len,intn->wave); fwrite(data,1,sizeof(data)-1,intn->wave); } // fill already written frames with no sound unsigned char *buffer = new unsigned char[fmt->nBlockAlign * 1024]; int sampleFill = MulDiv(frame,fmt->nSamplesPerSec*frameRateDenom,frameRateScaled); memset(buffer,0,fmt->nBlockAlign * 1024); for(int samplePos=0;samplePos<sampleFill;samplePos+=1024) WriteAudioFrame(buffer,min(sampleFill-samplePos,1024)); } }
WAVEFORMATEX *BMPVideoEncoder::GetAudioFormat() { if(!intn->wave || !intn->wfx) return 0; return CopyFormat(intn->wfx); }
/* BalsaTypeMakeDefaultFormatBody : body function of BalsaTypeMakeDefaultFormat, make format into a preallocated array (format) */ static void BalsaTypeMakeDefaultFormatBody (const BalsaType * type, FormatElement * format) { int i; FormatPosition position; position.offset = 0; position.bitCount = ABS (type->size); /* usual case for whole type printing */ if (type->format) /* Copy the elements of the format rather than making a new one. This is really just a fallback in case this function is called when type->format is already set to allow a new format to be created */ { format = CopyFormat (format, type->format, 0); } else { switch (type->nature) { case BalsaNumericType: NewFormatNumber (format, position); format->info.number.showSign = type->size < 0; format++; break; case BalsaEnumerationType: { unsigned elementCount = type->info.enumeration.elementCount; FormatEnumerationElement *elements = malloc (sizeof (FormatEnumerationElement) * elementCount); char **elementNames = type->info.enumeration.elementNames; FormatData **elementValues = type->info.enumeration.elementValues; for (i = 0; i < elementCount; i++) { elements[i].name = strdup (elementNames[i]); elements[i].value = CopyFormatData (elementValues[i]); } NewFormatEnumeration (format, position, elementCount, elements); format++; } break; case BalsaRecordType: { unsigned elementCount = type->info.record.elementCount; unsigned offset = 0; /* "{" "elemType0" "," ... "elemTypeN-1" "}" */ NewFormatLiteral (format, "{", 1); format++; for (i = 0; i < elementCount; i++) { BalsaType *elementType = type->info.record.elementTypes[i]; BalsaTypeMakeDefaultFormat (elementType); format = CopyFormat (format, elementType->format, offset); offset += ABS (elementType->size); NewFormatLiteral (format, (i == elementCount - 1 ? "}" : ","), 1); format++; } } break; case BalsaArrayType: { unsigned elementCount = type->info.array.elementCount; unsigned offset = 0; BalsaType *elementType = type->info.array.elementType; /* "{" "elem" "," ... "elem" "}" */ NewFormatLiteral (format, "{", 1); format++; BalsaTypeMakeDefaultFormat (elementType); for (i = 0; i < elementCount; i++) { format = CopyFormat (format, elementType->format, offset); offset += ABS (elementType->size); NewFormatLiteral (format, (i == elementCount - 1 ? "}" : ","), 1); format++; } } break; case BalsaAliasType: BalsaTypeMakeDefaultFormat (type->info.alias.type); format = CopyFormat (format, type->info.alias.type->format, 0); break; case BalsaBuiltinType: /* Special case for strings */ if (strcmp (type->name, "String") == 0) { NewFormatString (format, position, '\"', (FormatGetFunction) BalsaObjectStringGetCharPtr, (FormatPutFunction) BalsaObjectStringPutBalsaString); format++; } else { NewFormatLiteral (format, "builtin: ", 0); format++; NewFormatNumber (format, position); format++; } break; default: break; } } }