summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspeex/speex_header.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2024-05-08 10:36:38 -0400
committerSolomon Peachy <pizza@shaftnet.org>2024-06-20 07:08:35 -0400
commit547b6a570dbad844e79b4ba5eb934f043bab6318 (patch)
tree0cbdb670d73a2544d33985166c5abfa69e20a590 /lib/rbcodec/codecs/libspeex/speex_header.c
parent8ef20383b1e5025f7724e750832de6e28e50680d (diff)
downloadrockbox-547b6a570dbad844e79b4ba5eb934f043bab6318.tar.gz
rockbox-547b6a570dbad844e79b4ba5eb934f043bab6318.zip
codecs: Update libspeex from 1.2beta3 to 1.2rc1
This is a relatively minor bump, but it's the first step towards bringing this current. Change-Id: Iab6c9b0c77f0ba705280434ea74b513364719499
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/speex_header.c')
-rw-r--r--lib/rbcodec/codecs/libspeex/speex_header.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/lib/rbcodec/codecs/libspeex/speex_header.c b/lib/rbcodec/codecs/libspeex/speex_header.c
index b0e98b7c9c..f83e0f2152 100644
--- a/lib/rbcodec/codecs/libspeex/speex_header.c
+++ b/lib/rbcodec/codecs/libspeex/speex_header.c
@@ -1,22 +1,22 @@
1/* Copyright (C) 2002 Jean-Marc Valin 1/* Copyright (C) 2002 Jean-Marc Valin
2 File: speex_header.c 2 File: speex_header.c
3 Describes the Speex header 3 Describes the Speex header
4 4
5 Redistribution and use in source and binary forms, with or without 5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions 6 modification, are permitted provided that the following conditions
7 are met: 7 are met:
8 8
9 - Redistributions of source code must retain the above copyright 9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer. 10 notice, this list of conditions and the following disclaimer.
11 11
12 - Redistributions in binary form must reproduce the above copyright 12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the 13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution. 14 documentation and/or other materials provided with the distribution.
15 15
16 - Neither the name of the Xiph.org Foundation nor the names of its 16 - Neither the name of the Xiph.org Foundation nor the names of its
17 contributors may be used to endorse or promote products derived from 17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission. 18 this software without specific prior written permission.
19 19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -47,7 +47,7 @@
47/** Convert little endian */ 47/** Convert little endian */
48static inline spx_int32_t le_int(spx_int32_t i) 48static inline spx_int32_t le_int(spx_int32_t i)
49{ 49{
50#ifdef ROCKBOX 50#ifdef ROCKBOX
51 return letoh32(i); 51 return letoh32(i);
52#elif !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) ) 52#elif !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
53 spx_uint32_t ui, ret; 53 spx_uint32_t ui, ret;
@@ -86,7 +86,7 @@ typedef struct SpeexHeader {
86*/ 86*/
87 87
88#ifndef SPEEX_DISABLE_ENCODER 88#ifndef SPEEX_DISABLE_ENCODER
89void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const SpeexMode *m) 89EXPORT void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const SpeexMode *m)
90{ 90{
91 int i; 91 int i;
92 const char *h="Speex "; 92 const char *h="Speex ";
@@ -101,10 +101,10 @@ void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const Spe
101 header->speex_version[i]=SPEEX_VERSION[i]; 101 header->speex_version[i]=SPEEX_VERSION[i];
102 for (;i<SPEEX_HEADER_VERSION_LENGTH;i++) 102 for (;i<SPEEX_HEADER_VERSION_LENGTH;i++)
103 header->speex_version[i]=0; 103 header->speex_version[i]=0;
104 104
105 header->speex_version_id = 1; 105 header->speex_version_id = 1;
106 header->header_size = sizeof(SpeexHeader); 106 header->header_size = sizeof(SpeexHeader);
107 107
108 header->rate = rate; 108 header->rate = rate;
109 header->mode = m->modeID; 109 header->mode = m->modeID;
110 header->mode_bitstream_version = m->bitstream_version; 110 header->mode_bitstream_version = m->bitstream_version;
@@ -114,20 +114,20 @@ void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const Spe
114 header->bitrate = -1; 114 header->bitrate = -1;
115 speex_mode_query(m, SPEEX_MODE_FRAME_SIZE, &header->frame_size); 115 speex_mode_query(m, SPEEX_MODE_FRAME_SIZE, &header->frame_size);
116 header->vbr = 0; 116 header->vbr = 0;
117 117
118 header->frames_per_packet = 0; 118 header->frames_per_packet = 0;
119 header->extra_headers = 0; 119 header->extra_headers = 0;
120 header->reserved1 = 0; 120 header->reserved1 = 0;
121 header->reserved2 = 0; 121 header->reserved2 = 0;
122} 122}
123 123
124char *speex_header_to_packet(SpeexHeader *header, int *size) 124EXPORT char *speex_header_to_packet(SpeexHeader *header, int *size)
125{ 125{
126 SpeexHeader *le_header; 126 SpeexHeader *le_header;
127 le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); 127 le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader));
128 128
129 SPEEX_COPY(le_header, header, 1); 129 SPEEX_COPY(le_header, header, 1);
130 130
131 /*Make sure everything is now little-endian*/ 131 /*Make sure everything is now little-endian*/
132 ENDIAN_SWITCH(le_header->speex_version_id); 132 ENDIAN_SWITCH(le_header->speex_version_id);
133 ENDIAN_SWITCH(le_header->header_size); 133 ENDIAN_SWITCH(le_header->header_size);
@@ -147,7 +147,7 @@ char *speex_header_to_packet(SpeexHeader *header, int *size)
147#endif /* SPEEX_DISABLE_ENCODER */ 147#endif /* SPEEX_DISABLE_ENCODER */
148 148
149static SpeexHeader global_le_header; /* Avoid malloc */ 149static SpeexHeader global_le_header; /* Avoid malloc */
150SpeexHeader *speex_packet_to_header(char *packet, int size) 150EXPORT SpeexHeader *speex_packet_to_header(char *packet, int size)
151{ 151{
152 int i; 152 int i;
153 SpeexHeader *le_header = &global_le_header; 153 SpeexHeader *le_header = &global_le_header;
@@ -158,18 +158,18 @@ SpeexHeader *speex_packet_to_header(char *packet, int size)
158 speex_notify("This doesn't look like a Speex file"); 158 speex_notify("This doesn't look like a Speex file");
159 return NULL; 159 return NULL;
160 } 160 }
161 161
162 /*FIXME: Do we allow larger headers?*/ 162 /*FIXME: Do we allow larger headers?*/
163 if (size < (int)sizeof(SpeexHeader)) 163 if (size < (int)sizeof(SpeexHeader))
164 { 164 {
165 speex_notify("Speex header too small"); 165 speex_notify("Speex header too small");
166 return NULL; 166 return NULL;
167 } 167 }
168 168
169 /* le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); */ 169 /* le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); */
170 170
171 SPEEX_COPY(le_header, (SpeexHeader*)packet, 1); 171 SPEEX_COPY(le_header, (SpeexHeader*)packet, 1);
172 172
173 /*Make sure everything is converted correctly from little-endian*/ 173 /*Make sure everything is converted correctly from little-endian*/
174 ENDIAN_SWITCH(le_header->speex_version_id); 174 ENDIAN_SWITCH(le_header->speex_version_id);
175 ENDIAN_SWITCH(le_header->header_size); 175 ENDIAN_SWITCH(le_header->header_size);
@@ -183,6 +183,25 @@ SpeexHeader *speex_packet_to_header(char *packet, int size)
183 ENDIAN_SWITCH(le_header->frames_per_packet); 183 ENDIAN_SWITCH(le_header->frames_per_packet);
184 ENDIAN_SWITCH(le_header->extra_headers); 184 ENDIAN_SWITCH(le_header->extra_headers);
185 185
186 if (le_header->mode >= SPEEX_NB_MODES || le_header->mode < 0)
187 {
188 speex_notify("Invalid mode specified in Speex header");
189 speex_free (le_header);
190 return NULL;
191 }
192
193 if (le_header->nb_channels>2)
194 le_header->nb_channels = 2;
195 if (le_header->nb_channels<1)
196 le_header->nb_channels = 1;
197
186 return le_header; 198 return le_header;
187 199
188} 200}
201
202#if 0 /* Unused by rockbox */
203EXPORT void speex_header_free(void *ptr)
204{
205 speex_free(ptr);
206}
207#endif