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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
*** cdstatus-0.96.05/src/cdstatus.c.orig 2005-11-26 16:23:27.000000000 +0100
--- cdstatus-0.96.05/src/cdstatus.c 2005-11-26 19:06:57.000000000 +0100
***************
*** 436,441 ****
--- 436,501 ----
return 0;
}
+ /* following code copied from
+ http://www.gamedev.net/reference/articles/article2091.asp
+ it has been slightly modified as we did not have a reason to output
+ big endian or float
+ */
+ static short ShortSwap( short s )
+ {
+ unsigned char b1, b2;
+
+ b1 = s & 255;
+ b2 = (s >> 8) & 255;
+
+ return (b1 << 8) + b2;
+ }
+
+ static short ShortNoSwap( short s )
+ {
+ return s;
+ }
+
+ static int LongSwap (int i)
+ {
+ unsigned char b1, b2, b3, b4;
+
+ b1 = i & 255;
+ b2 = ( i >> 8 ) & 255;
+ b3 = ( i>>16 ) & 255;
+ b4 = ( i>>24 ) & 255;
+
+ return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4;
+ }
+
+ static int LongNoSwap( int i )
+ {
+ return i;
+ }
+
+ static short (*LittleShort) ( short s );
+ static int (*LittleLong) ( int i );
+
+ static void InitEndian( void )
+ {
+ char SwapTest[2] = { 1, 0 };
+
+ if( *(short *) SwapTest == 1 )
+ {
+ // little endian
+ //set func pointers to correct funcs
+ LittleShort = ShortNoSwap;
+ LittleLong = LongNoSwap;
+ }
+ else
+ {
+ // big endian
+ LittleShort = ShortSwap;
+ LittleLong = LongSwap;
+ }
+ }
+ /* end of copied code */
+
static void writeWavHeader(unsigned int readframes, FILE * audio_out)
{
long int chunksize;
***************
*** 456,478 ****
wavHeader wHeader;
/* "RIFF" */
! wHeader.RIFF_header = 0x46464952;
chunksize = readframes * CD_FRAMESIZE_RAW;
! wHeader.total_size = (int32_t)(chunksize + sizeof(wavHeader));
/* "WAVEfmt " */
! wHeader.WAVE = 0x45564157;
! wHeader.fmt = 0x20746D66;
! wHeader.subchunk_size = 16;
! wHeader.audio_format = 1;
! wHeader.number_channels = 2;
! wHeader.sampling_rate = 44100;
! wHeader.byte_rate = 176400;
! wHeader.block_align = 4;
! wHeader.bits_per_sample = 16;
if(fwrite((const void *) &wHeader, sizeof(wavHeader), (size_t) 1, audio_out)!=1)
{
--- 516,539 ----
wavHeader wHeader;
+ InitEndian();
/* "RIFF" */
! wHeader.RIFF_header = LittleLong(0x46464952);
chunksize = readframes * CD_FRAMESIZE_RAW;
! wHeader.total_size = LittleLong((int32_t)(chunksize + sizeof(wavHeader)));
/* "WAVEfmt " */
! wHeader.WAVE = LittleLong(0x45564157);
! wHeader.fmt = LittleLong(0x20746D66);
! wHeader.subchunk_size = LittleLong(16);
! wHeader.audio_format = LittleShort(1);
! wHeader.number_channels = LittleShort(2);
! wHeader.sampling_rate = LittleLong(44100);
! wHeader.byte_rate = LittleLong(176400);
! wHeader.block_align = LittleShort(4);
! wHeader.bits_per_sample = LittleShort(16);
if(fwrite((const void *) &wHeader, sizeof(wavHeader), (size_t) 1, audio_out)!=1)
{
***************
*** 492,497 ****
--- 553,559 ----
}
exit(EXIT_FAILURE);
}
+ chunksize = LittleLong(chunksize);
if(fwrite((const void *) &chunksize, sizeof(long int), (size_t) 1, audio_out)!=1)
{
perror("Error writing wav file chunksize header");
|