| 1 | /* Bonk - Lossy/lossless audio codec |
| 2 | * Copyright (C) 2001 Paul Francis Harrison |
| 3 | * Portions Copyright (C) 2004-2009 Robert Kausch <[email protected]> |
| 4 | * |
| 5 | * This header file is in the public domain; you can redistribute |
| 6 | * it and/or modify it freely without any limitations. |
| 7 | * |
| 8 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 9 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 10 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 11 | |
| 12 | #ifndef H_BONK |
| 13 | #define H_BONK |
| 14 | |
| 15 | #ifdef __WIN32__ |
| 16 | # ifdef BONK_LIBRARY_BUILD |
| 17 | # define BONKAPI __declspec (dllexport) |
| 18 | # define BONKCONV _stdcall |
| 19 | # else |
| 20 | # ifdef BONK_STATIC |
| 21 | # define BONKAPI |
| 22 | # define BONKCONV _stdcall |
| 23 | # else |
| 24 | # define BONKAPI __declspec (dllimport) |
| 25 | # define BONKCONV _stdcall |
| 26 | # endif |
| 27 | # endif |
| 28 | #else |
| 29 | # define BONKAPI |
| 30 | # define BONKCONV |
| 31 | #endif |
| 32 | |
| 33 | extern "C" |
| 34 | { |
| 35 | /* void *bonk_encoder_create() |
| 36 | * Creates a Bonk encoder context. |
| 37 | * |
| 38 | * Call this function as the first one and use the returned context |
| 39 | * handle as the first argument to any other bonk_encoder_* call. |
| 40 | */ |
| 41 | BONKAPI void * BONKCONV bonk_encoder_create(); |
| 42 | |
| 43 | /* bool bonk_encoder_init(void *encoder, unsigned int length, unsigned int rate, int channels, bool lossless, bool mid_side, int n_taps, int down_sampling, int samples_per_packet, double quantization) |
| 44 | * Initializes the Bonk encoder. |
| 45 | * |
| 46 | * This function initializes the encoder and sets all encoding parameters. |
| 47 | */ |
| 48 | BONKAPI bool BONKCONV bonk_encoder_init(void *, unsigned int, unsigned int, int, bool, bool, int, int, int, double); |
| 49 | |
| 50 | /* int bonk_encoder_encode_packet(void *encoder, signed short *samples, int n_samples, unsigned char *out_buffer, int out_size) |
| 51 | * Writes a packet of audio samples to the encoded Bonk stream. |
| 52 | * |
| 53 | * The function returns the number of bytes written to out_buffer. |
| 54 | */ |
| 55 | |
| 56 | BONKAPI int BONKCONV bonk_encoder_encode_packet(void *, signed short *, int, unsigned char *, int); |
| 57 | |
| 58 | /* int bonk_encoder_finish(void *encoder, unsigned char *out_buffer, int out_size) |
| 59 | * Finishes encoding of an audio stream. |
| 60 | * |
| 61 | * Call bonk_encoder_finish after you have written all samples using |
| 62 | * bonk_encoder_encode_packet. The function will write any remaining |
| 63 | * data to the buffer given as a parameter. The number of bytes written |
| 64 | * will be returned. |
| 65 | * |
| 66 | * If the buffer is too small, the function will return the number of |
| 67 | * bytes needed in the buffer. |
| 68 | */ |
| 69 | BONKAPI int BONKCONV bonk_encoder_finish(void *, unsigned char *, int); |
| 70 | |
| 71 | /* bool bonk_encoder_close(void *encoder) |
| 72 | * Frees a Bonk encoder context. |
| 73 | * |
| 74 | * Call this function after you have finished using the encoder context. |
| 75 | */ |
| 76 | BONKAPI bool BONKCONV bonk_encoder_close(void *); |
| 77 | |
| 78 | /* int bonk_encoder_get_sample_count(void *encoder) |
| 79 | * Returns the number of samples processed by the encoder. |
| 80 | * |
| 81 | * You have to write the number of samples to the output file at |
| 82 | * the position indicated by bonk_encoder_get_sample_count_offset. |
| 83 | */ |
| 84 | BONKAPI int BONKCONV bonk_encoder_get_sample_count(void *); |
| 85 | |
| 86 | /* int bonk_encoder_get_sample_count_offset(void *encoder) |
| 87 | * Returns the offset of the samples count in the output file. |
| 88 | * |
| 89 | * You have to write the number of samples to this position. |
| 90 | */ |
| 91 | BONKAPI int BONKCONV bonk_encoder_get_sample_count_offset(void *); |
| 92 | |
| 93 | /* bool bonk_encoder_set_id3_data(void *encoder, unsigned char *id3data, int bytes) |
| 94 | * Set an ID3v2 tag to write to the output stream. |
| 95 | * |
| 96 | * This function has to be called before bonk_encoder_init if you want |
| 97 | * to add ID3v2 information to your Bonk file. |
| 98 | */ |
| 99 | BONKAPI bool BONKCONV bonk_encoder_set_id3_data(void *, unsigned char *, int); |
| 100 | |
| 101 | /* void *bonk_decoder_create() |
| 102 | * Creates a Bonk decoder context. |
| 103 | * |
| 104 | * Call this function as the first one and use the returned context |
| 105 | * handle as the first argument to any other bonk_decoder_* call. |
| 106 | */ |
| 107 | BONKAPI void * BONKCONV bonk_decoder_create(); |
| 108 | |
| 109 | /* bool bonk_decoder_init(void *decoder, unsigned char *in_buffer, int in_bytes, unsigned int *length, unsigned int *rate, int *channels) |
| 110 | * Initializes the Bonk audio decoder. |
| 111 | * |
| 112 | * This function initializes the decoder. You must provide enough bytes |
| 113 | * from the beginning of the file to include the header of the BONK tag. |
| 114 | * Be aware that a Bonk file might have an ID3 tag prepended before the |
| 115 | * BONK tag. |
| 116 | * The function will write the number of samples, sampling rate and the |
| 117 | * number of channels to the supplied pointers. The pointers can be null |
| 118 | * if this information is not needed. |
| 119 | */ |
| 120 | BONKAPI bool BONKCONV bonk_decoder_init(void *, unsigned char *, int, unsigned int *, unsigned int *, int *); |
| 121 | |
| 122 | /* int bonk_decoder_decode_packet(void *decoder, unsigned char *in_buffer, int in_bytes, signed short *samples, int samples_size) |
| 123 | * Decodes a packet of samples from the Bonk audio stream. |
| 124 | * |
| 125 | * This function decodes one block at once. You should provide enough data |
| 126 | * in in_buffer. If you have provided all data to the Bonk decoder, but there |
| 127 | * are still packets left to decode, simply set in_bytes to 0 and continue |
| 128 | * calling bonk_decoder_decode_packet until all packets are read. |
| 129 | * The function will return the number of samples written to samples. |
| 130 | */ |
| 131 | BONKAPI int BONKCONV bonk_decoder_decode_packet(void *, unsigned char *, int, signed short *, int); |
| 132 | |
| 133 | /* int bonk_decoder_finish(void *decoder) |
| 134 | * Finishes decoding of an audio stream. |
| 135 | * |
| 136 | * bonk_decoder_finish should be called after all blocks of a Bonk stream |
| 137 | * have been processed. It should return 0. |
| 138 | */ |
| 139 | BONKAPI int BONKCONV bonk_decoder_finish(void *); |
| 140 | |
| 141 | /* bool bonk_decoder_close(void *decoder) |
| 142 | * Frees a Bonk decoder context. |
| 143 | * |
| 144 | * Call this function after you have finished using the decoder context. |
| 145 | */ |
| 146 | BONKAPI bool BONKCONV bonk_decoder_close(void *); |
| 147 | |
| 148 | /* bool bonk_decoder_get_stream_format(void *decoder, unsigned int *length, unsigned int *rate, int *channels) |
| 149 | * Get information about the audio stream format. |
| 150 | * |
| 151 | * This function will return information about the format of the currently |
| 152 | * open Bonk audio stream. The function will write the number of samples, |
| 153 | * sampling rate and the number of channels to the supplied pointers. |
| 154 | */ |
| 155 | BONKAPI bool BONKCONV bonk_decoder_get_stream_format(void *, unsigned int *, unsigned int *, int *); |
| 156 | |
| 157 | /* bool bonk_decoder_get_stream_info(void *decoder, bool *lossless, bool *mid_side) |
| 158 | * Get stream information for a Bonk stream. |
| 159 | * |
| 160 | * This function will return information about the currently open Bonk |
| 161 | * audio stream. The lossless parameter will be set to true if the stream |
| 162 | * is a lossless Bonk stream. The mid_side parameter will be set to true |
| 163 | * if the stream is encoded using joint stereo. |
| 164 | */ |
| 165 | BONKAPI bool BONKCONV bonk_decoder_get_stream_info(void *, bool *, bool *); |
| 166 | |
| 167 | /* bool bonk_decoder_get_id3_data(void *decoder, unsigned char **id3data, int *bytes) |
| 168 | * Get ID3v2 tag from a Bonk stream. |
| 169 | * |
| 170 | * This function will return the raw ID3v2 tag of the Bonk audio stream. |
| 171 | * The tag data is written to id3data, the number of bytes in id3data is |
| 172 | * returned in the parameter bytes. |
| 173 | */ |
| 174 | BONKAPI bool BONKCONV bonk_decoder_get_id3_data(void *, unsigned char **, int *); |
| 175 | |
| 176 | /* bool bonk_decoder_init_seektable(void *decoder, unsigned char *buffer, int bytes) |
| 177 | * Initialize the seektable to prepare for seeking. |
| 178 | * |
| 179 | * This function must be called before bonk_decoder_seek_to can be used. |
| 180 | * The function will look for an INFO tag in the supplied buffer. |
| 181 | * You should provide enough data from the end of the Bonk file to |
| 182 | * include the whole INFO tag. |
| 183 | */ |
| 184 | BONKAPI bool BONKCONV bonk_decoder_init_seektable(void *, unsigned char *, int); |
| 185 | |
| 186 | /* bool bonk_decoder_seek_to(void *decoder, int sample) |
| 187 | * Seek to the given sample number. |
| 188 | * |
| 189 | * The function will seek to the given sample number. It only works after |
| 190 | * the seektable has been initialized by bonk_decoder_init_seektable. |
| 191 | * Seeking is not exact but will seek to the nearest packet start. |
| 192 | */ |
| 193 | BONKAPI bool BONKCONV bonk_decoder_seek_to(void *, int); |
| 194 | |
| 195 | /* const char *bonk_get_version_string() |
| 196 | * Returns the version number of the Bonk library as a string. |
| 197 | * |
| 198 | * The result will be something like "0.10" or "1.0 beta 2". |
| 199 | */ |
| 200 | BONKAPI const char * BONKCONV bonk_get_version_string(); |
| 201 | } |
| 202 | |
| 203 | #endif |