OpenBveApi.Sounds.Sound.Sound C# (CSharp) Method

Sound() public method

Creates a new instance of this class.
Raised when the number of samples per second is not positive. Raised when the number of bits per samples is neither 8 nor 16. Raised when the bytes array or any of its subarrays is a null reference. Raised when the bytes array does not contain any elements. Raised when the bytes' subarrays are of unequal length.
public Sound ( int sampleRate, int bitsPerSample, byte bytes ) : System
sampleRate int The number of samples per second.
bitsPerSample int The number of bits per sample. Allowed values are 8 or 16.
bytes byte The PCM sound data per channel. For 8 bits per sample, samples are unsigned from 0 to 255. For 16 bits per sample, samples are signed from -32768 to 32767 and in little endian byte order.
return System
		public Sound(int sampleRate, int bitsPerSample, byte[][] bytes) {
			if (sampleRate <= 0) {
				throw new ArgumentException("The sample rate must be positive.");
			}
			if (bitsPerSample != 8 & bitsPerSample != 16) {
				throw new ArgumentException("The number of bits per sample is neither 8 nor 16.");
			}
			if (bytes == null) {
				throw new ArgumentNullException("bytes");
			}
			if (bytes.Length == 0) {
				throw new ArgumentException("There must be at least one channel.");
			}
			for (int i = 0; i < bytes.Length; i++) {
				if (bytes[i] == null) {
					throw new ArgumentNullException("The data bytes channel " + i.ToString() + " are a null reference.");
				}
			}
			for (int i = 1; i < bytes.Length; i++) {
				if (bytes[i].Length != bytes[0].Length) {
					throw new ArgumentException("The data bytes of the channels are of unequal length.");
				}
			}
			this.MySampleRate = sampleRate;
			this.MyBitsPerSample = bitsPerSample;
			this.MyBytes = bytes;
		}
		// --- properties ---