source: mainline/uspace/app/dplay/wave.c@ eaa1c28

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since eaa1c28 was af05429, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

dplay, wave: Make data and size parameters voluntary.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup dplay
29 * @{
30 */
31/**
32 * @file PCM playback audio devices
33 */
34
35#include <byteorder.h>
36#include <str.h>
37#include <errno.h>
38
39#include "wave.h"
40
41int wav_parse_header(void *file, void ** data, size_t *data_size,
42 unsigned *sampling_rate, unsigned *sample_size, unsigned *channels,
43 bool *sign, const char **error)
44{
45 if (!file) {
46 if (error)
47 *error = "file not present";
48 return EINVAL;
49 }
50
51 wave_header_t *header = file;
52 if (str_lcmp(header->chunk_id, CHUNK_ID, 4) != 0) {
53 if (error)
54 *error = "invalid chunk id";
55 return EINVAL;
56 }
57
58 if (str_lcmp(header->format, FORMAT_STR, 4) != 0) {
59 if (error)
60 *error = "invalid format string";
61 return EINVAL;
62 }
63
64 if (str_lcmp(header->subchunk1_id, SUBCHUNK1_ID, 4) != 0) {
65 if (error)
66 *error = "invalid subchunk1 id";
67 return EINVAL;
68 }
69
70 if (uint16_t_le2host(header->subchunk1_size) != PCM_SUBCHUNK1_SIZE) {
71 if (error)
72 *error = "invalid subchunk1 size";
73 return EINVAL;
74 }
75
76 if (uint16_t_le2host(header->audio_format) != FORMAT_LINEAR_PCM) {
77 if (error)
78 *error = "unknown format";
79 return ENOTSUP;
80 }
81
82 if (str_lcmp(header->subchunk2_id, SUBCHUNK2_ID, 4) != 0) {
83 if (error)
84 *error = "invalid subchunk2 id";
85 return EINVAL;
86 }
87
88 if (data)
89 *data = header->data;
90 if (data_size)
91 *data_size = uint32_t_le2host(header->subchunk2_size);
92
93 if (sampling_rate)
94 *sampling_rate = uint32_t_le2host(header->sampling_rate);
95 if (sample_size)
96 *sample_size = uint32_t_le2host(header->sample_size);
97 if (channels)
98 *channels = uint16_t_le2host(header->channels);
99 if (sign)
100 *sign = uint32_t_le2host(header->sample_size) == 16
101 ? true : false;
102 if (error)
103 *error = "no error";
104
105 return EOK;
106}
107/**
108 * @}
109 */
Note: See TracBrowser for help on using the repository browser.