2 * Copyright 1998-1999, Be Incorporated.
3 * Copyright (c) 1999-2000, Eric Moon.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions, and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /*******************************************************************************
37 / Description: Utility functions for handling audio data.
39 *******************************************************************************/
41 #if ! defined( _SoundUtils_h )
44 #include <MediaDefs.h>
46 // Simple helper functions that come in handy when doing
47 // buffer calculations.
48 double us_to_s(bigtime_t usecs
);
49 bigtime_t
s_to_us(double secs
);
51 int bytes_per_frame(const media_raw_audio_format
& format
);
52 int frames_per_buffer(const media_raw_audio_format
& format
);
53 bigtime_t
buffer_duration(const media_raw_audio_format
& format
);
54 bigtime_t
frames_duration(const media_raw_audio_format
& format
,
56 int64
frames_for_duration(const media_raw_audio_format
& format
,
58 int buffers_for_duration(const media_raw_audio_format
& format
,
61 // This is a common hook function interface for
62 // SoundConsumer and SoundProducer to use.
63 typedef void (*SoundProcessFunc
)(void * cookie
,
64 bigtime_t timestamp
, void * data
, size_t datasize
,
65 const media_raw_audio_format
& format
);
66 typedef void (*SoundNotifyFunc
)(void * cookie
,
69 // These are special codes that we use in the Notify
72 B_WILL_START
= 1, // performance_time
73 B_WILL_STOP
, // performance_time immediate
74 B_WILL_SEEK
, // performance_time media_time
75 B_WILL_TIMEWARP
, // real_time performance_time
76 B_CONNECTED
, // name (char*)
78 B_FORMAT_CHANGED
, // media_raw_audio_format*
79 B_NODE_DIES
, // node will die!
81 B_OP_TIMED_OUT
, // timeout that expired -- Consumer only
82 B_PRODUCER_DATA_STATUS
, // status performance_time -- Consumer only
83 B_LATE_NOTICE
// how_much performance_time -- Producer only
86 #endif /* _SoundUtils_h */