]> lisas.de Git - terminatorX.git/blob - src/wav_write.c
Fix preferences for UI colors.
[terminatorX.git] / src / wav_write.c
1 /*
2     wav_write.c - taken from wav-tools 1.1
3     Copyright (C) by Colin Ligertwood
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <stdio.h>
20 #include <fcntl.h>
21 #include <signal.h>
22
23 #ifndef WIN32
24 #include <sys/soundcard.h>
25 #include <unistd.h>
26 #endif
27
28 #include "wav_file.h"
29
30 #include "tX_endian.h"
31 #include <string.h>
32
33 void init_head(wav_sig *info){
34         int32_t tmp32;
35         
36         strcpy(info->head, "RIFF    WAVEfmt                     data    ");
37         
38         tmp32=(info->sofar + 32);       
39 #ifdef BIG_ENDIAN_MACHINE       
40         swap32(&tmp32);
41 #endif
42         *(int32_t  *)&info->head[4]  = tmp32;
43         
44         
45         tmp32=16;
46 #ifdef BIG_ENDIAN_MACHINE       
47         swap32(&tmp32);
48 #endif
49         *(int32_t *)&info->head[16] = tmp32;
50         
51 /*      tmp16=1;
52 #ifdef BIG_ENDIAN_MACHINE       
53         swap16(&tmp16);
54 #endif
55         *(int16_t *)&info->head[20] = tmp16;
56 */
57         info->head[20] = 1;
58         info->head[21] = 0;
59         
60         info->head[22] = info->chans;
61         info->head[23] = 0;     
62         
63         tmp32=info->srate;
64 #ifdef BIG_ENDIAN_MACHINE       
65         swap32(&tmp32);
66 #endif
67         *(int32_t  *)&info->head[24] = tmp32;
68         
69         tmp32=info->bps;
70 #ifdef BIG_ENDIAN_MACHINE       
71         swap32(&tmp32);
72 #endif
73         *(int32_t  *)&info->head[28] = tmp32;
74         
75         info->head[32] = info->blkalign;
76         info->head[33] = 0;
77                 
78         info->head[34] = info->depth;
79         info->head[35] = 0;
80         
81         tmp32=info->sofar;
82 #ifdef BIG_ENDIAN_MACHINE       
83         swap32(&tmp32);
84 #endif
85         *(int32_t  *)&info->head[40] = tmp32;
86 }
87
88 FILE* open_wav_rec(wav_sig *info){
89         info->handle = fopen(info->name, "w");
90         if (!info->handle) return NULL;
91         init_head(info);
92         fwrite(info->head, 44, 1, info->handle);
93         return(info->handle);
94 }
95
96 int rewrite_head(wav_sig *info){
97         rewind(info->handle);
98         init_head(info);
99         fwrite(info->head, 44, 1, info->handle);
100
101         return(0);
102 }