2
* Copyright (C) 2003-2011 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"
41
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
42
const gchar *message, G_GNUC_UNUSED gpointer user_data)
44
if (log_domain != NULL)
45
g_printerr("%s: %s\n", log_domain, message);
47
g_printerr("%s\n", message);
51
config_get_string(G_GNUC_UNUSED const char *name, const char *default_value)
56
int main(int argc, char **argv)
59
struct audio_format in_audio_format, out_audio_format;
60
struct pcm_convert_state state;
66
g_printerr("Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n");
70
g_log_set_default_handler(my_log_func, NULL);
72
if (!audio_format_parse(&in_audio_format, argv[1],
74
g_printerr("Failed to parse audio format: %s\n",
79
struct audio_format out_audio_format_mask;
80
if (!audio_format_parse(&out_audio_format_mask, argv[2],
82
g_printerr("Failed to parse audio format: %s\n",
87
out_audio_format = in_audio_format;
88
audio_format_mask_apply(&out_audio_format, &out_audio_format_mask);
90
const size_t in_frame_size = audio_format_frame_size(&in_audio_format);
92
pcm_convert_init(&state);
94
struct fifo_buffer *buffer = fifo_buffer_new(4096);
97
void *p = fifo_buffer_write(buffer, &length);
100
nbytes = read(0, p, length);
104
fifo_buffer_append(buffer, nbytes);
106
const void *src = fifo_buffer_read(buffer, &length);
109
length -= length % in_frame_size;
113
fifo_buffer_consume(buffer, length);
115
output = pcm_convert(&state, &in_audio_format, src, length,
116
&out_audio_format, &length, &error);
117
if (output == NULL) {
118
g_printerr("Failed to convert: %s\n", error->message);
122
G_GNUC_UNUSED ssize_t ignored = write(1, output, length);
125
pcm_convert_deinit(&state);