1 /*
2  * libPCM by László Szerémi.
3  * Copyright under Boost License.
4  */
5 
6 module libPCM.types;
7 
8 import core.stdc.stdlib;
9 
10 import libPCM.common;
11 
12 /**
13  * Stores wave data
14  */
15 public class WaveData{
16 	size_t length;
17 	CodecType codecType;
18 	float sampleRate;
19 	void[] data;
20 	this(size_t length, float sampleRate, CodecType codecType, void[] data){
21 		this.length = length;
22 		this.sampleRate = sampleRate;
23 		this.codecType = codecType;
24 		this.data = data;
25 	}
26 	this(size_t length, float sampleRate, CodecType codecType, size_t dataLength){
27 		this.length = length;
28 		this.sampleRate = sampleRate;
29 		this.codecType = codecType;
30 		this.data.length = dataLength;
31 	}
32 }
33 /**
34  * Stores *.PCM file header data
35  */
36 
37 public struct PCMHeader{
38 	public:
39 		uint length;
40 		uint length_u;
41 		CodecType codecType;
42 		ubyte numOfChannels;
43 		ubyte aux;				///Stores additional data if needed
44 		float sampleRate;
45 		ubyte name_l;			///Actual length = value * 4
46 		ubyte author_l;			///Actual length = value * 4
47 		ubyte copyright_l;		///Actual length = value * 4
48 		ubyte comment_l;		///Actual length = value * 4
49 	//export char* name, author, copyright, comment;
50 	//export void* startOfData;		///Data Layout in file: ch1pkg, ch2pkg, ch1pkg, ch2pkg... Null if individual streams used
51 	//export WaveData** waveData;	///Used for individual streams.
52 	public this(int length, int length_u, CodecType codecType, ubyte numOfChannels, ubyte aux, float sampleRate){
53 		this.length = length;
54 		this.length_u = length_u;
55 		this.codecType = codecType;
56 		this.numOfChannels = numOfChannels;
57 		this.aux = aux;
58 		this.sampleRate = sampleRate;
59 	}
60 }
61 public struct PCMFile{
62 	public:
63 		PCMHeader header;
64 		char[] name, author, copyright, comment;
65 		WaveData[] waveData;
66 		void[] startOfData;
67 	public @nogc:
68 		void loadTagData(void* tagData){
69 			
70 		}
71 }
72 /**
73  * *.wav file header
74  */
75 public struct WavHeader{
76 	public:
77 		char[4] chunkID;
78 		uint chunkSize;
79 		char[4] format;
80 		char[4] subchunk1ID;
81 		uint subchunk1Size;
82 		ushort audioFormat;
83 		ushort numOfChannels;
84 		uint sampleRate;
85 		uint byteRate;
86 		ushort blockAlign;
87 		ushort bitsPerSample;
88 		char[4] subchunk2ID;
89 		uint subchunk2Size;
90 	public @nogc:
91 		this(uint subchunk2Size, ushort audioFormat, ushort numOfChannels, ushort blockAlign, ushort bitsPerSample, uint sampleRate, uint byteRate){
92 			chunkID = "RIFF";
93 			format = "WAVE";
94 			subchunk1ID = "fmt ";
95 			subchunk2ID = "data";
96 			subchunk1Size = 16;
97 			this.subchunk2Size = subchunk2Size;
98 			this.audioFormat = audioFormat;
99 			this.numOfChannels = numOfChannels;
100 			this.blockAlign = blockAlign;
101 			this.bitsPerSample = bitsPerSample;
102 			this.sampleRate = sampleRate;
103 			this.byteRate = byteRate;
104 		}
105 }
106 /**	
107  * *.wav file container
108  */
109 public struct WavFile{
110 	public: 
111 		WavHeader header;
112 		WaveData[] waveData;
113 		void[] startOfData;
114 	
115 }