| OLD | NEW |
| 1 #if HAVE_CONFIG_H | 1 #ifdef HAVE_CONFIG_H |
| 2 # include <config.h> | 2 # include <config.h> |
| 3 #endif | 3 #endif |
| 4 | 4 |
| 5 #include <stdlib.h> /* for malloc() */ | 5 #include <stdlib.h> /* for malloc() */ |
| 6 #include <string.h> /* for memcpy() */ | 6 #include <string.h> /* for memcpy() */ |
| 7 | 7 |
| 8 #include "private/md5.h" | 8 #include "private/md5.h" |
| 9 #include "share/alloc.h" | 9 #include "share/alloc.h" |
| 10 | 10 #include "share/endswap.h" |
| 11 #ifndef FLaC__INLINE | |
| 12 #define FLaC__INLINE | |
| 13 #endif | |
| 14 | 11 |
| 15 /* | 12 /* |
| 16 * This code implements the MD5 message-digest algorithm. | 13 * This code implements the MD5 message-digest algorithm. |
| 17 * The algorithm is due to Ron Rivest. This code was | 14 * The algorithm is due to Ron Rivest. This code was |
| 18 * written by Colin Plumb in 1993, no copyright is claimed. | 15 * written by Colin Plumb in 1993, no copyright is claimed. |
| 19 * This code is in the public domain; do with it what you wish. | 16 * This code is in the public domain; do with it what you wish. |
| 20 * | 17 * |
| 21 * Equivalent code is available from RSA Data Security, Inc. | 18 * Equivalent code is available from RSA Data Security, Inc. |
| 22 * This code has been tested against that, and is equivalent, | 19 * This code has been tested against that, and is equivalent, |
| 23 * except that you don't need to include two pages of legalese | 20 * except that you don't need to include two pages of legalese |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 buf[2] += c; | 133 buf[2] += c; |
| 137 buf[3] += d; | 134 buf[3] += d; |
| 138 } | 135 } |
| 139 | 136 |
| 140 #if WORDS_BIGENDIAN | 137 #if WORDS_BIGENDIAN |
| 141 //@@@@@@ OPT: use bswap/intrinsics | 138 //@@@@@@ OPT: use bswap/intrinsics |
| 142 static void byteSwap(FLAC__uint32 *buf, unsigned words) | 139 static void byteSwap(FLAC__uint32 *buf, unsigned words) |
| 143 { | 140 { |
| 144 register FLAC__uint32 x; | 141 register FLAC__uint32 x; |
| 145 do { | 142 do { |
| 146 » » x = *buf; | 143 » » x = *buf; |
| 147 x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); | 144 x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); |
| 148 *buf++ = (x >> 16) | (x << 16); | 145 *buf++ = (x >> 16) | (x << 16); |
| 149 } while (--words); | 146 } while (--words); |
| 150 } | 147 } |
| 151 static void byteSwapX16(FLAC__uint32 *buf) | 148 static void byteSwapX16(FLAC__uint32 *buf) |
| 152 { | 149 { |
| 153 register FLAC__uint32 x; | 150 register FLAC__uint32 x; |
| 154 | 151 |
| 155 x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++
= (x >> 16) | (x << 16); | 152 x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++
= (x >> 16) | (x << 16); |
| 156 x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++
= (x >> 16) | (x << 16); | 153 x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++
= (x >> 16) | (x << 16); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void FLAC__MD5Init(FLAC__MD5Context *ctx) | 217 void FLAC__MD5Init(FLAC__MD5Context *ctx) |
| 221 { | 218 { |
| 222 ctx->buf[0] = 0x67452301; | 219 ctx->buf[0] = 0x67452301; |
| 223 ctx->buf[1] = 0xefcdab89; | 220 ctx->buf[1] = 0xefcdab89; |
| 224 ctx->buf[2] = 0x98badcfe; | 221 ctx->buf[2] = 0x98badcfe; |
| 225 ctx->buf[3] = 0x10325476; | 222 ctx->buf[3] = 0x10325476; |
| 226 | 223 |
| 227 ctx->bytes[0] = 0; | 224 ctx->bytes[0] = 0; |
| 228 ctx->bytes[1] = 0; | 225 ctx->bytes[1] = 0; |
| 229 | 226 |
| 230 » ctx->internal_buf = 0; | 227 » ctx->internal_buf.p8= 0; |
| 231 ctx->capacity = 0; | 228 ctx->capacity = 0; |
| 232 } | 229 } |
| 233 | 230 |
| 234 /* | 231 /* |
| 235 * Final wrapup - pad to 64-byte boundary with the bit pattern | 232 * Final wrapup - pad to 64-byte boundary with the bit pattern |
| 236 * 1 0* (64-bit count of bits processed, MSB-first) | 233 * 1 0* (64-bit count of bits processed, MSB-first) |
| 237 */ | 234 */ |
| 238 void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx) | 235 void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx) |
| 239 { | 236 { |
| 240 int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ | 237 int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 256 memset(p, 0, count); | 253 memset(p, 0, count); |
| 257 byteSwap(ctx->in, 14); | 254 byteSwap(ctx->in, 14); |
| 258 | 255 |
| 259 /* Append length in bits and transform */ | 256 /* Append length in bits and transform */ |
| 260 ctx->in[14] = ctx->bytes[0] << 3; | 257 ctx->in[14] = ctx->bytes[0] << 3; |
| 261 ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; | 258 ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; |
| 262 FLAC__MD5Transform(ctx->buf, ctx->in); | 259 FLAC__MD5Transform(ctx->buf, ctx->in); |
| 263 | 260 |
| 264 byteSwap(ctx->buf, 4); | 261 byteSwap(ctx->buf, 4); |
| 265 memcpy(digest, ctx->buf, 16); | 262 memcpy(digest, ctx->buf, 16); |
| 266 » if(0 != ctx->internal_buf) { | 263 » if (0 != ctx->internal_buf.p8) { |
| 267 » » free(ctx->internal_buf); | 264 » » free(ctx->internal_buf.p8); |
| 268 » » ctx->internal_buf = 0; | 265 » » ctx->internal_buf.p8= 0; |
| 269 ctx->capacity = 0; | 266 ctx->capacity = 0; |
| 270 } | 267 } |
| 271 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ | 268 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ |
| 272 } | 269 } |
| 273 | 270 |
| 274 /* | 271 /* |
| 275 * Convert the incoming audio signal to a byte stream | 272 * Convert the incoming audio signal to a byte stream |
| 276 */ | 273 */ |
| 277 static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], u
nsigned channels, unsigned samples, unsigned bytes_per_sample) | 274 static void format_input_(FLAC__multibyte *mbuf, const FLAC__int32 * const signa
l[], unsigned channels, unsigned samples, unsigned bytes_per_sample) |
| 278 { | 275 { |
| 276 FLAC__byte *buf_ = mbuf->p8; |
| 277 FLAC__int16 *buf16 = mbuf->p16; |
| 278 FLAC__int32 *buf32 = mbuf->p32; |
| 279 FLAC__int32 a_word; |
| 279 unsigned channel, sample; | 280 unsigned channel, sample; |
| 280 register FLAC__int32 a_word; | |
| 281 register FLAC__byte *buf_ = buf; | |
| 282 | 281 |
| 283 #if WORDS_BIGENDIAN | 282 » /* Storage in the output buffer, buf, is little endian. */ |
| 284 #else | 283 |
| 285 » if(channels == 2 && bytes_per_sample == 2) { | 284 #define BYTES_CHANNEL_SELECTOR(bytes, channels) (bytes * 100 + channels) |
| 286 » » FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1; | 285 |
| 287 » » memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples); | 286 » /* First do the most commonly used combinations. */ |
| 288 » » for(sample = 0; sample < samples; sample++, buf1_+=2) | 287 » switch (BYTES_CHANNEL_SELECTOR (bytes_per_sample, channels)) { |
| 289 » » » *buf1_ = (FLAC__int16)signal[1][sample]; | 288 » » /* One byte per sample. */ |
| 290 » } | 289 » » case (BYTES_CHANNEL_SELECTOR (1, 1)): |
| 291 » else if(channels == 1 && bytes_per_sample == 2) { | 290 » » » for (sample = 0; sample < samples; sample++) |
| 292 » » FLAC__int16 *buf1_ = (FLAC__int16*)buf_; | 291 » » » » *buf_++ = signal[0][sample]; |
| 293 » » for(sample = 0; sample < samples; sample++) | 292 » » » return; |
| 294 » » » *buf1_++ = (FLAC__int16)signal[0][sample]; | 293 |
| 295 » } | 294 » » case (BYTES_CHANNEL_SELECTOR (1, 2)): |
| 296 » else | 295 » » » for (sample = 0; sample < samples; sample++) { |
| 297 #endif | 296 » » » » *buf_++ = signal[0][sample]; |
| 298 » if(bytes_per_sample == 2) { | 297 » » » » *buf_++ = signal[1][sample]; |
| 299 » » if(channels == 2) { | 298 » » » } |
| 300 » » » for(sample = 0; sample < samples; sample++) { | 299 » » » return; |
| 300 |
| 301 » » case (BYTES_CHANNEL_SELECTOR (1, 4)): |
| 302 » » » for (sample = 0; sample < samples; sample++) { |
| 303 » » » » *buf_++ = signal[0][sample]; |
| 304 » » » » *buf_++ = signal[1][sample]; |
| 305 » » » » *buf_++ = signal[2][sample]; |
| 306 » » » » *buf_++ = signal[3][sample]; |
| 307 » » » } |
| 308 » » » return; |
| 309 |
| 310 » » case (BYTES_CHANNEL_SELECTOR (1, 6)): |
| 311 » » » for (sample = 0; sample < samples; sample++) { |
| 312 » » » » *buf_++ = signal[0][sample]; |
| 313 » » » » *buf_++ = signal[1][sample]; |
| 314 » » » » *buf_++ = signal[2][sample]; |
| 315 » » » » *buf_++ = signal[3][sample]; |
| 316 » » » » *buf_++ = signal[4][sample]; |
| 317 » » » » *buf_++ = signal[5][sample]; |
| 318 » » » } |
| 319 » » » return; |
| 320 |
| 321 » » case (BYTES_CHANNEL_SELECTOR (1, 8)): |
| 322 » » » for (sample = 0; sample < samples; sample++) { |
| 323 » » » » *buf_++ = signal[0][sample]; |
| 324 » » » » *buf_++ = signal[1][sample]; |
| 325 » » » » *buf_++ = signal[2][sample]; |
| 326 » » » » *buf_++ = signal[3][sample]; |
| 327 » » » » *buf_++ = signal[4][sample]; |
| 328 » » » » *buf_++ = signal[5][sample]; |
| 329 » » » » *buf_++ = signal[6][sample]; |
| 330 » » » » *buf_++ = signal[7][sample]; |
| 331 » » » } |
| 332 » » » return; |
| 333 |
| 334 » » /* Two bytes per sample. */ |
| 335 » » case (BYTES_CHANNEL_SELECTOR (2, 1)): |
| 336 » » » for (sample = 0; sample < samples; sample++) |
| 337 » » » » *buf16++ = H2LE_16(signal[0][sample]); |
| 338 » » » return; |
| 339 |
| 340 » » case (BYTES_CHANNEL_SELECTOR (2, 2)): |
| 341 » » » for (sample = 0; sample < samples; sample++) { |
| 342 » » » » *buf16++ = H2LE_16(signal[0][sample]); |
| 343 » » » » *buf16++ = H2LE_16(signal[1][sample]); |
| 344 » » » } |
| 345 » » » return; |
| 346 |
| 347 » » case (BYTES_CHANNEL_SELECTOR (2, 4)): |
| 348 » » » for (sample = 0; sample < samples; sample++) { |
| 349 » » » » *buf16++ = H2LE_16(signal[0][sample]); |
| 350 » » » » *buf16++ = H2LE_16(signal[1][sample]); |
| 351 » » » » *buf16++ = H2LE_16(signal[2][sample]); |
| 352 » » » » *buf16++ = H2LE_16(signal[3][sample]); |
| 353 » » » } |
| 354 » » » return; |
| 355 |
| 356 » » case (BYTES_CHANNEL_SELECTOR (2, 6)): |
| 357 » » » for (sample = 0; sample < samples; sample++) { |
| 358 » » » » *buf16++ = H2LE_16(signal[0][sample]); |
| 359 » » » » *buf16++ = H2LE_16(signal[1][sample]); |
| 360 » » » » *buf16++ = H2LE_16(signal[2][sample]); |
| 361 » » » » *buf16++ = H2LE_16(signal[3][sample]); |
| 362 » » » » *buf16++ = H2LE_16(signal[4][sample]); |
| 363 » » » » *buf16++ = H2LE_16(signal[5][sample]); |
| 364 » » » } |
| 365 » » » return; |
| 366 |
| 367 » » case (BYTES_CHANNEL_SELECTOR (2, 8)): |
| 368 » » » for (sample = 0; sample < samples; sample++) { |
| 369 » » » » *buf16++ = H2LE_16(signal[0][sample]); |
| 370 » » » » *buf16++ = H2LE_16(signal[1][sample]); |
| 371 » » » » *buf16++ = H2LE_16(signal[2][sample]); |
| 372 » » » » *buf16++ = H2LE_16(signal[3][sample]); |
| 373 » » » » *buf16++ = H2LE_16(signal[4][sample]); |
| 374 » » » » *buf16++ = H2LE_16(signal[5][sample]); |
| 375 » » » » *buf16++ = H2LE_16(signal[6][sample]); |
| 376 » » » » *buf16++ = H2LE_16(signal[7][sample]); |
| 377 » » » } |
| 378 » » » return; |
| 379 |
| 380 » » /* Three bytes per sample. */ |
| 381 » » case (BYTES_CHANNEL_SELECTOR (3, 1)): |
| 382 » » » for (sample = 0; sample < samples; sample++) { |
| 301 a_word = signal[0][sample]; | 383 a_word = signal[0][sample]; |
| 302 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 384 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 303 *buf_++ = (FLAC__byte)a_word; | |
| 304 a_word = signal[1][sample]; | |
| 305 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 385 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 306 *buf_++ = (FLAC__byte)a_word; | 386 *buf_++ = (FLAC__byte)a_word; |
| 307 } | 387 } |
| 308 » » } | 388 » » » return; |
| 309 » » else if(channels == 1) { | 389 |
| 310 » » » for(sample = 0; sample < samples; sample++) { | 390 » » case (BYTES_CHANNEL_SELECTOR (3, 2)): |
| 311 » » » » a_word = signal[0][sample]; | 391 » » » for (sample = 0; sample < samples; sample++) { |
| 312 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | |
| 313 » » » » *buf_++ = (FLAC__byte)a_word; | |
| 314 » » » } | |
| 315 » » } | |
| 316 » » else { | |
| 317 » » » for(sample = 0; sample < samples; sample++) { | |
| 318 » » » » for(channel = 0; channel < channels; channel++)
{ | |
| 319 » » » » » a_word = signal[channel][sample]; | |
| 320 » » » » » *buf_++ = (FLAC__byte)a_word; a_word >>=
8; | |
| 321 » » » » » *buf_++ = (FLAC__byte)a_word; | |
| 322 » » » » } | |
| 323 » » » } | |
| 324 » » } | |
| 325 » } | |
| 326 » else if(bytes_per_sample == 3) { | |
| 327 » » if(channels == 2) { | |
| 328 » » » for(sample = 0; sample < samples; sample++) { | |
| 329 a_word = signal[0][sample]; | 392 a_word = signal[0][sample]; |
| 330 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 393 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 331 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 394 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 332 *buf_++ = (FLAC__byte)a_word; | 395 *buf_++ = (FLAC__byte)a_word; |
| 333 a_word = signal[1][sample]; | 396 a_word = signal[1][sample]; |
| 334 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 397 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 335 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 398 *buf_++ = (FLAC__byte)a_word; a_word >>= 8; |
| 336 *buf_++ = (FLAC__byte)a_word; | 399 *buf_++ = (FLAC__byte)a_word; |
| 337 } | 400 } |
| 338 » » } | 401 » » » return; |
| 339 » » else if(channels == 1) { | 402 |
| 340 » » » for(sample = 0; sample < samples; sample++) { | 403 » » /* Four bytes per sample. */ |
| 341 » » » » a_word = signal[0][sample]; | 404 » » case (BYTES_CHANNEL_SELECTOR (4, 1)): |
| 342 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 405 » » » for (sample = 0; sample < samples; sample++) |
| 343 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | 406 » » » » *buf32++ = H2LE_32(signal[0][sample]); |
| 344 » » » » *buf_++ = (FLAC__byte)a_word; | 407 » » » return; |
| 408 |
| 409 » » case (BYTES_CHANNEL_SELECTOR (4, 2)): |
| 410 » » » for (sample = 0; sample < samples; sample++) { |
| 411 » » » » *buf32++ = H2LE_32(signal[0][sample]); |
| 412 » » » » *buf32++ = H2LE_32(signal[1][sample]); |
| 345 } | 413 } |
| 346 » » } | 414 » » » return; |
| 347 » » else { | 415 |
| 348 » » » for(sample = 0; sample < samples; sample++) { | 416 » » case (BYTES_CHANNEL_SELECTOR (4, 4)): |
| 349 » » » » for(channel = 0; channel < channels; channel++)
{ | 417 » » » for (sample = 0; sample < samples; sample++) { |
| 418 » » » » *buf32++ = H2LE_32(signal[0][sample]); |
| 419 » » » » *buf32++ = H2LE_32(signal[1][sample]); |
| 420 » » » » *buf32++ = H2LE_32(signal[2][sample]); |
| 421 » » » » *buf32++ = H2LE_32(signal[3][sample]); |
| 422 » » » } |
| 423 » » » return; |
| 424 |
| 425 » » case (BYTES_CHANNEL_SELECTOR (4, 6)): |
| 426 » » » for (sample = 0; sample < samples; sample++) { |
| 427 » » » » *buf32++ = H2LE_32(signal[0][sample]); |
| 428 » » » » *buf32++ = H2LE_32(signal[1][sample]); |
| 429 » » » » *buf32++ = H2LE_32(signal[2][sample]); |
| 430 » » » » *buf32++ = H2LE_32(signal[3][sample]); |
| 431 » » » » *buf32++ = H2LE_32(signal[4][sample]); |
| 432 » » » » *buf32++ = H2LE_32(signal[5][sample]); |
| 433 » » » } |
| 434 » » » return; |
| 435 |
| 436 » » case (BYTES_CHANNEL_SELECTOR (4, 8)): |
| 437 » » » for (sample = 0; sample < samples; sample++) { |
| 438 » » » » *buf32++ = H2LE_32(signal[0][sample]); |
| 439 » » » » *buf32++ = H2LE_32(signal[1][sample]); |
| 440 » » » » *buf32++ = H2LE_32(signal[2][sample]); |
| 441 » » » » *buf32++ = H2LE_32(signal[3][sample]); |
| 442 » » » » *buf32++ = H2LE_32(signal[4][sample]); |
| 443 » » » » *buf32++ = H2LE_32(signal[5][sample]); |
| 444 » » » » *buf32++ = H2LE_32(signal[6][sample]); |
| 445 » » » » *buf32++ = H2LE_32(signal[7][sample]); |
| 446 » » » } |
| 447 » » » return; |
| 448 |
| 449 » » default: |
| 450 » » » break; |
| 451 » } |
| 452 |
| 453 » /* General version. */ |
| 454 » switch (bytes_per_sample) { |
| 455 » » case 1: |
| 456 » » » for (sample = 0; sample < samples; sample++) |
| 457 » » » » for (channel = 0; channel < channels; channel++) |
| 458 » » » » » *buf_++ = signal[channel][sample]; |
| 459 » » » return; |
| 460 |
| 461 » » case 2: |
| 462 » » » for (sample = 0; sample < samples; sample++) |
| 463 » » » » for (channel = 0; channel < channels; channel++) |
| 464 » » » » » *buf16++ = H2LE_16(signal[channel][sampl
e]); |
| 465 » » » return; |
| 466 |
| 467 » » case 3: |
| 468 » » » for (sample = 0; sample < samples; sample++) |
| 469 » » » » for (channel = 0; channel < channels; channel++)
{ |
| 350 a_word = signal[channel][sample]; | 470 a_word = signal[channel][sample]; |
| 351 *buf_++ = (FLAC__byte)a_word; a_word >>=
8; | 471 *buf_++ = (FLAC__byte)a_word; a_word >>=
8; |
| 352 *buf_++ = (FLAC__byte)a_word; a_word >>=
8; | 472 *buf_++ = (FLAC__byte)a_word; a_word >>=
8; |
| 353 *buf_++ = (FLAC__byte)a_word; | 473 *buf_++ = (FLAC__byte)a_word; |
| 354 } | 474 } |
| 355 » » » } | 475 » » » return; |
| 356 » » } | 476 |
| 357 » } | 477 » » case 4: |
| 358 » else if(bytes_per_sample == 1) { | 478 » » » for (sample = 0; sample < samples; sample++) |
| 359 » » if(channels == 2) { | 479 » » » » for (channel = 0; channel < channels; channel++) |
| 360 » » » for(sample = 0; sample < samples; sample++) { | 480 » » » » » *buf32++ = H2LE_32(signal[channel][sampl
e]); |
| 361 » » » » a_word = signal[0][sample]; | 481 » » » return; |
| 362 » » » » *buf_++ = (FLAC__byte)a_word; | 482 |
| 363 » » » » a_word = signal[1][sample]; | 483 » » default: |
| 364 » » » » *buf_++ = (FLAC__byte)a_word; | 484 » » » break; |
| 365 » » » } | |
| 366 » » } | |
| 367 » » else if(channels == 1) { | |
| 368 » » » for(sample = 0; sample < samples; sample++) { | |
| 369 » » » » a_word = signal[0][sample]; | |
| 370 » » » » *buf_++ = (FLAC__byte)a_word; | |
| 371 » » » } | |
| 372 » » } | |
| 373 » » else { | |
| 374 » » » for(sample = 0; sample < samples; sample++) { | |
| 375 » » » » for(channel = 0; channel < channels; channel++)
{ | |
| 376 » » » » » a_word = signal[channel][sample]; | |
| 377 » » » » » *buf_++ = (FLAC__byte)a_word; | |
| 378 » » » » } | |
| 379 » » » } | |
| 380 » » } | |
| 381 » } | |
| 382 » else { /* bytes_per_sample == 4, maybe optimize more later */ | |
| 383 » » for(sample = 0; sample < samples; sample++) { | |
| 384 » » » for(channel = 0; channel < channels; channel++) { | |
| 385 » » » » a_word = signal[channel][sample]; | |
| 386 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | |
| 387 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | |
| 388 » » » » *buf_++ = (FLAC__byte)a_word; a_word >>= 8; | |
| 389 » » » » *buf_++ = (FLAC__byte)a_word; | |
| 390 » » » } | |
| 391 » » } | |
| 392 } | 485 } |
| 393 } | 486 } |
| 394 | 487 |
| 395 /* | 488 /* |
| 396 * Convert the incoming audio signal to a byte stream and FLAC__MD5Update it. | 489 * Convert the incoming audio signal to a byte stream and FLAC__MD5Update it. |
| 397 */ | 490 */ |
| 398 FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const
signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample) | 491 FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const
signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample) |
| 399 { | 492 { |
| 400 const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t
)bytes_per_sample; | 493 const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t
)bytes_per_sample; |
| 401 | 494 |
| 402 /* overflow check */ | 495 /* overflow check */ |
| 403 » if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample) | 496 » if ((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample) |
| 404 return false; | 497 return false; |
| 405 » if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samp
les) | 498 » if ((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)sam
ples) |
| 406 return false; | 499 return false; |
| 407 | 500 |
| 408 » if(ctx->capacity < bytes_needed) { | 501 » if (ctx->capacity < bytes_needed) { |
| 409 » » FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_
needed); | 502 » » FLAC__byte *tmp = realloc(ctx->internal_buf.p8, bytes_needed); |
| 410 » » if(0 == tmp) { | 503 » » if (0 == tmp) { |
| 411 » » » free(ctx->internal_buf); | 504 » » » free(ctx->internal_buf.p8); |
| 412 » » » if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(b
ytes_needed))) | 505 » » » if (0 == (ctx->internal_buf.p8= safe_malloc_(bytes_neede
d))) |
| 413 return false; | 506 return false; |
| 414 } | 507 } |
| 415 » » ctx->internal_buf = tmp; | 508 » » else |
| 509 » » » ctx->internal_buf.p8= tmp; |
| 416 ctx->capacity = bytes_needed; | 510 ctx->capacity = bytes_needed; |
| 417 } | 511 } |
| 418 | 512 |
| 419 » format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sa
mple); | 513 » format_input_(&ctx->internal_buf, signal, channels, samples, bytes_per_s
ample); |
| 420 | 514 |
| 421 » FLAC__MD5Update(ctx, ctx->internal_buf, (unsigned)bytes_needed); | 515 » FLAC__MD5Update(ctx, ctx->internal_buf.p8, bytes_needed); |
| 422 | 516 |
| 423 return true; | 517 return true; |
| 424 } | 518 } |
| OLD | NEW |