public byte[] Encode(PCM16Audio lwav, string original_filename_no_ext) { if (lwav.OriginalPath != null) { switch (Path.GetExtension(lwav.OriginalPath).ToLowerInvariant()) { case ".brstm": return(File.ReadAllBytes(lwav.OriginalPath)); case ".bcstm": return(CSTMConverter.ToRSTM(File.ReadAllBytes(lwav.OriginalPath))); case ".bfstm": return(FSTMConverter.ToRSTM(File.ReadAllBytes(lwav.OriginalPath))); } } using (var pw = new ProgressWindow(null, "BrawlLib Audio Encoder", $"Encoding {original_filename_no_ext}", true)) using (FileMap rstm = RSTMConverter.Encode(new PCM16AudioStream(lwav), pw, WaveEncoding.ADPCM)) { if (pw.Cancelled) { throw new AudioExporterException("RSTM export cancelled"); } byte[] data = new byte[rstm.Length]; Marshal.Copy(rstm.Address, data, 0, rstm.Length); return(data); } }
public override bool OnInitialize() { if (_name == null && _origPath != null) { _name = Path.GetFileNameWithoutExtension(_origPath); } base.OnInitialize(); if (Header->_header._tag == CSTMHeader.Tag) { ShowADPCMConversionWarning(); byte[] brstm_temp = CSTMConverter.ToRSTM((CSTMHeader *)Header); fixed(byte *ptr = brstm_temp) { ReplaceRaw(ptr, brstm_temp.Length); return(false); } } if (Header->_header._tag == FSTMHeader.Tag) { ShowADPCMConversionWarning(); byte[] brstm_temp = FSTMConverter.ToRSTM((FSTMHeader *)Header); fixed(byte *ptr = brstm_temp) { ReplaceRaw(ptr, brstm_temp.Length); return(false); } } StrmDataInfo *part1 = Header->HEADData->Part1; _encoding = part1->_format._encoding; _channels = part1->_format._channels; _looped = part1->_format._looped != 0; _sampleRate = part1->_sampleRate; _loopStart = part1->_loopStartSample; _numSamples = part1->_numSamples; _dataOffset = part1->_dataOffset; _numBlocks = part1->_numBlocks; _blockSize = part1->_blockSize; _bps = part1->_bitsPerSample; int offset = Header->DATAData->Data - Header; if (offset < WorkingUncompressed.Length) { _audioSource = new DataSource(Header->DATAData->Data, WorkingUncompressed.Length - offset); SetSizeInternal(offset); } return(false); }