private static void WriteAudioData(BinaryFile binaryFile, float[] audioData, int length) { for (int i = 0; i < audioData.Length; i++) { binaryFile.Write(audioData[i]); } // pad if neccesary if (length > audioData.Length) { for (int i = 0; i < length - audioData.Length; i++) { binaryFile.Write(0); } } }
private static void WriteAudioBlock(BinaryFile binaryFile, float[] audioData, int length, string channel) { binaryFile.Write("BLOCK"); binaryFile.Write((byte)0); string lengthText = length.ToString(); int lenghtTextLength = lengthText.Length; int blockLength = length*4+lenghtTextLength+13; string blockLengthText = blockLength.ToString(); binaryFile.Write(blockLengthText); // length from where "AUDIODATA" starts binaryFile.Write((byte)0); binaryFile.Write("AUDIODATA"); binaryFile.Write((byte)0); binaryFile.Write(channel); // channel text ("0" - "3") binaryFile.Write((byte)0); binaryFile.Write(lengthText); binaryFile.Write((byte)0); // Example: // channel 1 mono (L - 1) // length 701444 bytes / 4 bytes per float = 175361 float's WriteAudioData(binaryFile, audioData, length); }
public static void Write8Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { #if DEBUG Console.Write("Write8Bit...\n"); #endif for (int i = 0; i < samplecount; i++) { for (int ic = 0; ic < channels; ic++) { int val = Util.RoundToClosestInt((sound[ic][i] + 1) * 128); if (val > 255) val = 255; if (val < 0) val = 0; byte @byte = (byte) val; wavfile.Write(@byte); } } }
public static void Main(string[] args) { string inLeft = @"F:\SAMPLES\IMPULSE RESPONSES\PER IVAR IR SAMPLES\ALTIVERB-QUAD-IMPULSE-RESPONSES\Scoring Stages (Orchestral Studios)_Todd-AO - California US_st to st wide mics at 18m90_L.wav"; string inRight = @"F:\SAMPLES\IMPULSE RESPONSES\PER IVAR IR SAMPLES\ALTIVERB-QUAD-IMPULSE-RESPONSES\Scoring Stages (Orchestral Studios)_Todd-AO - California US_st to st wide mics at 18m90_R.wav"; float[] channel1; float[] channel2; float[] channel3; float[] channel4; AudioUtilsNAudio.SplitStereoWaveFileToMono(inLeft, out channel1, out channel2); AudioUtilsNAudio.SplitStereoWaveFileToMono(inRight, out channel3, out channel4); // find out what channel is longest int maxLength = Math.Max(channel1.Length, channel3.Length); string outputFile = @"Scoring Stages (Orchestral Studios)_Todd-AO - California US_st to st wide mics at 18m90V2.sir"; //string cfh_data = @"abe6f4214362.34U4T9yaBCCDEuyH0uCm7T6Pf.z+PqR.kBAoHEfz3DlPB4lX.K4XirMP+3WCzJZ6RYE0ka38ty94e5j858dEG1RUZlT3iZV2EATQgrjIV5ixyF5zA0qasZdXlJpZ8FtlNjwomlnU8lHn+JhPP48khE9n1HPSpVyoJhg5itqiqqKp600.vKJEevIQJ4fXS0aTksgilV6fMkL4wNFPLDn33w5irgZ7lpiNZaJe791OXu1ATcghs1bHHwzElL49JBlnXKYBBeeT8QCedFNXTRbHdVznj7XbHjFhSlLFaURBSgnoA1RJ7UWAwYQSCSew407fANeNiyoYvERkkO.1PVR0vMSTEqnZihvsR6eC5ammIKKcBl.NPeBmsPpDLBjimqMfQB15NVIEpXEZfXflcpdxcd77xh56HaQM9Shz7rIRJa4p+EHo0YfjCv3BeKI87QR6yGIW1qI+hIdM99OMVIuF+7+KqzUe.bo2V9C"; string cfh_data = @"abe6f42143 "; BinaryFile binaryFile = new BinaryFile(outputFile, BinaryFile.ByteOrder.LittleEndian, true); binaryFile.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); binaryFile.Write("\n\n"); binaryFile.Write("<SirImpulseFile version=\"2.1\" cfh_data=\""); binaryFile.Write(cfh_data); binaryFile.Write("\"/>"); binaryFile.Write("\r\n"); binaryFile.Write((byte)0); WriteAudioBlock(binaryFile, channel1, maxLength, "0"); WriteAudioBlock(binaryFile, channel2, maxLength, "1"); WriteAudioBlock(binaryFile, channel3, maxLength, "2"); WriteAudioBlock(binaryFile, channel4, maxLength, "3"); binaryFile.Close(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public static void WriteBMPGrayscale(string filePath, double[][] image, int bitDepth = 24) { var bmpfile = new BinaryFile(filePath, BinaryFile.ByteOrder.LittleEndian, true); int y = image.Length; int x = image[0].Length; const byte zerobyte = 255; // what byte should we pad with int numBytes = bitDepth / 8; // calculate zero bytes (bytes to skip at the end of each bitmap line) int zerobytes = (byte)(4 - ((x * numBytes) & numBytes)); if (zerobytes == 4) { zerobytes = 0; } #region Tags int filesize = 54 + ((x * numBytes) + zerobytes) * y; int imagesize = ((x * numBytes) + zerobytes) * y; bmpfile.Write("BM"); bmpfile.Write((UInt32)filesize); // filesize bmpfile.Write((UInt32)0); // reserved bmpfile.Write((UInt32)54); // off bits bmpfile.Write((UInt32)40); // bitmap info header size bmpfile.Write((UInt32)x); // width bmpfile.Write((UInt32)y); // height bmpfile.Write((UInt16)1); // planes bmpfile.Write((UInt32)bitDepth); // bit depth bmpfile.Write((UInt16)0); // compression bmpfile.Write((UInt32)imagesize); //bmpfile.Write((UInt32) 0); // There are at least three kind value of PelsPerMeter used for 96 DPI bitmap: // 0 - the bitmap just simply doesn't set this value // 2834 - 72 DPI // 3780 - 96 DPI const UInt32 pelsPerMeter = 0; //3780; bmpfile.Write((UInt32)pelsPerMeter); // XPelsPerMeter bmpfile.Write((UInt32)pelsPerMeter); // YPelsPerMeter bmpfile.Write((UInt32)0); // clr used bmpfile.Write((UInt32)0); // clr important #endregion Tags // backwards writing for (int iy = y - 1; iy != -1; iy--) { for (int ix = 0; ix < x; ix++) { // define color (grayscale) double vald = image[iy][ix] * 255.0; if (vald > 255.0) { vald = 255.0; } if (vald < 0.0) { vald = 0.0; } byte val = Convert.ToByte(vald); for (int ic = numBytes - 1; ic != -1; ic--) { if (ic == 0 && numBytes == 4) { bmpfile.Write((byte)0); // alpha bit } else { bmpfile.Write(val); } } } // write padding bytes for (int i = 0; i < zerobytes; i++) { bmpfile.Write(zerobyte); } } //bmpfile.Write((UInt16)0); bmpfile.Close(); #if DEBUG Console.Write("Image size : {0:D}x{1:D}\n", x, y); #endif }
private static void Write(BinaryFile bf, FxContent content, XmlDocument xmlDocument) { if (content == null) { Log.Error("Error writing file. Missing preset content."); return; } // determine if the chunkdata is saved as XML bool writeXMLChunkData = false; string xmlChunkData = ""; if (xmlDocument != null) { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlDocument.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); xmlChunkData = stringWriter.ToString().Replace("'", "'"); writeXMLChunkData = true; if (content is FxProgramSet) { ((FxProgramSet)content).ChunkSize = xmlChunkData.Length; } else if (content is FxChunkSet) { ((FxChunkSet)content).ChunkSize = xmlChunkData.Length; } } if (content.ChunkMagic != "CcnK") { Log.Error("Cannot save the preset file. Missing preset header information."); return; } bf.Write(content.ChunkMagic); // chunkMagic, 4 // check what preset type we are saving if (content.FxMagic == "FBCh") { // Bank (.fxb) with chunk (magic = 'FBCh') var chunkSet = (FxChunkSet)content; chunkSet.ByteSize = 152 + chunkSet.ChunkSize; bf.Write(chunkSet.ByteSize); // byteSize = 4 bf.Write(chunkSet.FxMagic); // fxMagic, 4 bf.Write(chunkSet.Version); // version, 4 bf.Write(chunkSet.FxID); // fxID, 4 bf.Write(chunkSet.FxVersion); // fxVersion, 4 bf.Write(chunkSet.NumPrograms); // numPrograms, 4 bf.Write(chunkSet.Future, 128); // future, 128 bf.Write(chunkSet.ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(chunkSet.ChunkData, BinaryFile.ByteOrder.LittleEndian); } } else if (content.FxMagic == "FPCh") { // Preset (Program) (.fxp) with chunk (magic = 'FPCh') var programSet = (FxProgramSet)content; programSet.ByteSize = 52 + programSet.ChunkSize; bf.Write(programSet.ByteSize); // byteSize = 4 bf.Write(programSet.FxMagic); // fxMagic, 4 bf.Write(programSet.Version); // version, 4 bf.Write(programSet.FxID); // fxID, 4 bf.Write(programSet.FxVersion); // fxVersion, 4 bf.Write(programSet.NumPrograms); // numPrograms, 4 bf.Write(programSet.Name, 28); // name, 28 bf.Write(programSet.ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(programSet.ChunkData, BinaryFile.ByteOrder.LittleEndian); } } else if (content.FxMagic == "FxCk") { // For Preset (Program) (.fxp) without chunk (magic = 'FxCk') var program = (FxProgram)content; program.ByteSize = 48 + (4 * program.NumParameters); bf.Write(program.ByteSize); // byteSize = 4 bf.Write(program.FxMagic); // fxMagic, 4 bf.Write(program.Version); // version, 4 bf.Write(program.FxID); // fxID, 4 bf.Write(program.FxVersion); // fxVersion, 4 bf.Write(program.NumParameters); // numParameters, 4 bf.Write(program.ProgramName, 28); // name, 28 // variable no. of parameters for (int i = 0; i < program.NumParameters; i++) { bf.Write((float)program.Parameters[i]); } } else if (content.FxMagic == "FxBk") { // For bank (.fxb) without chunk (magic = 'FxBk') var set = (FxSet)content; // variable no. of programs var byteSize = 48; for (int i = 0; i < set.NumPrograms; i++) { var program = set.Programs[i]; byteSize += (4 * program.NumParameters); } set.ByteSize = 156 + byteSize; bf.Write(set.ByteSize); // byteSize = 4 bf.Write(set.FxMagic); // fxMagic, 4 bf.Write(set.Version); // version, 4 bf.Write(set.FxID); // fxID, 4 bf.Write(set.FxVersion); // fxVersion, 4 bf.Write(set.NumPrograms); // numPrograms, 4 bf.Write(set.Future, 128); // future, 128 // variable no. of programs for (int i = 0; i < set.NumPrograms; i++) { var program = set.Programs[i]; Write(bf, program, null); } } }
/** * Saves selected frame span to a new file. * * @param filename where to save frames * @param begin number of the first frame * @param end number of the last frame * @throw FormatException not allowed to save 8b-mono files */ public void SaveFrames(string filename, int begin, int end) { if (1 == hdr.Channels && 8 == hdr.BitsPerSamp) { throw new FormatException("Save error: 8-bit mono files are not supported yet!"); } int samples = GetSamplesPerFrame(); // calculate the boundaries of a fragment of the source channel // which correspond to given frame numbers int startPos = (int)(begin * samples * (1 - overlap)); int endPos = (int)((end + 1) * samples * (1 - overlap) + samples * overlap); if (endPos > LChTab.Count) endPos = LChTab.Count; // number of data bytes in the resulting wave file UInt32 waveSize = (UInt32) (endPos - startPos) * hdr.BytesPerSamp; // prepare a new header and write it to file stream WaveHeader newHdr = new WaveHeader(); //std.strncpy(newHdr.RIFF, hdr.RIFF, 4); newHdr.DataLength = (UInt32) (waveSize + newHdr.WaveHeaderSize); //std.strncpy(newHdr.WAVE, hdr.WAVE, 4); //std.strncpy(newHdr.fmt_, hdr.fmt_, 4); newHdr.SubBlockLength = hdr.SubBlockLength; newHdr.formatTag = hdr.formatTag; newHdr.Channels = hdr.Channels; newHdr.SampFreq = hdr.SampFreq; newHdr.BytesPerSec = hdr.BytesPerSec; newHdr.BytesPerSamp = hdr.BytesPerSamp; newHdr.BitsPerSamp = hdr.BitsPerSamp; //std.strncpy(newHdr.data, hdr.data, 4); newHdr.WaveSize = waveSize; BinaryFile fs = new BinaryFile(filename); //fs.write((string) newHdr, sizeof(WaveHeader)); fs.Write(newHdr.RIFF); fs.Write(newHdr.DataLength); fs.Write(newHdr.WAVE); fs.Write(newHdr.fmt_); fs.Write(newHdr.SubBlockLength); fs.Write(newHdr.formatTag); fs.Write(newHdr.Channels); fs.Write(newHdr.SampFreq); fs.Write(newHdr.BytesPerSec); fs.Write(newHdr.BytesPerSamp); fs.Write(newHdr.BitsPerSamp); fs.Write(newHdr.data); fs.Write(newHdr.WaveSize); // convert our data from source channels to a temporary buffer short[] data = new short[waveSize/2]; for (int i = startPos, di = 0; i < endPos; ++i, ++di) { if (16 == hdr.BitsPerSamp) { if (2 == hdr.Channels) { data[2 *di] = LChTab[i]; data[2 *di+1] = RChTab[i]; } else { data[di] = LChTab[i]; } } else { if (2 == hdr.Channels) { //data[di/2] = ((RChTab[i] + 128) << 8) | (LChTab[i] + 128); } } } // write the raw data to file and clean the buffer for (int i = 0; i < data.Length; i++) { fs.Write(data[i]); } fs.Close(); data = null; }
public static void Write16Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { #if DEBUG Console.Write("Write16Bit...\n"); #endif for (int i = 0; i<samplecount; i++) { for (int ic = 0;ic<channels;ic++) { int val = Util.RoundToClosestInt(sound[ic][i] * 32768); if (val > 32767) val = 32767; if (val < -32768) val = -32768; wavfile.Write((Int16) val); } } }
public static void Write8Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { int i = 0; int ic = 0; double val; byte @byte = new byte(); #if DEBUG Console.Write("Write8Bit...\n"); #endif for (i = 0; i<samplecount; i++) { for (ic = 0;ic<channels;ic++) { val = GlobalMembersUtil.RoundOff((sound[ic][i]+1.0)*128.0); if (val>255) val = 255; if (val<0) val = 0; @byte = (byte) val; wavfile.Write(@byte); } } }
private byte[] GetChunkData() { var memStream = new MemoryStream(); var bFile = new BinaryFile(memStream, BinaryFile.ByteOrder.LittleEndian); // Write UAD Preset Header information bFile.Write((int) PresetHeaderVar1); bFile.Write((int) PresetHeaderVar2); bFile.Write(PresetName, 32); // Write Parameters bFile.Write((float) Input); // (-20.0 dB -> 20.0 dB) bFile.Write((float) Phase); // (Normal -> Inverted) bFile.Write((float) HPFreq); // (Out -> 304 Hz) bFile.Write((float) LPFreq); // (Out -> 3.21 k) bFile.Write((float) HP_LPDynSC); // (Off -> On) bFile.Write((float) CMPRatio); // (1.00:1 -> Limit) bFile.Write((float) CMPThresh); // (10.0 dB -> -20.0 dB) bFile.Write((float) CMPRelease); // (0.10 s -> 4.00 s) bFile.Write((float) CMPAttack); // (Auto -> Fast) bFile.Write((float) StereoLink); // (UnLink -> Link) bFile.Write((float) Select); // (Expand -> Gate 2) bFile.Write((float) EXPThresh); // (-30.0 dB -> 10.0 dB) bFile.Write((float) EXPRange); // (0.0 dB -> 40.0 dB) bFile.Write((float) EXPRelease); // (0.10 s -> 4.00 s) bFile.Write((float) EXPAttack); // (Auto -> Fast) bFile.Write((float) DYNIn); // (Out -> In) bFile.Write((float) CompIn); // (Out -> In) bFile.Write((float) ExpIn); // (Out -> In) bFile.Write((float) LFGain); // (-10.0 dB -> 10.0 dB) bFile.Write((float) LFFreq); // (36.1 Hz -> 355 Hz) bFile.Write((float) LFBell); // (Shelf -> Bell) bFile.Write((float) LMFGain); // (-15.6 dB -> 15.6 dB) bFile.Write((float) LMFFreq); // (251 Hz -> 2.17 k) bFile.Write((float) LMFQ); // (2.50 -> 2.50) bFile.Write((float) HMFQ); // (4.00 -> 0.40) bFile.Write((float) HMFGain); // (-16.5 dB -> 16.5 dB) bFile.Write((float) HMFFreq); // (735 Hz -> 6.77 k) bFile.Write((float) HFGain); // (-16.0 dB -> 16.1 dB) bFile.Write((float) HFFreq); // (6.93 k -> 21.7 k) bFile.Write((float) HFBell); // (Shelf -> Bell) bFile.Write((float) EQIn); // (Out -> In) bFile.Write((float) EQDynSC); // (Off -> On) bFile.Write((float) PreDyn); // (Off -> On) bFile.Write((float) Output); // (-20.0 dB -> 20.0 dB) bFile.Write((float) EQType); // (Black -> Brown) bFile.Write((float) Power); // (Off -> On) byte[] chunkData = memStream.ToArray(); memStream.Close(); return chunkData; }
// write to file a 32-bit integer in little endian public static void WriteUInt32(UInt32 w, BinaryFile file) { file.Write(w); }
// write to file a 16-bit integer in little endian public static void WriteUInt16(UInt16 s, BinaryFile file) { file.Write(s); }
public static bool Convert2FabfilterProQ(REWEQFilters filters, string filePath) { List<ProQBand> proQBands = new List<ProQBand>(); foreach (REWEQBand filter in filters) { ProQBand band = new ProQBand(); band.FilterFreq = filter.FilterFreq; band.FilterGain = filter.FilterGain; band.FilterQ = filter.FilterQ; band.Enabled = filter.Enabled; switch (filter.FilterType) { case REWEQFilterType.PK: band.FilterType = ProQFilterType.Bell; break; case REWEQFilterType.LP: band.FilterType = ProQFilterType.HighCut; break; case REWEQFilterType.HP: band.FilterType = ProQFilterType.LowCut; break; case REWEQFilterType.LS: band.FilterType = ProQFilterType.LowShelf; break; case REWEQFilterType.HS: band.FilterType = ProQFilterType.HighShelf; break; default: band.FilterType = ProQFilterType.Bell; break; } band.FilterLPHPSlope = ProQLPHPSlope.Slope24dB_oct; band.FilterStereoPlacement = ProQStereoPlacement.Stereo; proQBands.Add(band); } BinaryFile binFile = new BinaryFile(filePath, BinaryFile.ByteOrder.LittleEndian, true); binFile.Write("FPQr"); binFile.Write((int) 2); binFile.Write((int) 180); binFile.Write((float) proQBands.Count); for (int i = 0; i < 24; i++) { if (i < proQBands.Count) { binFile.Write((float) FreqConvert(proQBands[i].FilterFreq)); binFile.Write((float) proQBands[i].FilterGain); binFile.Write((float) QConvert(proQBands[i].FilterQ)); binFile.Write((float) proQBands[i].FilterType); binFile.Write((float) proQBands[i].FilterLPHPSlope); binFile.Write((float) proQBands[i].FilterStereoPlacement); binFile.Write((float) (proQBands[i].Enabled ? 1 : 0) ); } else { binFile.Write((float) FreqConvert(1000)); binFile.Write((float) 0); binFile.Write((float) QConvert(1)); binFile.Write((float) ProQFilterType.Bell); binFile.Write((float) ProQLPHPSlope.Slope24dB_oct); binFile.Write((float) ProQStereoPlacement.Stereo); binFile.Write((float) 1); } } binFile.Write((float) 0); // float output_gain; // -1 to 1 (- Infinity to +36 dB , 0 = 0 dB) binFile.Write((float) 0); // float output_pan; // -1 to 1 (0 = middle) binFile.Write((float) 2); // float display_range; // 0 = 6dB, 1 = 12dB, 2 = 30dB, 3 = 3dB binFile.Write((float) 0); // float process_mode; // 0 = zero latency, 1 = lin.phase.low - medium - high - maximum binFile.Write((float) 0); // float channel_mode; // 0 = Left/Right, 1 = Mid/Side binFile.Write((float) 0); // float bypass; // 0 = No bypass binFile.Write((float) 0); // float receive_midi; // 0 = Enabled? binFile.Write((float) 3); // float analyzer; // 0 = Off, 1 = Pre, 2 = Post, 3 = Pre+Post binFile.Write((float) 1); // float analyzer_resolution; // 0 - 3 : low - medium[x] - high - maximum binFile.Write((float) 2); // float analyzer_speed; // 0 - 3 : very slow, slow, medium[x], fast binFile.Write((float) -1); // float solo_band; // -1 binFile.Close(); return true; }
public void WriteFile(string filePath) { BinaryFile bf = new BinaryFile(filePath, BinaryFile.ByteOrder.BigEndian, true); // determine if the chunkdata is saved as XML bool writeXMLChunkData = false; string xmlChunkData = ""; if (XmlDocument != null) { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); XmlDocument.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); xmlChunkData = stringWriter.ToString().Replace("'", "'"); ChunkSize = xmlChunkData.Length; writeXMLChunkData = true; } if (ChunkMagic != "CcnK") { Console.Out.WriteLine("Cannot save the preset file. Missing preset header information."); return; } Console.Out.WriteLine("Writing FXP to {0} ...", filePath); bf.Write(ChunkMagic); // chunkMagic, 4 // check what preset type we are saving if (FxMagic == "FBCh") { // Bank with Chunk Data ByteSize = 152 + ChunkSize; bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ProgramCount); // numPrograms, 4 bf.Write(Future, 128); // future, 128 bf.Write(ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian); } } else if (FxMagic == "FPCh") { // Preset with Chunk Data ByteSize = 52 + ChunkSize; bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ProgramCount); // numPrograms, 4 bf.Write(Name, 28); // name, 28 bf.Write(ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian); } } else if (FxMagic == "FxCk") { // For Preset (Program) (.fxp) without chunk (magic = 'FxCk') // Bank with Chunk Data ByteSize = 48 + (4 * ParameterCount); bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ParameterCount); // numParameters, 4 bf.Write(Name, 28); // name, 28 // variable no. of parameters for (int i = 0; i < ParameterCount; i++) { bf.Write((float)Parameters[i]); } } bf.Close(); }
public void WriteFile( string filePath ) { BinaryFile bf = new BinaryFile(filePath, BinaryFile.ByteOrder.BigEndian, true); // determine if the chunkdata is saved as XML bool writeXMLChunkData = false; string xmlChunkData = ""; if (XmlDocument != null) { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); XmlDocument.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); xmlChunkData = stringWriter.ToString().Replace("'", "'"); ChunkSize = xmlChunkData.Length; writeXMLChunkData = true; } if (ChunkMagic != "CcnK") { Console.Out.WriteLine("Cannot save the preset file. Missing preset header information."); return; } Console.Out.WriteLine("Writing FXP to {0} ...", filePath); bf.Write(ChunkMagic); // chunkMagic, 4 // check what preset type we are saving if (FxMagic == "FBCh") { // Bank with Chunk Data ByteSize = 152 + ChunkSize; bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ProgramCount); // numPrograms, 4 bf.Write(Future, 128); // future, 128 bf.Write(ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian); } } else if (FxMagic == "FPCh") { // Preset with Chunk Data ByteSize = 52 + ChunkSize; bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ProgramCount); // numPrograms, 4 bf.Write(Name, 28); // name, 28 bf.Write(ChunkSize); // chunkSize, 4 if (writeXMLChunkData) { bf.Write(xmlChunkData); // chunkData, <chunkSize> } else { // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian); } } else if (FxMagic == "FxCk") { // For Preset (Program) (.fxp) without chunk (magic = 'FxCk') // Bank with Chunk Data ByteSize = 48 + (4*ParameterCount); bf.Write(ByteSize); // byteSize = 4 bf.Write(FxMagic); // fxMagic, 4 bf.Write(Version); // version, 4 bf.Write(FxID); // fxID, 4 bf.Write(FxVersion); // fxVersion, 4 bf.Write(ParameterCount); // numParameters, 4 bf.Write(Name, 28); // name, 28 // variable no. of parameters for (int i = 0; i < ParameterCount; i++) { bf.Write((float) Parameters[i]); } } bf.Close(); }
public static void Write32Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { #if DEBUG Console.Write("Write32Bit...\n"); #endif for (int i = 0; i < samplecount; i++) { for (int ic = 0; ic < channels; ic++) { int val = Util.RoundToClosestInt(sound[ic][i] * 2147483648); if (val > 2147483647) val = 2147483647; if (val < -2147483648) val = -2147483648; wavfile.Write((int) val); } } }
public static bool Convert2ReaEQ(REWEQFilters filters, string filePath) { List<ReaEQBand> ReaEqBands = new List<ReaEQBand>(); foreach (REWEQBand filter in filters) { ReaEQBand band = new ReaEQBand(); band.LogScaleAutoFreq = true; band.FilterFreq = filter.FilterFreq; band.FilterGain = filter.FilterGain; band.FilterBWOct = filter.FilterBWOct; band.Enabled = filter.Enabled; switch (filter.FilterType) { case REWEQFilterType.PK: band.FilterType = ReaEQFilterType.Band; break; case REWEQFilterType.LP: band.FilterType = ReaEQFilterType.LowPass; break; case REWEQFilterType.HP: band.FilterType = ReaEQFilterType.HighPass; break; case REWEQFilterType.LS: band.FilterType = ReaEQFilterType.LowShelf; break; case REWEQFilterType.HS: band.FilterType = ReaEQFilterType.HighShelf; break; default: band.FilterType = ReaEQFilterType.Band; break; } ReaEqBands.Add(band); } // store to file FXP fxp = new FXP(); fxp.ChunkMagic = "CcnK"; fxp.ByteSize = 0; // will be set correctly by FXP class fxp.FxMagic = "FPCh"; // FPCh = FXP (preset), FBCh = FXB (bank) fxp.Version = 1; // Format Version (should be 1) fxp.FxID = "reeq"; fxp.FxVersion = 1100; fxp.ProgramCount = 1; fxp.Name = ""; using(MemoryStream memStream = new MemoryStream(10)) { BinaryFile binFile = new BinaryFile(memStream, BinaryFile.ByteOrder.LittleEndian); binFile.Write((int)33); binFile.Write((int)ReaEqBands.Count); foreach (ReaEQBand band in ReaEqBands) { binFile.Write((int) band.FilterType); binFile.Write((int) (band.Enabled ? 1 : 0) ); binFile.Write((double) band.FilterFreq); binFile.Write((double) Decibel2AmplitudeRatio(band.FilterGain)); binFile.Write((double) band.FilterBWOct); binFile.Write((byte) 1); } binFile.Write((int)1); binFile.Write((int)1); binFile.Write((double) Decibel2AmplitudeRatio(0.00)); binFile.Write((int)0); memStream.Flush(); byte[] chunkData = memStream.GetBuffer(); fxp.ChunkSize = chunkData.Length; fxp.ChunkDataByteArray = chunkData; } fxp.WriteFile(filePath); return true; }
public static void Write32BitFloat(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { #if DEBUG Console.Write("Write32BitFloat...\n"); #endif for (int i = 0; i < samplecount; i++) { for (int ic = 0; ic < channels; ic++) { wavfile.Write((float)sound[ic][i]); } } }
public static void BMPWrite(BinaryFile bmpfile, double[][] image, int y, int x) { int i = 0; // various iterators int iy = 0; int ix = 0; int ic = 0; int filesize = 0; int imagesize = 0; byte zerobytes = new byte(); byte val = new byte(); byte zero = 0; double vald; #if DEBUG Console.Write("BMPWrite...\n"); #endif zerobytes = (byte) (4 - ((x *3) & 3)); // computation of zero bytes if (zerobytes == 4) { zerobytes = 0; } //********Tags******** filesize = 56 + ((x *3)+zerobytes) * y; imagesize = 2 + ((x *3)+zerobytes) * y; GlobalMembersUtil.WriteUInt16(19778, bmpfile); GlobalMembersUtil.WriteUInt32((UInt32)filesize, bmpfile); GlobalMembersUtil.WriteUInt32(0, bmpfile); GlobalMembersUtil.WriteUInt32(54, bmpfile); GlobalMembersUtil.WriteUInt32(40, bmpfile); GlobalMembersUtil.WriteUInt32((UInt32)x, bmpfile); GlobalMembersUtil.WriteUInt32((UInt32)y, bmpfile); GlobalMembersUtil.WriteUInt16(1, bmpfile); GlobalMembersUtil.WriteUInt32(24, bmpfile); GlobalMembersUtil.WriteUInt16(0, bmpfile); GlobalMembersUtil.WriteUInt32((UInt32)imagesize, bmpfile); GlobalMembersUtil.WriteUInt32(2834, bmpfile); GlobalMembersUtil.WriteUInt32(2834, bmpfile); GlobalMembersUtil.WriteUInt32(0, bmpfile); GlobalMembersUtil.WriteUInt32(0, bmpfile); //--------Tags-------- for (iy = y-1; iy!=-1; iy--) { // backwards writing for (ix = 0; ix<x; ix++) { // define color vald = image[iy][ix] * 255.0; if (vald > 255.0) { vald = 255.0; } if (vald < 0.0) { vald = 0.0; } val = (byte) vald; for (ic = 2; ic!=-1; ic--) { bmpfile.Write(val); } } // write padding bytes for (i = 0; i<zerobytes; i++) { bmpfile.Write(zero); } } GlobalMembersUtil.WriteUInt16(0, bmpfile); bmpfile.Close(); #if DEBUG Console.Write("Image size : {0:D}x{1:D}\n", x, y); #endif }
public static void Write32Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { int i = 0; int ic = 0; double val; #if DEBUG Console.Write("Write32Bit...\n"); #endif for (i = 0; i<samplecount; i++) { for (ic = 0;ic<channels;ic++) { val = GlobalMembersUtil.RoundOff(sound[ic][i]*2147483648.0); if (val>2147483647.0) val = 2147483647.0; if (val<-2147483648.0) val = -2147483648.0; wavfile.Write((int) val); } } }