~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/audio_format.c

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 
 * http://www.musicpd.org
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 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.
18
 
 */
19
 
 
20
 
#include "audio_format.h"
21
 
 
22
 
#include <assert.h>
23
 
#include <stdio.h>
24
 
 
25
 
void
26
 
audio_format_mask_apply(struct audio_format *af,
27
 
                        const struct audio_format *mask)
28
 
{
29
 
        assert(audio_format_valid(af));
30
 
        assert(audio_format_mask_valid(mask));
31
 
 
32
 
        if (mask->sample_rate != 0)
33
 
                af->sample_rate = mask->sample_rate;
34
 
 
35
 
        if (mask->format != SAMPLE_FORMAT_UNDEFINED)
36
 
                af->format = mask->format;
37
 
 
38
 
        if (mask->channels != 0)
39
 
                af->channels = mask->channels;
40
 
 
41
 
        assert(audio_format_valid(af));
42
 
}
43
 
 
44
 
const char *
45
 
sample_format_to_string(enum sample_format format)
46
 
{
47
 
        switch (format) {
48
 
        case SAMPLE_FORMAT_UNDEFINED:
49
 
                return "?";
50
 
 
51
 
        case SAMPLE_FORMAT_S8:
52
 
                return "8";
53
 
 
54
 
        case SAMPLE_FORMAT_S16:
55
 
                return "16";
56
 
 
57
 
        case SAMPLE_FORMAT_S24_P32:
58
 
                return "24";
59
 
 
60
 
        case SAMPLE_FORMAT_S32:
61
 
                return "32";
62
 
 
63
 
        case SAMPLE_FORMAT_FLOAT:
64
 
                return "f";
65
 
 
66
 
        case SAMPLE_FORMAT_DSD:
67
 
                return "dsd";
68
 
        }
69
 
 
70
 
        /* unreachable */
71
 
        assert(false);
72
 
        return "?";
73
 
}
74
 
 
75
 
const char *
76
 
audio_format_to_string(const struct audio_format *af,
77
 
                       struct audio_format_string *s)
78
 
{
79
 
        assert(af != NULL);
80
 
        assert(s != NULL);
81
 
 
82
 
        snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
83
 
                 af->sample_rate, sample_format_to_string(af->format),
84
 
                 af->channels);
85
 
 
86
 
        return s->buffer;
87
 
}