internal virtual byte[] GetData() { byte[] array = new byte[8]; LittleEndianHelper.WriteIntU(m_escherHeader, array, 0); LittleEndianHelper.WriteIntU(m_cbLength, array, 4); return(array); }
private static void ToSamplesFromPcm(byte[] input, int bitsPerSample, int channelCount, float[] output, int channel, bool interleaved) { int x, xc, i, ic; if (interleaved) { x = channel; xc = channelCount; } else { x = 0; xc = 1; } i = channel * bitsPerSample / 8; ic = channelCount * bitsPerSample / 8; switch (bitsPerSample) { case 8: while (x < output.Length) { output[x] = ((input[i] / 255f) * 2f) - 1f; x += xc; i += ic; } break; case 16: while (x < output.Length) { output[x] = LittleEndianHelper.ReadInt16(input, i) / 32768f; x += xc; i += ic; } break; case 24: while (x < output.Length) { output[x] = LittleEndianHelper.ReadInt24(input, i) / 8388608f; x += xc; i += ic; } break; case 32: while (x < output.Length) { output[x] = LittleEndianHelper.ReadInt32(input, i) / 2147483648f; x += xc; i += ic; } break; default: throw new Exception("Invalid sample format: PCM " + bitsPerSample + " bit."); } }
//returns raw audio data in little endian form private static void ToPcmFromSamples(float[] input, int bitsPerSample, int channels, byte[] output, int index) { switch (bitsPerSample) { case 8: for (int x = 0; x < input.Length; x++) { output[index] = (byte)((input[x] + 1f) / 2f * 255f); index += channels; } break; case 16: for (int x = 0; x < input.Length; x++) { LittleEndianHelper.WriteInt16((short)SynthHelper.Clamp(input[x] * 32768f, -32768f, 32767f), output, index); index += channels * 2; } break; case 24: for (int x = 0; x < input.Length; x++) { LittleEndianHelper.WriteInt24((int)SynthHelper.Clamp(input[x] * 8388608f, -8388608f, 8388607f), output, index); index += channels * 3; } break; case 32: for (int x = 0; x < input.Length; x++) { LittleEndianHelper.WriteInt32((int)SynthHelper.Clamp(input[x] * 2147483648f, -2147483648f, 2147483647f), output, index); index += channels * 4; } break; default: throw new ArgumentException("Invalid bitspersample value. Supported values are 8, 16, 24, and 32."); } }