1 /* 2 Copyright (C) 2003 Commonwealth Scientific and Industrial Research 3 Organisation (CSIRO) Australia 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 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 - Neither the name of CSIRO Australia nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR 24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef __FISH_SOUND_PRIVATE_H__ 34 #define __FISH_SOUND_PRIVATE_H__ 35 36 #include <stdlib.h> 37 38 #include "fs_compat.h" 39 #include "fs_vector.h" 40 41 #include <fishsound/constants.h> 42 43 #undef MIN 44 #define MIN(a,b) (((a)<(b))?(a):(b)) 45 46 typedef struct _FishSound FishSound; 47 typedef struct _FishSoundInfo FishSoundInfo; 48 typedef struct _FishSoundCodec FishSoundCodec; 49 typedef struct _FishSoundFormat FishSoundFormat; 50 typedef struct _FishSoundComment FishSoundComment; 51 52 typedef int (*FSCodecIdentify) (unsigned char * buf, long bytes); 53 typedef FishSound * (*FSCodecInit) (FishSound * fsound); 54 typedef FishSound * (*FSCodecDelete) (FishSound * fsound); 55 typedef int (*FSCodecReset) (FishSound * fsound); 56 typedef int (*FSCodecUpdate) (FishSound * fsound, int interleave); 57 typedef int (*FSCodecCommand) (FishSound * fsound, int command, 58 void * data, int datasize); 59 typedef long (*FSCodecDecode) (FishSound * fsound, unsigned char * buf, 60 long bytes); 61 typedef long (*FSCodecEncode_Float) (FishSound * fsound, float * pcm[], 62 long frames); 63 typedef long (*FSCodecEncode_FloatIlv) (FishSound * fsound, 64 float ** pcm, long frames); 65 typedef long (*FSCodecFlush) (FishSound * fsound); 66 67 #include <fishsound/decode.h> 68 #include <fishsound/encode.h> 69 70 struct _FishSoundFormat { 71 int format; 72 const char * name; 73 const char * extension; 74 }; 75 76 struct _FishSoundCodec { 77 struct _FishSoundFormat format; 78 FSCodecInit init; 79 FSCodecDelete del; 80 FSCodecReset reset; 81 FSCodecUpdate update; 82 FSCodecCommand command; 83 FSCodecDecode decode; 84 FSCodecEncode_FloatIlv encode_f_ilv; 85 FSCodecEncode_Float encode_f; 86 FSCodecFlush flush; 87 }; 88 89 struct _FishSoundInfo { 90 int samplerate; 91 int channels; 92 int format; 93 }; 94 95 struct _FishSoundComment { 96 char * name; 97 char * value; 98 }; 99 100 union FishSoundCallback { 101 FishSoundDecoded_Float decoded_float; 102 FishSoundDecoded_FloatIlv decoded_float_ilv; 103 FishSoundEncoded encoded; 104 }; 105 106 struct _FishSound { 107 /** FISH_SOUND_DECODE or FISH_SOUND_ENCODE */ 108 FishSoundMode mode; 109 110 /** General info related to sound */ 111 FishSoundInfo info; 112 113 /** Interleave boolean */ 114 int interleave; 115 116 /** 117 * Current frameno. 118 */ 119 long frameno; 120 121 /** 122 * Truncation frameno for the next block of data sent to decode. 123 * In Ogg encapsulation, this is represented by the Ogg packet's 124 * "granulepos" field. 125 */ 126 long next_granulepos; 127 128 /** 129 * Flag if the next block of data sent to decode will be the last one 130 * for this stream (eos = End Of Stream). 131 * In Ogg encapsulation, this is represented by the Ogg packet's 132 * "eos" field. 133 */ 134 int next_eos; 135 136 /** The codec class structure */ 137 FishSoundCodec * codec; 138 139 /** codec specific data */ 140 void * codec_data; 141 142 /* encode or decode callback */ 143 union FishSoundCallback callback; 144 145 /** user data for encode/decode callback */ 146 void * user_data; 147 148 /** The comments */ 149 char * vendor; 150 FishSoundVector * comments; 151 }; 152 153 int fish_sound_identify (unsigned char * buf, long bytes); 154 int fish_sound_set_format (FishSound * fsound, int format); 155 156 /* Format specific interfaces */ 157 int fish_sound_vorbis_identify (unsigned char * buf, long bytes); 158 FishSoundCodec * fish_sound_vorbis_codec (void); 159 160 int fish_sound_speex_identify (unsigned char * buf, long bytes); 161 FishSoundCodec * fish_sound_speex_codec (void); 162 163 int fish_sound_flac_identify (unsigned char * buf, long bytes); 164 FishSoundCodec * fish_sound_flac_codec (void); 165 166 /* comments */ 167 int fish_sound_comments_init (FishSound * fsound); 168 int fish_sound_comments_free (FishSound * fsound); 169 int fish_sound_comments_decode (FishSound * fsound, unsigned char * buf, 170 long bytes); 171 long fish_sound_comments_encode (FishSound * fsound, unsigned char * buf, 172 long length); 173 174 /** 175 * Set the vendor string. 176 * \param fsound A FishSound* handle (created with FISH_SOUND_ENCODE) 177 * \param vendor The vendor string. 178 * \retval 0 Success 179 * \retval FISH_SOUND_ERR_BAD \a fsound is not a valid FishSound* handle 180 * \retval FISH_SOUND_ERR_INVALID Operation not suitable for this FishSound 181 */ 182 int 183 fish_sound_comment_set_vendor (FishSound * fsound, const char * vendor); 184 185 const FishSoundComment * fish_sound_comment_first (FishSound * fsound); 186 const FishSoundComment * 187 fish_sound_comment_next (FishSound * fsound, const FishSoundComment * comment); 188 189 #endif /* __FISH_SOUND_PRIVATE_H__ */ 190