• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef RAW_H_
7 #define RAW_H_
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #include <stddef.h>
14 
15 /* Reads a raw file to a float buffer.
16  * Args:
17  *    filename - The name of the raw file.
18  *    frames - Returns the number of frames read.
19  * Returns:
20  *    The float buffer allocated by malloc(), or NULL if reading fails. The
21  *    first half of the buffer contains left channel data, and the second half
22  *    contains the right channel data.
23  * The raw file is assumed to have two channel 16 bit signed integer samples in
24  * native endian. The raw file can be created by:
25  *    sox input.wav output.raw
26  * The raw file can be played by:
27  *    play -r 44100 -s -b 16 -c 2 test.raw
28  */
29 float *read_raw(const char *filename, size_t *frames);
30 
31 /* Writes a float buffer to a raw file.
32  * Args:
33  *    filename - The name of the raw file.
34  *    buf - The float buffer containing the samples.
35  *    frames - The number of frames in the float buffer.
36  * Returns:
37  *    0 if success. -1 if writing fails.
38  * The format of the float buffer is the same as described in read_raw().
39  */
40 void write_raw(const char *filename, float *buf, size_t frames);
41 
42 #ifdef __cplusplus
43 } /* extern "C" */
44 #endif
45 
46 #endif /* RAW_H_ */
47