public static byte[] BRRToWAV(byte[] inBrr, int rate, int loopStart) { if (inBrr == null) { inBrr = new byte[9]; } p1 = 0; p2 = 0; short[] samples = new short[0]; byte[] BRR = new byte[9]; int size = (int)inBrr.Length; //if (size % 9 != 0) //{ // MessageBox.Show("Error : BRR file isn't a multiple of 9 bytes or is too big."); // return null; //} int blockamount = size / 9; int offset = 0; size = 0; for (int i = 0; i < blockamount; i++) { BRR = Bits.GetBytes(inBrr, offset, 9); offset += 9; samples = append(samples, DecodeBRR(BRR)); //Append 16 BRR samples to existing array size += 16; } // int position = loopStart / 9 * 16; if (position >= size) { position = 0; } size -= position; // byte[] outWav = new byte[(size << 1) + 44]; offset = 0; Bits.SetChars(outWav, offset, "RIFF".ToCharArray()); offset += 4; Bits.SetInt32(outWav, offset, (size << 1) + 36); offset += 4; Bits.SetChars(outWav, offset, "WAVEfmt ".ToCharArray()); offset += 8; Bits.SetInt32(outWav, offset, 16); offset += 4; Bits.SetShort(outWav, offset, 1); offset += 2; Bits.SetShort(outWav, offset, 1); offset += 2; Bits.SetInt32(outWav, offset, rate); offset += 4; Bits.SetInt32(outWav, offset, rate * 2); offset += 4; Bits.SetShort(outWav, offset, 2); offset += 2; Bits.SetShort(outWav, offset, 16); offset += 2; Bits.SetChars(outWav, offset, "data".ToCharArray()); offset += 4; Bits.SetInt32(outWav, offset, size << 1); offset += 4; // for (int i = position; i < size + position; i++) { Bits.SetShort(outWav, offset, samples[i]); offset += 2; } return(outWav); }