1/*
2 * Copyright 1998-1999, Be Incorporated.
3 * Copyright (c) 1999-2000, Eric Moon.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions, and the following disclaimer.
12 *
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.
16 *
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.
19 *
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.
30 */
31
32
33/*******************************************************************************
34/
35/	File:			SoundUtils.h
36/
37/   Description:	Utility functions for handling audio data.
38/
39*******************************************************************************/
40
41#if ! defined( _SoundUtils_h )
42#define _SoundUtils_h
43
44#include <MediaDefs.h>
45
46//	Simple helper functions that come in handy when doing
47//	buffer calculations.
48double us_to_s(bigtime_t usecs);
49bigtime_t s_to_us(double secs);
50
51int bytes_per_frame(const media_raw_audio_format & format);
52int frames_per_buffer(const media_raw_audio_format & format);
53bigtime_t buffer_duration(const media_raw_audio_format & format);
54bigtime_t frames_duration(const media_raw_audio_format & format,
55	int64 num_frames);
56int64 frames_for_duration(const media_raw_audio_format & format,
57	bigtime_t duration);
58int buffers_for_duration(const media_raw_audio_format & format,
59	bigtime_t duration);
60
61//	This is a common hook function interface for
62//	SoundConsumer and SoundProducer to use.
63typedef void (*SoundProcessFunc)(void * cookie,
64	bigtime_t timestamp, void * data, size_t datasize,
65	const media_raw_audio_format & format);
66typedef void (*SoundNotifyFunc)(void * cookie,
67	int32 code, ...);
68
69//	These are special codes that we use in the Notify
70//	function hook.
71enum {
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*)
77	B_DISCONNECTED,			//
78	B_FORMAT_CHANGED,		//	media_raw_audio_format*
79	B_NODE_DIES,			//	node will die!
80	B_HOOKS_CHANGED,		//
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
84};
85
86#endif /* _SoundUtils_h */
87