The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

Dependencies:   R_BSP TLV320_RBSP USBHost_custom

Note

For a sample program of with LCD Board,
please refer to GR-PEACH_Audio_Playback_7InchLCD_Sample.

Introduction

The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/dkato/audioplayback_figure1_1x.png

1.2 Pin Definitions

Table 1.1 shows the pins that this sample code are to use.

/media/uploads/dkato/audioplayback_table1_1.png

2. Sample Code Operating Environment

This sample code runs in GR-PEACH + the Audio/Camera shield for the GR-PEACH environment. This section explains the functions of the ports that are used by this sample code.

2.1 Operating Environment

Figure 2.1 shows the configuration of the operating environment for running this sample code.

/media/uploads/dkato/audioplayback_figure2_1.png /media/uploads/1050186/figure2_2.png /media/uploads/dkato/audioplayback_figure2_3.png

2.2 List of User Operations

A list of user operations on the command line, TFT touch keys, and switch key that the user can perform for this sample code is shown in. Table 2.1.

/media/uploads/dkato/audioplayback_table2_1x.png

3. Function Outline

The functions of this sample code are summarized in Table 3.1 to Table 3.3.

/media/uploads/dkato/audioplayback_table3_1.png /media/uploads/dkato/audioplayback_table3_2.png /media/uploads/dkato/audioplayback_table3_3.png /media/uploads/dkato/audioplayback_figure3_1.png

3.1 Playback Control

The playback control that the sample code supports include play, pause, stop, skip to next, and skip to previous.

3.2 Trick Play Control

Manipulating "Repeat" alternates between "Repeat mode On" and "Repeat mode Off". The default mode is "Repeat mode On". When the repeat mode is on, the playback of the first song starts after the playback of the last song is finished. When the repeat mode is off, the sample code enters the stopped state after the playback of the last song is finished.

3.3 Acquisition of the Song Information

The information of the song being played is obtained by operating the "Play info" during the playback of the song. Table 3.4 lists the items of information that can be obtained by the "Play info" operation.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How the Folder Structure is Analyzed

The sample coded analyzes the folder structure in the breadth-first search order. The order in which files are numbered is illustrated in Table 3.5. The sample code does not sort the files by file or folder name.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Committer:
dkato
Date:
Fri Oct 16 04:28:07 2015 +0000
Revision:
0:ee40da884cfc
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:ee40da884cfc 1 /* libFLAC - Free Lossless Audio Codec library
dkato 0:ee40da884cfc 2 * Copyright (C) 2000-2009 Josh Coalson
dkato 0:ee40da884cfc 3 * Copyright (C) 2011-2014 Xiph.Org Foundation
dkato 0:ee40da884cfc 4 *
dkato 0:ee40da884cfc 5 * Redistribution and use in source and binary forms, with or without
dkato 0:ee40da884cfc 6 * modification, are permitted provided that the following conditions
dkato 0:ee40da884cfc 7 * are met:
dkato 0:ee40da884cfc 8 *
dkato 0:ee40da884cfc 9 * - Redistributions of source code must retain the above copyright
dkato 0:ee40da884cfc 10 * notice, this list of conditions and the following disclaimer.
dkato 0:ee40da884cfc 11 *
dkato 0:ee40da884cfc 12 * - Redistributions in binary form must reproduce the above copyright
dkato 0:ee40da884cfc 13 * notice, this list of conditions and the following disclaimer in the
dkato 0:ee40da884cfc 14 * documentation and/or other materials provided with the distribution.
dkato 0:ee40da884cfc 15 *
dkato 0:ee40da884cfc 16 * - Neither the name of the Xiph.org Foundation nor the names of its
dkato 0:ee40da884cfc 17 * contributors may be used to endorse or promote products derived from
dkato 0:ee40da884cfc 18 * this software without specific prior written permission.
dkato 0:ee40da884cfc 19 *
dkato 0:ee40da884cfc 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dkato 0:ee40da884cfc 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dkato 0:ee40da884cfc 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dkato 0:ee40da884cfc 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
dkato 0:ee40da884cfc 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dkato 0:ee40da884cfc 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dkato 0:ee40da884cfc 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dkato 0:ee40da884cfc 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dkato 0:ee40da884cfc 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dkato 0:ee40da884cfc 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dkato 0:ee40da884cfc 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dkato 0:ee40da884cfc 31 */
dkato 0:ee40da884cfc 32
dkato 0:ee40da884cfc 33 #ifdef HAVE_CONFIG_H
dkato 0:ee40da884cfc 34 # include <config.h>
dkato 0:ee40da884cfc 35 #endif
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 #include <stdio.h>
dkato 0:ee40da884cfc 38 #include <stdlib.h> /* for qsort() */
dkato 0:ee40da884cfc 39 #include <string.h> /* for memset() */
dkato 0:ee40da884cfc 40 #include "FLAC/assert.h"
dkato 0:ee40da884cfc 41 #include "FLAC/format.h"
dkato 0:ee40da884cfc 42 #include "share/compat.h"
dkato 0:ee40da884cfc 43 #include "private/format.h"
dkato 0:ee40da884cfc 44 #include "private/macros.h"
dkato 0:ee40da884cfc 45
dkato 0:ee40da884cfc 46 #if(1) /* mbed */
dkato 0:ee40da884cfc 47 #define VERSION "1.3.1"
dkato 0:ee40da884cfc 48 #endif /* end mbed */
dkato 0:ee40da884cfc 49
dkato 0:ee40da884cfc 50 /* VERSION should come from configure */
dkato 0:ee40da884cfc 51 FLAC_API const char *FLAC__VERSION_STRING = VERSION;
dkato 0:ee40da884cfc 52
dkato 0:ee40da884cfc 53 FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20141125";
dkato 0:ee40da884cfc 54
dkato 0:ee40da884cfc 55 FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
dkato 0:ee40da884cfc 56 FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
dkato 0:ee40da884cfc 57 FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
dkato 0:ee40da884cfc 58
dkato 0:ee40da884cfc 59 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
dkato 0:ee40da884cfc 60 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
dkato 0:ee40da884cfc 61 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
dkato 0:ee40da884cfc 62 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
dkato 0:ee40da884cfc 63 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
dkato 0:ee40da884cfc 64 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
dkato 0:ee40da884cfc 65 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
dkato 0:ee40da884cfc 66 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
dkato 0:ee40da884cfc 67 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
dkato 0:ee40da884cfc 70
dkato 0:ee40da884cfc 71 FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
dkato 0:ee40da884cfc 72 FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
dkato 0:ee40da884cfc 73 FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
dkato 0:ee40da884cfc 74
dkato 0:ee40da884cfc 75 FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
dkato 0:ee40da884cfc 76
dkato 0:ee40da884cfc 77 FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 78 FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
dkato 0:ee40da884cfc 79
dkato 0:ee40da884cfc 80 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
dkato 0:ee40da884cfc 81 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
dkato 0:ee40da884cfc 82 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
dkato 0:ee40da884cfc 83
dkato 0:ee40da884cfc 84 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
dkato 0:ee40da884cfc 85 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
dkato 0:ee40da884cfc 86 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
dkato 0:ee40da884cfc 87 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
dkato 0:ee40da884cfc 88 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
dkato 0:ee40da884cfc 89 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
dkato 0:ee40da884cfc 90 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
dkato 0:ee40da884cfc 91
dkato 0:ee40da884cfc 92 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
dkato 0:ee40da884cfc 93 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
dkato 0:ee40da884cfc 94 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
dkato 0:ee40da884cfc 95 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
dkato 0:ee40da884cfc 96 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
dkato 0:ee40da884cfc 97
dkato 0:ee40da884cfc 98 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
dkato 0:ee40da884cfc 99 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 100 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 101 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 102 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
dkato 0:ee40da884cfc 103 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 104 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
dkato 0:ee40da884cfc 105 FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
dkato 0:ee40da884cfc 106
dkato 0:ee40da884cfc 107 FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
dkato 0:ee40da884cfc 108 FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
dkato 0:ee40da884cfc 109 FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
dkato 0:ee40da884cfc 110
dkato 0:ee40da884cfc 111 FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
dkato 0:ee40da884cfc 112 FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
dkato 0:ee40da884cfc 113 FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
dkato 0:ee40da884cfc 114 FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
dkato 0:ee40da884cfc 115 FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
dkato 0:ee40da884cfc 116 FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
dkato 0:ee40da884cfc 117 FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
dkato 0:ee40da884cfc 118 FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
dkato 0:ee40da884cfc 119 FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
dkato 0:ee40da884cfc 120 FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
dkato 0:ee40da884cfc 121
dkato 0:ee40da884cfc 122 FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
dkato 0:ee40da884cfc 123
dkato 0:ee40da884cfc 124 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
dkato 0:ee40da884cfc 125 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
dkato 0:ee40da884cfc 126 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
dkato 0:ee40da884cfc 127 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
dkato 0:ee40da884cfc 128 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
dkato 0:ee40da884cfc 129
dkato 0:ee40da884cfc 130 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
dkato 0:ee40da884cfc 131 FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
dkato 0:ee40da884cfc 132
dkato 0:ee40da884cfc 133 FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
dkato 0:ee40da884cfc 134 "PARTITIONED_RICE",
dkato 0:ee40da884cfc 135 "PARTITIONED_RICE2"
dkato 0:ee40da884cfc 136 };
dkato 0:ee40da884cfc 137
dkato 0:ee40da884cfc 138 FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
dkato 0:ee40da884cfc 139 FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
dkato 0:ee40da884cfc 140
dkato 0:ee40da884cfc 141 FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
dkato 0:ee40da884cfc 142 FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
dkato 0:ee40da884cfc 143 FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
dkato 0:ee40da884cfc 144
dkato 0:ee40da884cfc 145 FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
dkato 0:ee40da884cfc 146 FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
dkato 0:ee40da884cfc 147 FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
dkato 0:ee40da884cfc 148 FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
dkato 0:ee40da884cfc 149
dkato 0:ee40da884cfc 150 FLAC_API const char * const FLAC__SubframeTypeString[] = {
dkato 0:ee40da884cfc 151 "CONSTANT",
dkato 0:ee40da884cfc 152 "VERBATIM",
dkato 0:ee40da884cfc 153 "FIXED",
dkato 0:ee40da884cfc 154 "LPC"
dkato 0:ee40da884cfc 155 };
dkato 0:ee40da884cfc 156
dkato 0:ee40da884cfc 157 FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
dkato 0:ee40da884cfc 158 "INDEPENDENT",
dkato 0:ee40da884cfc 159 "LEFT_SIDE",
dkato 0:ee40da884cfc 160 "RIGHT_SIDE",
dkato 0:ee40da884cfc 161 "MID_SIDE"
dkato 0:ee40da884cfc 162 };
dkato 0:ee40da884cfc 163
dkato 0:ee40da884cfc 164 FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
dkato 0:ee40da884cfc 165 "FRAME_NUMBER_TYPE_FRAME_NUMBER",
dkato 0:ee40da884cfc 166 "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
dkato 0:ee40da884cfc 167 };
dkato 0:ee40da884cfc 168
dkato 0:ee40da884cfc 169 FLAC_API const char * const FLAC__MetadataTypeString[] = {
dkato 0:ee40da884cfc 170 "STREAMINFO",
dkato 0:ee40da884cfc 171 "PADDING",
dkato 0:ee40da884cfc 172 "APPLICATION",
dkato 0:ee40da884cfc 173 "SEEKTABLE",
dkato 0:ee40da884cfc 174 "VORBIS_COMMENT",
dkato 0:ee40da884cfc 175 "CUESHEET",
dkato 0:ee40da884cfc 176 "PICTURE"
dkato 0:ee40da884cfc 177 };
dkato 0:ee40da884cfc 178
dkato 0:ee40da884cfc 179 FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
dkato 0:ee40da884cfc 180 "Other",
dkato 0:ee40da884cfc 181 "32x32 pixels 'file icon' (PNG only)",
dkato 0:ee40da884cfc 182 "Other file icon",
dkato 0:ee40da884cfc 183 "Cover (front)",
dkato 0:ee40da884cfc 184 "Cover (back)",
dkato 0:ee40da884cfc 185 "Leaflet page",
dkato 0:ee40da884cfc 186 "Media (e.g. label side of CD)",
dkato 0:ee40da884cfc 187 "Lead artist/lead performer/soloist",
dkato 0:ee40da884cfc 188 "Artist/performer",
dkato 0:ee40da884cfc 189 "Conductor",
dkato 0:ee40da884cfc 190 "Band/Orchestra",
dkato 0:ee40da884cfc 191 "Composer",
dkato 0:ee40da884cfc 192 "Lyricist/text writer",
dkato 0:ee40da884cfc 193 "Recording Location",
dkato 0:ee40da884cfc 194 "During recording",
dkato 0:ee40da884cfc 195 "During performance",
dkato 0:ee40da884cfc 196 "Movie/video screen capture",
dkato 0:ee40da884cfc 197 "A bright coloured fish",
dkato 0:ee40da884cfc 198 "Illustration",
dkato 0:ee40da884cfc 199 "Band/artist logotype",
dkato 0:ee40da884cfc 200 "Publisher/Studio logotype"
dkato 0:ee40da884cfc 201 };
dkato 0:ee40da884cfc 202
dkato 0:ee40da884cfc 203 FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
dkato 0:ee40da884cfc 204 {
dkato 0:ee40da884cfc 205 if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
dkato 0:ee40da884cfc 206 return false;
dkato 0:ee40da884cfc 207 }
dkato 0:ee40da884cfc 208 else
dkato 0:ee40da884cfc 209 return true;
dkato 0:ee40da884cfc 210 }
dkato 0:ee40da884cfc 211
dkato 0:ee40da884cfc 212 FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned blocksize, unsigned sample_rate)
dkato 0:ee40da884cfc 213 {
dkato 0:ee40da884cfc 214 if(blocksize > 16384)
dkato 0:ee40da884cfc 215 return false;
dkato 0:ee40da884cfc 216 else if(sample_rate <= 48000 && blocksize > 4608)
dkato 0:ee40da884cfc 217 return false;
dkato 0:ee40da884cfc 218 else
dkato 0:ee40da884cfc 219 return true;
dkato 0:ee40da884cfc 220 }
dkato 0:ee40da884cfc 221
dkato 0:ee40da884cfc 222 FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
dkato 0:ee40da884cfc 223 {
dkato 0:ee40da884cfc 224 if(
dkato 0:ee40da884cfc 225 !FLAC__format_sample_rate_is_valid(sample_rate) ||
dkato 0:ee40da884cfc 226 (
dkato 0:ee40da884cfc 227 sample_rate >= (1u << 16) &&
dkato 0:ee40da884cfc 228 !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
dkato 0:ee40da884cfc 229 )
dkato 0:ee40da884cfc 230 ) {
dkato 0:ee40da884cfc 231 return false;
dkato 0:ee40da884cfc 232 }
dkato 0:ee40da884cfc 233 else
dkato 0:ee40da884cfc 234 return true;
dkato 0:ee40da884cfc 235 }
dkato 0:ee40da884cfc 236
dkato 0:ee40da884cfc 237 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
dkato 0:ee40da884cfc 238 FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
dkato 0:ee40da884cfc 239 {
dkato 0:ee40da884cfc 240 unsigned i;
dkato 0:ee40da884cfc 241 FLAC__uint64 prev_sample_number = 0;
dkato 0:ee40da884cfc 242 FLAC__bool got_prev = false;
dkato 0:ee40da884cfc 243
dkato 0:ee40da884cfc 244 FLAC__ASSERT(0 != seek_table);
dkato 0:ee40da884cfc 245
dkato 0:ee40da884cfc 246 for(i = 0; i < seek_table->num_points; i++) {
dkato 0:ee40da884cfc 247 if(got_prev) {
dkato 0:ee40da884cfc 248 if(
dkato 0:ee40da884cfc 249 seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
dkato 0:ee40da884cfc 250 seek_table->points[i].sample_number <= prev_sample_number
dkato 0:ee40da884cfc 251 )
dkato 0:ee40da884cfc 252 return false;
dkato 0:ee40da884cfc 253 }
dkato 0:ee40da884cfc 254 prev_sample_number = seek_table->points[i].sample_number;
dkato 0:ee40da884cfc 255 got_prev = true;
dkato 0:ee40da884cfc 256 }
dkato 0:ee40da884cfc 257
dkato 0:ee40da884cfc 258 return true;
dkato 0:ee40da884cfc 259 }
dkato 0:ee40da884cfc 260
dkato 0:ee40da884cfc 261 /* used as the sort predicate for qsort() */
dkato 0:ee40da884cfc 262 static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
dkato 0:ee40da884cfc 263 {
dkato 0:ee40da884cfc 264 /* we don't just 'return l->sample_number - r->sample_number' since the result (FLAC__int64) might overflow an 'int' */
dkato 0:ee40da884cfc 265 if(l->sample_number == r->sample_number)
dkato 0:ee40da884cfc 266 return 0;
dkato 0:ee40da884cfc 267 else if(l->sample_number < r->sample_number)
dkato 0:ee40da884cfc 268 return -1;
dkato 0:ee40da884cfc 269 else
dkato 0:ee40da884cfc 270 return 1;
dkato 0:ee40da884cfc 271 }
dkato 0:ee40da884cfc 272
dkato 0:ee40da884cfc 273 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
dkato 0:ee40da884cfc 274 FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
dkato 0:ee40da884cfc 275 {
dkato 0:ee40da884cfc 276 unsigned i, j;
dkato 0:ee40da884cfc 277 FLAC__bool first;
dkato 0:ee40da884cfc 278
dkato 0:ee40da884cfc 279 FLAC__ASSERT(0 != seek_table);
dkato 0:ee40da884cfc 280
dkato 0:ee40da884cfc 281 /* sort the seekpoints */
dkato 0:ee40da884cfc 282 qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
dkato 0:ee40da884cfc 283
dkato 0:ee40da884cfc 284 /* uniquify the seekpoints */
dkato 0:ee40da884cfc 285 first = true;
dkato 0:ee40da884cfc 286 for(i = j = 0; i < seek_table->num_points; i++) {
dkato 0:ee40da884cfc 287 if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
dkato 0:ee40da884cfc 288 if(!first) {
dkato 0:ee40da884cfc 289 if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
dkato 0:ee40da884cfc 290 continue;
dkato 0:ee40da884cfc 291 }
dkato 0:ee40da884cfc 292 }
dkato 0:ee40da884cfc 293 first = false;
dkato 0:ee40da884cfc 294 seek_table->points[j++] = seek_table->points[i];
dkato 0:ee40da884cfc 295 }
dkato 0:ee40da884cfc 296
dkato 0:ee40da884cfc 297 for(i = j; i < seek_table->num_points; i++) {
dkato 0:ee40da884cfc 298 seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
dkato 0:ee40da884cfc 299 seek_table->points[i].stream_offset = 0;
dkato 0:ee40da884cfc 300 seek_table->points[i].frame_samples = 0;
dkato 0:ee40da884cfc 301 }
dkato 0:ee40da884cfc 302
dkato 0:ee40da884cfc 303 return j;
dkato 0:ee40da884cfc 304 }
dkato 0:ee40da884cfc 305
dkato 0:ee40da884cfc 306 /*
dkato 0:ee40da884cfc 307 * also disallows non-shortest-form encodings, c.f.
dkato 0:ee40da884cfc 308 * http://www.unicode.org/versions/corrigendum1.html
dkato 0:ee40da884cfc 309 * and a more clear explanation at the end of this section:
dkato 0:ee40da884cfc 310 * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
dkato 0:ee40da884cfc 311 */
dkato 0:ee40da884cfc 312 static unsigned utf8len_(const FLAC__byte *utf8)
dkato 0:ee40da884cfc 313 {
dkato 0:ee40da884cfc 314 FLAC__ASSERT(0 != utf8);
dkato 0:ee40da884cfc 315 if ((utf8[0] & 0x80) == 0) {
dkato 0:ee40da884cfc 316 return 1;
dkato 0:ee40da884cfc 317 }
dkato 0:ee40da884cfc 318 else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
dkato 0:ee40da884cfc 319 if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
dkato 0:ee40da884cfc 320 return 0;
dkato 0:ee40da884cfc 321 return 2;
dkato 0:ee40da884cfc 322 }
dkato 0:ee40da884cfc 323 else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
dkato 0:ee40da884cfc 324 if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
dkato 0:ee40da884cfc 325 return 0;
dkato 0:ee40da884cfc 326 /* illegal surrogates check (U+D800...U+DFFF and U+FFFE...U+FFFF) */
dkato 0:ee40da884cfc 327 if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
dkato 0:ee40da884cfc 328 return 0;
dkato 0:ee40da884cfc 329 if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
dkato 0:ee40da884cfc 330 return 0;
dkato 0:ee40da884cfc 331 return 3;
dkato 0:ee40da884cfc 332 }
dkato 0:ee40da884cfc 333 else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
dkato 0:ee40da884cfc 334 if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
dkato 0:ee40da884cfc 335 return 0;
dkato 0:ee40da884cfc 336 return 4;
dkato 0:ee40da884cfc 337 }
dkato 0:ee40da884cfc 338 else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
dkato 0:ee40da884cfc 339 if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
dkato 0:ee40da884cfc 340 return 0;
dkato 0:ee40da884cfc 341 return 5;
dkato 0:ee40da884cfc 342 }
dkato 0:ee40da884cfc 343 else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) {
dkato 0:ee40da884cfc 344 if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
dkato 0:ee40da884cfc 345 return 0;
dkato 0:ee40da884cfc 346 return 6;
dkato 0:ee40da884cfc 347 }
dkato 0:ee40da884cfc 348 else {
dkato 0:ee40da884cfc 349 return 0;
dkato 0:ee40da884cfc 350 }
dkato 0:ee40da884cfc 351 }
dkato 0:ee40da884cfc 352
dkato 0:ee40da884cfc 353 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
dkato 0:ee40da884cfc 354 {
dkato 0:ee40da884cfc 355 char c;
dkato 0:ee40da884cfc 356 for(c = *name; c; c = *(++name))
dkato 0:ee40da884cfc 357 if(c < 0x20 || c == 0x3d || c > 0x7d)
dkato 0:ee40da884cfc 358 return false;
dkato 0:ee40da884cfc 359 return true;
dkato 0:ee40da884cfc 360 }
dkato 0:ee40da884cfc 361
dkato 0:ee40da884cfc 362 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
dkato 0:ee40da884cfc 363 {
dkato 0:ee40da884cfc 364 if(length == (unsigned)(-1)) {
dkato 0:ee40da884cfc 365 while(*value) {
dkato 0:ee40da884cfc 366 unsigned n = utf8len_(value);
dkato 0:ee40da884cfc 367 if(n == 0)
dkato 0:ee40da884cfc 368 return false;
dkato 0:ee40da884cfc 369 value += n;
dkato 0:ee40da884cfc 370 }
dkato 0:ee40da884cfc 371 }
dkato 0:ee40da884cfc 372 else {
dkato 0:ee40da884cfc 373 const FLAC__byte *end = value + length;
dkato 0:ee40da884cfc 374 while(value < end) {
dkato 0:ee40da884cfc 375 unsigned n = utf8len_(value);
dkato 0:ee40da884cfc 376 if(n == 0)
dkato 0:ee40da884cfc 377 return false;
dkato 0:ee40da884cfc 378 value += n;
dkato 0:ee40da884cfc 379 }
dkato 0:ee40da884cfc 380 if(value != end)
dkato 0:ee40da884cfc 381 return false;
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383 return true;
dkato 0:ee40da884cfc 384 }
dkato 0:ee40da884cfc 385
dkato 0:ee40da884cfc 386 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
dkato 0:ee40da884cfc 387 {
dkato 0:ee40da884cfc 388 const FLAC__byte *s, *end;
dkato 0:ee40da884cfc 389
dkato 0:ee40da884cfc 390 for(s = entry, end = s + length; s < end && *s != '='; s++) {
dkato 0:ee40da884cfc 391 if(*s < 0x20 || *s > 0x7D)
dkato 0:ee40da884cfc 392 return false;
dkato 0:ee40da884cfc 393 }
dkato 0:ee40da884cfc 394 if(s == end)
dkato 0:ee40da884cfc 395 return false;
dkato 0:ee40da884cfc 396
dkato 0:ee40da884cfc 397 s++; /* skip '=' */
dkato 0:ee40da884cfc 398
dkato 0:ee40da884cfc 399 while(s < end) {
dkato 0:ee40da884cfc 400 unsigned n = utf8len_(s);
dkato 0:ee40da884cfc 401 if(n == 0)
dkato 0:ee40da884cfc 402 return false;
dkato 0:ee40da884cfc 403 s += n;
dkato 0:ee40da884cfc 404 }
dkato 0:ee40da884cfc 405 if(s != end)
dkato 0:ee40da884cfc 406 return false;
dkato 0:ee40da884cfc 407
dkato 0:ee40da884cfc 408 return true;
dkato 0:ee40da884cfc 409 }
dkato 0:ee40da884cfc 410
dkato 0:ee40da884cfc 411 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
dkato 0:ee40da884cfc 412 FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
dkato 0:ee40da884cfc 413 {
dkato 0:ee40da884cfc 414 unsigned i, j;
dkato 0:ee40da884cfc 415
dkato 0:ee40da884cfc 416 if(check_cd_da_subset) {
dkato 0:ee40da884cfc 417 if(cue_sheet->lead_in < 2 * 44100) {
dkato 0:ee40da884cfc 418 if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
dkato 0:ee40da884cfc 419 return false;
dkato 0:ee40da884cfc 420 }
dkato 0:ee40da884cfc 421 if(cue_sheet->lead_in % 588 != 0) {
dkato 0:ee40da884cfc 422 if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
dkato 0:ee40da884cfc 423 return false;
dkato 0:ee40da884cfc 424 }
dkato 0:ee40da884cfc 425 }
dkato 0:ee40da884cfc 426
dkato 0:ee40da884cfc 427 if(cue_sheet->num_tracks == 0) {
dkato 0:ee40da884cfc 428 if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
dkato 0:ee40da884cfc 429 return false;
dkato 0:ee40da884cfc 430 }
dkato 0:ee40da884cfc 431
dkato 0:ee40da884cfc 432 if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
dkato 0:ee40da884cfc 433 if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
dkato 0:ee40da884cfc 434 return false;
dkato 0:ee40da884cfc 435 }
dkato 0:ee40da884cfc 436
dkato 0:ee40da884cfc 437 for(i = 0; i < cue_sheet->num_tracks; i++) {
dkato 0:ee40da884cfc 438 if(cue_sheet->tracks[i].number == 0) {
dkato 0:ee40da884cfc 439 if(violation) *violation = "cue sheet may not have a track number 0";
dkato 0:ee40da884cfc 440 return false;
dkato 0:ee40da884cfc 441 }
dkato 0:ee40da884cfc 442
dkato 0:ee40da884cfc 443 if(check_cd_da_subset) {
dkato 0:ee40da884cfc 444 if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
dkato 0:ee40da884cfc 445 if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
dkato 0:ee40da884cfc 446 return false;
dkato 0:ee40da884cfc 447 }
dkato 0:ee40da884cfc 448 }
dkato 0:ee40da884cfc 449
dkato 0:ee40da884cfc 450 if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
dkato 0:ee40da884cfc 451 if(violation) {
dkato 0:ee40da884cfc 452 if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
dkato 0:ee40da884cfc 453 *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
dkato 0:ee40da884cfc 454 else
dkato 0:ee40da884cfc 455 *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
dkato 0:ee40da884cfc 456 }
dkato 0:ee40da884cfc 457 return false;
dkato 0:ee40da884cfc 458 }
dkato 0:ee40da884cfc 459
dkato 0:ee40da884cfc 460 if(i < cue_sheet->num_tracks - 1) {
dkato 0:ee40da884cfc 461 if(cue_sheet->tracks[i].num_indices == 0) {
dkato 0:ee40da884cfc 462 if(violation) *violation = "cue sheet track must have at least one index point";
dkato 0:ee40da884cfc 463 return false;
dkato 0:ee40da884cfc 464 }
dkato 0:ee40da884cfc 465
dkato 0:ee40da884cfc 466 if(cue_sheet->tracks[i].indices[0].number > 1) {
dkato 0:ee40da884cfc 467 if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
dkato 0:ee40da884cfc 468 return false;
dkato 0:ee40da884cfc 469 }
dkato 0:ee40da884cfc 470 }
dkato 0:ee40da884cfc 471
dkato 0:ee40da884cfc 472 for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
dkato 0:ee40da884cfc 473 if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
dkato 0:ee40da884cfc 474 if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
dkato 0:ee40da884cfc 475 return false;
dkato 0:ee40da884cfc 476 }
dkato 0:ee40da884cfc 477
dkato 0:ee40da884cfc 478 if(j > 0) {
dkato 0:ee40da884cfc 479 if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
dkato 0:ee40da884cfc 480 if(violation) *violation = "cue sheet track index numbers must increase by 1";
dkato 0:ee40da884cfc 481 return false;
dkato 0:ee40da884cfc 482 }
dkato 0:ee40da884cfc 483 }
dkato 0:ee40da884cfc 484 }
dkato 0:ee40da884cfc 485 }
dkato 0:ee40da884cfc 486
dkato 0:ee40da884cfc 487 return true;
dkato 0:ee40da884cfc 488 }
dkato 0:ee40da884cfc 489
dkato 0:ee40da884cfc 490 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
dkato 0:ee40da884cfc 491 FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
dkato 0:ee40da884cfc 492 {
dkato 0:ee40da884cfc 493 char *p;
dkato 0:ee40da884cfc 494 FLAC__byte *b;
dkato 0:ee40da884cfc 495
dkato 0:ee40da884cfc 496 for(p = picture->mime_type; *p; p++) {
dkato 0:ee40da884cfc 497 if(*p < 0x20 || *p > 0x7e) {
dkato 0:ee40da884cfc 498 if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
dkato 0:ee40da884cfc 499 return false;
dkato 0:ee40da884cfc 500 }
dkato 0:ee40da884cfc 501 }
dkato 0:ee40da884cfc 502
dkato 0:ee40da884cfc 503 for(b = picture->description; *b; ) {
dkato 0:ee40da884cfc 504 unsigned n = utf8len_(b);
dkato 0:ee40da884cfc 505 if(n == 0) {
dkato 0:ee40da884cfc 506 if(violation) *violation = "description string must be valid UTF-8";
dkato 0:ee40da884cfc 507 return false;
dkato 0:ee40da884cfc 508 }
dkato 0:ee40da884cfc 509 b += n;
dkato 0:ee40da884cfc 510 }
dkato 0:ee40da884cfc 511
dkato 0:ee40da884cfc 512 return true;
dkato 0:ee40da884cfc 513 }
dkato 0:ee40da884cfc 514
dkato 0:ee40da884cfc 515 /*
dkato 0:ee40da884cfc 516 * These routines are private to libFLAC
dkato 0:ee40da884cfc 517 */
dkato 0:ee40da884cfc 518 unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
dkato 0:ee40da884cfc 519 {
dkato 0:ee40da884cfc 520 return
dkato 0:ee40da884cfc 521 FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
dkato 0:ee40da884cfc 522 FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
dkato 0:ee40da884cfc 523 blocksize,
dkato 0:ee40da884cfc 524 predictor_order
dkato 0:ee40da884cfc 525 );
dkato 0:ee40da884cfc 526 }
dkato 0:ee40da884cfc 527
dkato 0:ee40da884cfc 528 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
dkato 0:ee40da884cfc 529 {
dkato 0:ee40da884cfc 530 unsigned max_rice_partition_order = 0;
dkato 0:ee40da884cfc 531 while(!(blocksize & 1)) {
dkato 0:ee40da884cfc 532 max_rice_partition_order++;
dkato 0:ee40da884cfc 533 blocksize >>= 1;
dkato 0:ee40da884cfc 534 }
dkato 0:ee40da884cfc 535 return flac_min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
dkato 0:ee40da884cfc 536 }
dkato 0:ee40da884cfc 537
dkato 0:ee40da884cfc 538 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
dkato 0:ee40da884cfc 539 {
dkato 0:ee40da884cfc 540 unsigned max_rice_partition_order = limit;
dkato 0:ee40da884cfc 541
dkato 0:ee40da884cfc 542 while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
dkato 0:ee40da884cfc 543 max_rice_partition_order--;
dkato 0:ee40da884cfc 544
dkato 0:ee40da884cfc 545 FLAC__ASSERT(
dkato 0:ee40da884cfc 546 (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
dkato 0:ee40da884cfc 547 (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
dkato 0:ee40da884cfc 548 );
dkato 0:ee40da884cfc 549
dkato 0:ee40da884cfc 550 return max_rice_partition_order;
dkato 0:ee40da884cfc 551 }
dkato 0:ee40da884cfc 552
dkato 0:ee40da884cfc 553 void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
dkato 0:ee40da884cfc 554 {
dkato 0:ee40da884cfc 555 FLAC__ASSERT(0 != object);
dkato 0:ee40da884cfc 556
dkato 0:ee40da884cfc 557 object->parameters = 0;
dkato 0:ee40da884cfc 558 object->raw_bits = 0;
dkato 0:ee40da884cfc 559 object->capacity_by_order = 0;
dkato 0:ee40da884cfc 560 }
dkato 0:ee40da884cfc 561
dkato 0:ee40da884cfc 562 void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
dkato 0:ee40da884cfc 563 {
dkato 0:ee40da884cfc 564 FLAC__ASSERT(0 != object);
dkato 0:ee40da884cfc 565
dkato 0:ee40da884cfc 566 if(0 != object->parameters)
dkato 0:ee40da884cfc 567 free(object->parameters);
dkato 0:ee40da884cfc 568 if(0 != object->raw_bits)
dkato 0:ee40da884cfc 569 free(object->raw_bits);
dkato 0:ee40da884cfc 570 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
dkato 0:ee40da884cfc 571 }
dkato 0:ee40da884cfc 572
dkato 0:ee40da884cfc 573 FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
dkato 0:ee40da884cfc 574 {
dkato 0:ee40da884cfc 575 FLAC__ASSERT(0 != object);
dkato 0:ee40da884cfc 576
dkato 0:ee40da884cfc 577 FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
dkato 0:ee40da884cfc 578
dkato 0:ee40da884cfc 579 if(object->capacity_by_order < max_partition_order) {
dkato 0:ee40da884cfc 580 if(0 == (object->parameters = realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
dkato 0:ee40da884cfc 581 return false;
dkato 0:ee40da884cfc 582 if(0 == (object->raw_bits = realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
dkato 0:ee40da884cfc 583 return false;
dkato 0:ee40da884cfc 584 memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
dkato 0:ee40da884cfc 585 object->capacity_by_order = max_partition_order;
dkato 0:ee40da884cfc 586 }
dkato 0:ee40da884cfc 587
dkato 0:ee40da884cfc 588 return true;
dkato 0:ee40da884cfc 589 }