public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option) { clsPcmDataInfo pi = pcmDataInfo[v.Value.loopAdr == 0 ? 0 : 1]; try { EncAdpcmA ea = new EncAdpcmA(); buf = v.Value.loopAdr == 0 ? ea.YM_ADPCM_A_Encode(buf, is16bit) : ea.YM_ADPCM_B_Encode(buf, is16bit, true); long size = buf.Length; byte[] newBuf = new byte[size]; Array.Copy(buf, newBuf, size); buf = newBuf; long tSize = size; size = buf.Length; newDic.Add( v.Key , new clsPcm( v.Value.num , v.Value.seqNum, v.Value.chip , v.Value.chipNumber , v.Value.fileName , v.Value.freq , v.Value.vol , pi.totalBufPtr , pi.totalBufPtr + size - 1 , size , v.Value.loopAdr == 0 ? 0 : 1 , is16bit , samplerate) ); pi.totalBufPtr += size; newBuf = new byte[pi.totalBuf.Length + buf.Length]; Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length); Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length); pi.totalBuf = newBuf; Common.SetUInt32bit31( pi.totalBuf , pi.totalHeadrSizeOfDataPtr , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4)) , ChipNumber != 0 ); Common.SetUInt32bit31( pi.totalBuf , pi.totalHeadrSizeOfDataPtr + 4 , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4)) ); pi.use = true; pcmDataEasyA = pi.use ? pcmDataInfo[0].totalBuf : null; pcmDataEasyB = pi.use ? pcmDataInfo[1].totalBuf : null; } catch { pi.use = false; } }
private static long StoreAdpcmYM2608(ref byte[] tbufYm2608AdpcmP, ref byte[] tbufYm2608AdpcmS, ref long pYm2608AdpcmP, ref long pYm2608AdpcmS, ref bool uYm2608AdpcmP, ref bool uYm2608AdpcmS, Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, bool is16bit, ref byte[] buf) { long size; EncAdpcmA ea = new EncAdpcmA(); buf = ea.YM_ADPCM_B_Encode(buf, is16bit, false); size = buf.Length; byte[] newBuf; newBuf = new byte[size]; Array.Copy(buf, newBuf, size); buf = newBuf; long tSize = size; size = buf.Length; newDic.Add( v.Key , new clsPcm( v.Value.num , v.Value.seqNum, v.Value.chip , v.Value.isSecondary , v.Value.fileName , v.Value.freq , v.Value.vol , v.Value.isSecondary ? pYm2608AdpcmS : pYm2608AdpcmP , (v.Value.isSecondary ? pYm2608AdpcmS : pYm2608AdpcmP) + size , size , 1) ); if (!v.Value.isSecondary) { pYm2608AdpcmP += size; newBuf = new byte[tbufYm2608AdpcmP.Length + buf.Length]; Array.Copy(tbufYm2608AdpcmP, newBuf, tbufYm2608AdpcmP.Length); Array.Copy(buf, 0, newBuf, tbufYm2608AdpcmP.Length, buf.Length); tbufYm2608AdpcmP = newBuf; uYm2608AdpcmP = true; } else { pYm2608AdpcmS += size; newBuf = new byte[tbufYm2608AdpcmS.Length + buf.Length]; Array.Copy(tbufYm2608AdpcmS, newBuf, tbufYm2608AdpcmS.Length); Array.Copy(buf, 0, newBuf, tbufYm2608AdpcmS.Length, buf.Length); tbufYm2608AdpcmS = newBuf; uYm2608AdpcmS = true; } return(size); }
public override void StorePcmRawData(clsPcmDatSeq pds, byte[] buf, bool isRaw, bool is16bit, int samplerate, params object[] option) { if (!isRaw) { //Rawファイルは何もしない //Wavファイルはエンコ EncAdpcmA ea = new EncAdpcmA(); buf = ea.YM_ADPCM_B_Encode(buf, is16bit, true); } pcmDataDirect.Add(Common.MakePCMDataBlock((byte)dataType, pds, buf)); }
public override void StorePcmRawData(clsPcmDatSeq pds, byte[] buf, bool isRaw, bool is16bit, int samplerate, params object[] option) { if (!isRaw) { //Rawファイルは何もしない //Wavファイルはエンコ EncAdpcmA ea = new EncAdpcmA(); buf = pds.DatLoopAdr == 0 ? ea.YM_ADPCM_A_Encode(buf, is16bit) : ea.YM_ADPCM_B_Encode(buf, is16bit, true); } if (pds.DatLoopAdr == 0) { pcmDataDirectA.Add(Common.MakePCMDataBlock(dataType, pds, buf)); } else { pcmDataDirectB.Add(Common.MakePCMDataBlock((byte)(dataType + 1), pds, buf)); } }
public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option) { clsPcmDataInfo pi = pcmDataInfo[0]; try { EncAdpcmA ea = new EncAdpcmA(); buf = ea.YM_ADPCM_B_Encode(buf, is16bit, false, true); long size = buf.Length; byte[] newBuf; newBuf = new byte[size]; Array.Copy(buf, newBuf, size); buf = newBuf; int m256kbyte = 0b100_0000_0000_0000_0000;//CASAdr 9bit RASAdr 9bit = 18bit(2+4+4+4+4) //262,144 バイトを超える場合はそれ以降をカット if (size > m256kbyte) { List <byte> n = newBuf.ToList(); n.RemoveRange(m256kbyte, (int)(size - m256kbyte)); newBuf = n.ToArray(); size = m256kbyte; } //空いているBankを探す int freeBank = 0; int freeAdr = 0; do { if (memoryMap.Count < freeBank + 1) { memoryMap.Add(0); freeAdr = 0 + freeBank * m256kbyte; memoryMap[freeBank] += size; break; } if (size < m256kbyte - memoryMap[freeBank]) { freeAdr = (int)(memoryMap[freeBank] + freeBank * m256kbyte); memoryMap[freeBank] += size; break; } freeBank++; } while (true); //パディング(空きが足りない場合はバンクをひとつ進める(0b100_0000_0000_0000_0000)為、空きを全て埋める) while (freeAdr > pi.totalBuf.Length - pi.totalHeaderLength) { int fs = (pi.totalBuf.Length - pi.totalHeaderLength) % m256kbyte; List <byte> n = pi.totalBuf.ToList(); for (int i = 0; i < m256kbyte - fs; i++) { n.Add(0x00); } pi.totalBuf = n.ToArray(); pi.totalBufPtr += m256kbyte - fs; } //long tSize = size; //size = buf.Length; newDic.Add( v.Key , new Tuple <string, clsPcm>("", new clsPcm( v.Value.num , v.Value.seqNum, v.Value.chip , v.Value.chipNumber , v.Value.fileName , v.Value.freq , v.Value.vol , freeAdr , freeAdr + size - 1 , size , -1 , is16bit , samplerate , (v.Value.loopAdr & 3) ) )); if (freeAdr == pi.totalBufPtr) { pi.totalBufPtr += size; newBuf = new byte[pi.totalBuf.Length + buf.Length]; Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length); Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length); pi.totalBuf = newBuf; } else { Array.Copy(buf, 0, pi.totalBuf, freeAdr + pi.totalHeaderLength, buf.Length); } Common.SetUInt32bit31( pi.totalBuf , pi.totalHeadrSizeOfDataPtr , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4)) , ChipNumber != 0 ); Common.SetUInt32bit31( pi.totalBuf , pi.totalHeadrSizeOfDataPtr + 4 , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4)) ); pi.use = true; pcmDataEasy = pi.use ? pi.totalBuf : null; } catch { pi.use = false; newDic[v.Key].Item2.status = enmPCMSTATUS.ERROR; } }