Mercurial > audlegacy-plugins
comparison src/filewriter/convert.c @ 2874:11ef2164d90b
re-written format conversion using libSAD;
please test this on Big Endian system
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Thu, 07 Aug 2008 04:16:17 +0300 |
parents | |
children | dcd8d93ba781 |
comparison
equal
deleted
inserted
replaced
2873:31d6c44ffef2 | 2874:11ef2164d90b |
---|---|
1 #include "convert.h" | |
2 | |
3 static SAD_dither_t *sad_state = NULL; | |
4 gpointer convert_output = NULL; | |
5 static gsize convert_output_length = 0; | |
6 static gint nch; | |
7 static AFormat in_fmt; | |
8 static AFormat out_fmt; | |
9 | |
10 gboolean convert_init(AFormat input_fmt, AFormat output_fmt, gint channels) | |
11 { | |
12 gint ret; | |
13 SAD_buffer_format input_sad_fmt; | |
14 SAD_buffer_format output_sad_fmt; | |
15 | |
16 | |
17 input_sad_fmt.sample_format = aud_sadfmt_from_afmt(input_fmt); | |
18 if (input_sad_fmt.sample_format < 0) return FALSE; | |
19 input_sad_fmt.fracbits = FMT_FRACBITS(input_fmt); | |
20 input_sad_fmt.channels = channels; | |
21 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
22 input_sad_fmt.samplerate = 0; | |
23 | |
24 output_sad_fmt.sample_format = aud_sadfmt_from_afmt(output_fmt); | |
25 if (output_sad_fmt.sample_format < 0) return FALSE; | |
26 output_sad_fmt.fracbits = FMT_FRACBITS(output_fmt); | |
27 output_sad_fmt.channels = channels; | |
28 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
29 output_sad_fmt.samplerate = 0; | |
30 | |
31 sad_state = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
32 if (sad_state == NULL) { | |
33 AUDDBG("ditherer init failed\n"); | |
34 return FALSE; | |
35 } | |
36 | |
37 in_fmt = input_fmt; | |
38 out_fmt = output_fmt; | |
39 nch = channels; | |
40 | |
41 SAD_dither_set_dither(sad_state, FALSE); | |
42 return TRUE; | |
43 } | |
44 | |
45 gint convert_process(gpointer ptr, gint length) | |
46 { | |
47 gint frames, len; | |
48 frames = length / nch / FMT_SIZEOF(in_fmt); | |
49 len = frames * nch * FMT_SIZEOF(out_fmt); | |
50 | |
51 if (convert_output == NULL || convert_output_length < len) | |
52 { | |
53 convert_output_length = len; | |
54 convert_output = aud_smart_realloc(convert_output, &convert_output_length); | |
55 } | |
56 | |
57 SAD_dither_process_buffer(sad_state, ptr, convert_output, frames); | |
58 return len; | |
59 } | |
60 | |
61 void convert_free(void) | |
62 { | |
63 if (sad_state != NULL) {SAD_dither_free(sad_state); sad_state = NULL;} | |
64 } |