-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnd_dump.sv
30 lines (24 loc) · 967 Bytes
/
snd_dump.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
`default_nettype none
package snd_dump;
task automatic write_header(input int f, samplerate, channels, bit bit16);
$fwrite(f, ".snd");
$fwrite(f, "%c%c%c%c", 8'h00, 8'h00, 8'h00, 8'd32);
$fwrite(f, "%c%c%c%c", 8'hff, 8'hff, 8'hff, 8'hff);
$fwrite(f, "%c%c%c%c", 8'h00, 8'h00, 8'h00, bit16 ? 8'h03 : 8'h02);
$fwrite(f, "%c", (samplerate >> 24) & 8'hff);
$fwrite(f, "%c", (samplerate >> 16) & 8'hff);
$fwrite(f, "%c", (samplerate >> 8) & 8'hff);
$fwrite(f, "%c", samplerate & 8'hff);
$fwrite(f, "%c%c%c%c", 8'h00, 8'h00, 8'h00, channels & 8'hff);
$fwrite(f, "%c%c%c%c", 8'h00, 8'h00, 8'h00, 8'h00);
$fwrite(f, "%c%c%c%c", 8'h00, 8'h00, 8'h00, 8'h00);
endtask
task automatic write_bit4_as_int8(input int f, bit [3:0] s);
$fwrite(f, "%c", { 1'b0, s, 3'b0 });
endtask
task automatic write_real_as_int16(input int f, real s);
int tmp;
tmp = $rtoi(s * 32767.0);
$fwrite(f, "%c%c", { 1'b0, tmp[14:8] }, tmp[7:0]);
endtask
endpackage