Memory Copy-marshal.copy:
Copy the current incoming data
byte[] pcm_src = new Byte[len];
Copy data to binary array
marshal.copy (PCM, PCM_SRC, 0, Len);
Array replication-array.copy:
Copy the current incoming data
byte[] pcm_src = new Byte[len];
Copy data to binary array
marshal.copy (PCM, PCM_SRC, 0, Len);
Copy the new incoming data to the new array structure
array.copy (pcm_src, 0, Pcm_dest, Bts_left. Length, Len)
Test Example:
Sample number ushort samples = 320;
Last remaining bytes byte[] bts_left;
Class AA {public byte[] PCM;
public int len;
Private list<aa> data = new list<aa> (); public void Playaudio (IntPtr pcm, int len) {lock (this) {int Samples_len
= samples * 2;
if (len = = Samples_len) {byte[] BTS = new Byte[len];
Marshal.Copy (PCM, BTS, 0, Len); Data.
ADD (new AA {len = len, PCM = BTS
}); else//Here resolve the size of the partition to replicate data when the sample number is 1024 {var len_temp = BT S_left ==null? Len:len + bts_left.
Length;
byte[] pcm_dest = new Byte[len_temp]; byte[] BTS = new Byte[samples_Len];
Copy data if (Bts_left!= null) {//Copy length not enough data Array.copy (bts_left,0, pcm_dest, 0, Bts_left.
Length);
Copy the current incoming data byte[] pcm_src = new Byte[len];
Copy data to binary array marshal.copy (PCM, PCM_SRC, 0, Len); Copy the new incoming data to the new array structure array.copy (PCM_SRC, 0, Pcm_dest, Bts_left.
Length, Len);
Bts_left = null;
else {marshal.copy (PCM, pcm_dest, 0, len_temp);
//Get playback data int index = 0,count= Len_temp/samples_len;
int startindex=0; Console.WriteLine (">>>total:" + len_temp + ", Times:" + Count + ", left:" + len_temp% SamplEs_len); while (index< count) {//Copy the data array.copy that satisfies the length (pcm_
Dest, StartIndex, BTS, 0, Samples_len); Add data.
ADD (new AA {len = Samples_len, PCM = BTS
});
index++;
Calculates the next start position StartIndex = index * SAMPLES_LEN;
}///staging length not enough data var Left_len = len_temp% Samples_len;
if (Left_len > 0) {bts_left = new Byte[left_len];
Replication is not long enough for data array.copy (Pcm_dest, StartIndex, Bts_left, 0, Left_len); }}//sdl.
Sdl_delay (10); }