File: normalize.c

package info (click to toggle)
xcfa 5.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,300 kB
  • sloc: ansic: 47,148; sh: 4,380; makefile: 136; sed: 16
file content (241 lines) | stat: -rw-r--r-- 8,442 bytes parent folder | download | duplicates (5)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 *  file      : src/normalize.c
 *  project   : xcfa_cli
 *  copyright : (C) 2014 by BULIN Claude
 *
 *  This file is part of xcfa_cli project
 *
 *  xcfa_cli is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; version 3.
 *
 *  xcfa_cli is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA
 */


#ifdef HAVE_CONFIG_H
	#include "../config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
// #include <fcntl.h>	// PROCESSUS NON-BLOQUANT

#include "global.h"
#include "conv.h"


// p_type_infosong_file_is = FILE_IS_MP3 | FILE_IS_WAV | FILE_IS_OGG
//
CList *normalize_get_list( TYPE_FILE_IS p_type_infosong_file_is )
{
	CList	*list = NULL;
	INFO	*Info = NULL;
	CList	*list_normalize = NULL;

	if( NULL != ( list = C_list_first( Detail.ListFile ))) {
		while( list ) {
			if( NULL != (Info = (INFO *)list->data) ) {
				if( Info->type_infosong_file_is == p_type_infosong_file_is )
					list_normalize = C_list_append( list_normalize, Info->path_is_normalize ? Info->path_is_normalize : Info->path_name_file );
			}
			list = C_list_next( list );
		}
	}
	return( list_normalize );
}
CList *normalize_remove_glist( CList *p_list_normalize )
{
	CList *list = NULL;

	if( p_list_normalize != NULL ) {
		list = C_list_first( p_list_normalize );
		while( list ) {
			list->data = NULL;
			list = C_list_next( list );
		}
		C_list_free( p_list_normalize );
		p_list_normalize = NULL;
	}
	return( (CList *)NULL );
}

/*
! Normalize: static modification for next files: MP3, WAV, OGG
! See an excellent article by @Dzef on standardization: http://ubunteros.tuxfamily.org/spip.php?article159
!
! --peak                    Action on a single file.
!                           Increase the overall level of the signal so as to bring the level to 0 dBFS peak without changing dynamics.
! --peak_album              Action on a group of files.
!                           If the maximum level of one or more files is already at 0 dBFS, the level of all the selected files remain unchanged
!                           after normalization. That is why this mode can be safely used almost systematically.
! --mix_rms_album <dBFS>    Action on a group of files.
!                           The selecting a value for a file modifies the other files in the group.
! --fix_rms <dBFS>          Action on a single file.
!                           The selecting a value for a file.
*/
void normalize_set( C_BOOL p_bool_peak, C_BOOL p_bool_peak_album, int p_mix_rms_album, int p_fix_rms )
{
	int		pos;
	char	**PtrTabArgs = NULL;
	CList	*list_normalize = NULL;
	CList	*list = NULL;
	INFO	*Info = NULL;
	int	tab_file [ 3 ] = { FILE_IS_MP3, FILE_IS_WAV, FILE_IS_OGG };
	int	cpt;

	if( TRUE == p_bool_peak ) {
		if( NULL != ( list = C_list_first( Detail.ListFile ))) {
			while( list ) {
				if( NULL != (Info = (INFO *)list->data) ) {
					if( Info->type_infosong_file_is == FILE_IS_MP3 ||
						Info->type_infosong_file_is == FILE_IS_WAV ||
						Info->type_infosong_file_is == FILE_IS_OGG ) {

						PtrTabArgs = conv_AllocTabArgs( &pos );

						if( Info->type_infosong_file_is == FILE_IS_MP3 )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize-mp3" );
						else if( Info->type_infosong_file_is == FILE_IS_WAV )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize" );
						else if( Info->type_infosong_file_is == FILE_IS_OGG )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize-ogg" );

						PtrTabArgs [ pos++ ] = C_strdup( "--peak" );
						PtrTabArgs [ pos++ ] = C_strdup( Info->path_is_normalize ? Info->path_is_normalize : Info->path_name_file );
						PtrTabArgs [ pos++ ] = C_strdup( "--" );
						PtrTabArgs [ pos++ ] = NULL;
						conv_to_convert( PtrTabArgs, NORMALISE_EXEC, "NORMALISE_EXEC  peak" );
						PtrTabArgs = conv_RemoveTab( PtrTabArgs );
					}
				}
				list = C_list_next( list );
			}
		}
	}
	else if( TRUE == p_bool_peak_album ) {
		for( cpt = 0; cpt < 3; cpt ++ ) {
			if( NULL != (list_normalize = normalize_get_list( tab_file [ cpt ] ))) {

				PtrTabArgs = conv_AllocTabArgs( &pos );

				if( FILE_IS_MP3 == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-mp3" );
				else if( FILE_IS_WAV == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize" );
				else if( FILE_IS_OGG == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-ogg" );

				PtrTabArgs [ pos++ ] = C_strdup( "-n" );
				list = C_list_first( list_normalize );
				while( list ) {
					if( NULL != list->data )
						PtrTabArgs [ pos++ ] = C_strdup( list->data );
					list = C_list_next( list );
				}
				PtrTabArgs [ pos++ ] = NULL;
				// GET LEVEL to get value 'conv.value_PEAK_RMS_GROUP_ARGS'
				conv_to_convert( PtrTabArgs, NORMALISE_GET_LEVEL, "NORMALISE_GET_LEVEL" );
				PtrTabArgs = conv_RemoveTab( PtrTabArgs );

				// EXEC

				PtrTabArgs = conv_AllocTabArgs( &pos );

				if( FILE_IS_MP3 == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-mp3" );
				else if( FILE_IS_WAV == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize" );
				else if( FILE_IS_OGG == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-ogg" );

				PtrTabArgs [ pos++ ] = C_strdup_printf( "%d,0000dB", (int)conv.value_PEAK_RMS_GROUP_ARGS );
				list = C_list_first( list_normalize );
				while( list ) {
					if( NULL != list->data )
						PtrTabArgs [ pos++ ] = C_strdup( list->data );
					list = C_list_next( list );
				}
				PtrTabArgs [ pos++ ] = NULL;
				conv_to_convert( PtrTabArgs, NORMALISE_EXEC, "NORMALISE_EXEC peak_albu" );
				PtrTabArgs = conv_RemoveTab( PtrTabArgs );
				list_normalize = normalize_remove_glist( list_normalize );
			}
		}
	}
	else if( p_mix_rms_album < 0 ) {
		for( cpt = 0; cpt < 3; cpt ++ ) {
			if( NULL != (list_normalize = normalize_get_list( tab_file [ cpt ] ))) {

				PtrTabArgs = conv_AllocTabArgs( &pos );

				if( FILE_IS_MP3 == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-mp3" );
				else if( FILE_IS_WAV == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize" );
				else if( FILE_IS_OGG == tab_file [ cpt ] )
					PtrTabArgs [ pos++ ] = C_strdup( "normalize-ogg" );

				PtrTabArgs [ pos++ ] = C_strdup( "-a" );
				PtrTabArgs [ pos++ ] = C_strdup_printf( "%d,0000dB", p_mix_rms_album );
				PtrTabArgs [ pos++ ] = C_strdup( "--batch" );
				list = C_list_first( list_normalize );
				while( list ) {
					if( NULL != list->data )
						PtrTabArgs [ pos++ ] = C_strdup( list->data );
					list = C_list_next( list );
				}
				PtrTabArgs [ pos++ ] = NULL;
				conv_to_convert( PtrTabArgs, NORMALISE_EXEC, "NORMALISE_EXEC mix_rms_album" );
				PtrTabArgs = conv_RemoveTab( PtrTabArgs );
				list_normalize = normalize_remove_glist( list_normalize );
			}
		}
	}
	else if( p_fix_rms < 0 ) {
		if( NULL != ( list = C_list_first( Detail.ListFile ))) {
			while( list ) {
				if( NULL != (Info = (INFO *)list->data) ) {
					if( Info->type_infosong_file_is == FILE_IS_MP3 ||
						Info->type_infosong_file_is == FILE_IS_WAV ||
						Info->type_infosong_file_is == FILE_IS_OGG ) {

						PtrTabArgs = conv_AllocTabArgs( &pos );

						if( Info->type_infosong_file_is == FILE_IS_MP3 )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize-mp3" );
						else if( Info->type_infosong_file_is == FILE_IS_WAV )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize" );
						else if( Info->type_infosong_file_is == FILE_IS_OGG )
							PtrTabArgs [ pos++ ] = C_strdup( "normalize-ogg" );

						PtrTabArgs [ pos++ ] = C_strdup( "-a" );
						PtrTabArgs [ pos++ ] = C_strdup_printf( "%d,0000dB", p_fix_rms );
						PtrTabArgs [ pos++ ] = C_strdup( Info->path_is_normalize ? Info->path_is_normalize : Info->path_name_file );
						PtrTabArgs [ pos++ ] = NULL;
						conv_to_convert( PtrTabArgs, NORMALISE_EXEC, "NORMALISE_EXEC fix_rms" );
						PtrTabArgs = conv_RemoveTab( PtrTabArgs );
					}
				}
				list = C_list_next( list );
			}
		}
	}
}