2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * This program is a command line interface to MPD's PCM conversion
22 * library (pcm_convert.c).
27 #include "audio_parser.h"
28 #include "audio_format.h"
29 #include "pcm_convert.h"
31 #include "fifo_buffer.h"
40 my_log_func(const gchar
*log_domain
, G_GNUC_UNUSED GLogLevelFlags log_level
,
41 const gchar
*message
, G_GNUC_UNUSED gpointer user_data
)
43 if (log_domain
!= NULL
)
44 g_printerr("%s: %s\n", log_domain
, message
);
46 g_printerr("%s\n", message
);
50 config_get_string(G_GNUC_UNUSED
const char *name
, const char *default_value
)
55 int main(int argc
, char **argv
)
58 struct audio_format in_audio_format
, out_audio_format
;
59 struct pcm_convert_state state
;
65 g_printerr("Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n");
69 g_log_set_default_handler(my_log_func
, NULL
);
71 if (!audio_format_parse(&in_audio_format
, argv
[1],
73 g_printerr("Failed to parse audio format: %s\n",
78 if (!audio_format_parse(&out_audio_format
, argv
[2],
80 g_printerr("Failed to parse audio format: %s\n",
85 const size_t in_frame_size
= audio_format_frame_size(&in_audio_format
);
87 pcm_convert_init(&state
);
89 struct fifo_buffer
*buffer
= fifo_buffer_new(4096);
92 void *p
= fifo_buffer_write(buffer
, &length
);
95 nbytes
= read(0, p
, length
);
99 fifo_buffer_append(buffer
, nbytes
);
101 const void *src
= fifo_buffer_read(buffer
, &length
);
104 length
-= length
% in_frame_size
;
108 fifo_buffer_consume(buffer
, length
);
110 output
= pcm_convert(&state
, &in_audio_format
, src
, length
,
111 &out_audio_format
, &length
, &error
);
112 if (output
== NULL
) {
113 g_printerr("Failed to convert: %s\n", error
->message
);
117 write(1, output
, length
);
120 pcm_convert_deinit(&state
);