1 module pxtone.woiceptv; 2 // '12/03/03 3 4 import pxtone.pxtn; 5 6 import pxtone.descriptor; 7 import pxtone.error; 8 import pxtone.pulse.noise; 9 import pxtone.woice; 10 11 __gshared int _version = 20060111; // support no-envelope 12 13 void _Write_Wave(ref pxtnDescriptor p_doc, const(pxtnVOICEUNIT)* p_vc, ref int p_total) @system { 14 int num, i, size; 15 byte sc; 16 ubyte uc; 17 18 p_doc.v_w_asfile(p_vc.type, p_total); 19 20 switch (p_vc.type) { 21 // Coodinate (3) 22 case pxtnVOICETYPE.Coodinate: 23 p_doc.v_w_asfile(p_vc.wave.num, p_total); 24 p_doc.v_w_asfile(p_vc.wave.reso, p_total); 25 num = p_vc.wave.num; 26 for (i = 0; i < num; i++) { 27 uc = cast(byte) p_vc.wave.points[i].x; 28 p_doc.w_asfile(uc); 29 p_total++; 30 sc = cast(byte) p_vc.wave.points[i].y; 31 p_doc.w_asfile(sc); 32 p_total++; 33 } 34 break; 35 36 // Overtone (2) 37 case pxtnVOICETYPE.Overtone: 38 39 p_doc.v_w_asfile(p_vc.wave.num, p_total); 40 num = p_vc.wave.num; 41 for (i = 0; i < num; i++) { 42 p_doc.v_w_asfile(p_vc.wave.points[i].x, p_total); 43 p_doc.v_w_asfile(p_vc.wave.points[i].y, p_total); 44 } 45 break; 46 47 // sampling (7) 48 case pxtnVOICETYPE.Sampling: 49 p_doc.v_w_asfile(p_vc.p_pcm.get_ch(), p_total); 50 p_doc.v_w_asfile(p_vc.p_pcm.get_bps(), p_total); 51 p_doc.v_w_asfile(p_vc.p_pcm.get_sps(), p_total); 52 p_doc.v_w_asfile(p_vc.p_pcm.get_smp_head(), p_total); 53 p_doc.v_w_asfile(p_vc.p_pcm.get_smp_body(), p_total); 54 p_doc.v_w_asfile(p_vc.p_pcm.get_smp_tail(), p_total); 55 56 size = p_vc.p_pcm.get_buf_size(); 57 58 p_doc.w_asfile(p_vc.p_pcm.get_p_buf()); 59 p_total += size; 60 break; 61 62 case pxtnVOICETYPE.OggVorbis: 63 throw new PxtoneException("Ogg Vorbis is not supported here"); 64 default: 65 break; 66 } 67 } 68 69 void _Write_Envelope(ref pxtnDescriptor p_doc, const(pxtnVOICEUNIT)* p_vc, ref int p_total) @system { 70 int num, i; 71 72 // envelope. (5) 73 p_doc.v_w_asfile(p_vc.envelope.fps, p_total); 74 p_doc.v_w_asfile(p_vc.envelope.head_num, p_total); 75 p_doc.v_w_asfile(p_vc.envelope.body_num, p_total); 76 p_doc.v_w_asfile(p_vc.envelope.tail_num, p_total); 77 78 num = p_vc.envelope.head_num + p_vc.envelope.body_num + p_vc.envelope.tail_num; 79 for (i = 0; i < num; i++) { 80 p_doc.v_w_asfile(p_vc.envelope.points[i].x, p_total); 81 p_doc.v_w_asfile(p_vc.envelope.points[i].y, p_total); 82 } 83 } 84 85 void _Read_Wave(ref pxtnDescriptor p_doc, pxtnVOICEUNIT* p_vc) @system { 86 int i, num; 87 byte sc; 88 ubyte uc; 89 90 p_doc.v_r(*cast(int*)&p_vc.type); 91 92 switch (p_vc.type) { 93 // coodinate (3) 94 case pxtnVOICETYPE.Coodinate: 95 p_doc.v_r(p_vc.wave.num); 96 p_doc.v_r(p_vc.wave.reso); 97 num = p_vc.wave.num; 98 p_vc.wave.points = new pxtnPOINT[](num); 99 for (i = 0; i < num; i++) { 100 p_doc.r(uc); 101 p_vc.wave.points[i].x = uc; 102 p_doc.r(sc); 103 p_vc.wave.points[i].y = sc; 104 } 105 num = p_vc.wave.num; 106 break; 107 // overtone (2) 108 case pxtnVOICETYPE.Overtone: 109 110 p_doc.v_r(p_vc.wave.num); 111 num = p_vc.wave.num; 112 p_vc.wave.points = new pxtnPOINT[](num); 113 for (i = 0; i < num; i++) { 114 p_doc.v_r(p_vc.wave.points[i].x); 115 p_doc.v_r(p_vc.wave.points[i].y); 116 } 117 break; 118 119 // p_vc.sampring. (7) 120 case pxtnVOICETYPE.Sampling: 121 throw new PxtoneException("fmt unknown"); // un-support 122 123 //p_doc.v_r(p_vc.pcm.ch); 124 //p_doc.v_r(p_vc.pcm.bps); 125 //p_doc.v_r(p_vc.pcm.sps); 126 //p_doc.v_r(p_vc.pcm.smp_head); 127 //p_doc.v_r(p_vc.pcm.smp_body); 128 //p_doc.v_r(p_vc.pcm.smp_tail); 129 //size = ( p_vc.pcm.smp_head + p_vc.pcm.smp_body + p_vc.pcm.smp_tail ) * p_vc.pcm.ch * p_vc.pcm.bps / 8; 130 //if( !_malloc_zero( (void **)&p_vc.pcm.p_smp, size ) ) goto End; 131 //if( !p_doc.r( p_vc.pcm.p_smp, 1, size ) ) goto End; 132 //break; 133 134 default: 135 throw new PxtoneException("PTV not supported"); // un-support 136 } 137 } 138 139 void _Read_Envelope(ref pxtnDescriptor p_doc, pxtnVOICEUNIT* p_vc) @system { 140 int num, i; 141 142 scope(failure) { 143 p_vc.envelope.points = null; 144 } 145 //p_vc.envelope. (5) 146 p_doc.v_r(p_vc.envelope.fps); 147 p_doc.v_r(p_vc.envelope.head_num); 148 p_doc.v_r(p_vc.envelope.body_num); 149 p_doc.v_r(p_vc.envelope.tail_num); 150 if (p_vc.envelope.body_num) { 151 throw new PxtoneException("fmt unknown"); 152 } 153 if (p_vc.envelope.tail_num != 1) { 154 throw new PxtoneException("fmt unknown"); 155 } 156 157 num = p_vc.envelope.head_num + p_vc.envelope.body_num + p_vc.envelope.tail_num; 158 p_vc.envelope.points = new pxtnPOINT[](num); 159 for (i = 0; i < num; i++) { 160 p_doc.v_r(p_vc.envelope.points[i].x); 161 p_doc.v_r(p_vc.envelope.points[i].y); 162 } 163 }