-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 9d1ff8c..1989b4a 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -361,243 +361,243 @@ int LibMadPlugin::http_open(const QString& path ) { | |||
361 | http_request[4] = 0; | 361 | http_request[4] = 0; |
362 | if (strcmp(http_request, "200 ")) { | 362 | if (strcmp(http_request, "200 ")) { |
363 | fprintf(stderr, "http_open: "); | 363 | fprintf(stderr, "http_open: "); |
364 | do { | 364 | do { |
365 | read(tcp_sock, &c, sizeof(char)); | 365 | read(tcp_sock, &c, sizeof(char)); |
366 | fprintf(stderr, "%c", c); | 366 | fprintf(stderr, "%c", c); |
367 | } while (c != '\r'); | 367 | } while (c != '\r'); |
368 | fprintf(stderr, "\n"); | 368 | fprintf(stderr, "\n"); |
369 | return (0); | 369 | return (0); |
370 | } | 370 | } |
371 | #endif | 371 | #endif |
372 | 372 | ||
373 | QString name; | 373 | QString name; |
374 | QString genre; | 374 | QString genre; |
375 | QString bitrate; | 375 | QString bitrate; |
376 | QString url; | 376 | QString url; |
377 | QString message = tr("Info: "); | 377 | QString message = tr("Info: "); |
378 | do { | 378 | do { |
379 | 379 | ||
380 | int len; | 380 | int len; |
381 | 381 | ||
382 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); | 382 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); |
383 | 383 | ||
384 | if (len == -1) { | 384 | if (len == -1) { |
385 | qDebug( "http_open: "+ QString(strerror(errno)) +"\n"); | 385 | // qDebug( "http_open: "+ QString(strerror(errno)) +"\n"); |
386 | return 0; | 386 | return 0; |
387 | } | 387 | } |
388 | 388 | ||
389 | if (QString(http_request).left(9) == "Location:") { | 389 | if (QString(http_request).left(9) == "Location:") { |
390 | /* redirect */ | 390 | /* redirect */ |
391 | ::close(tcp_sock); | 391 | ::close(tcp_sock); |
392 | http_request[strlen(http_request) - 1] = '\0'; | 392 | http_request[strlen(http_request) - 1] = '\0'; |
393 | return http_open(&http_request[10]); | 393 | return http_open(&http_request[10]); |
394 | } | 394 | } |
395 | 395 | ||
396 | if (QString(http_request).left(4) == "ICY ") { | 396 | if (QString(http_request).left(4) == "ICY ") { |
397 | /* This is shoutcast/icecast streaming */ | 397 | /* This is shoutcast/icecast streaming */ |
398 | if (strncmp(http_request + 4, "200 ", 4)) { | 398 | if (strncmp(http_request + 4, "200 ", 4)) { |
399 | qDebug("http_open: " + QString(http_request) + "\n"); | 399 | // qDebug("http_open: " + QString(http_request) + "\n"); |
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | } else if (QString(http_request).left(4) == "icy-") { | 402 | } else if (QString(http_request).left(4) == "icy-") { |
403 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ | 403 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ |
404 | if ( QString( http_request ).left( 8 ) == "icy-name" ) { | 404 | if ( QString( http_request ).left( 8 ) == "icy-name" ) { |
405 | name = tr("Name: ") + QString(http_request).mid(9, (QString(http_request).length())- 9 ); | 405 | name = tr("Name: ") + QString(http_request).mid(9, (QString(http_request).length())- 9 ); |
406 | } else if ( QString( http_request ).left( 9 ) == "icy-genre" ) { | 406 | } else if ( QString( http_request ).left( 9 ) == "icy-genre" ) { |
407 | genre = tr("Genre: ") + QString(http_request).mid(10, (QString(http_request).length())-10 ); | 407 | genre = tr("Genre: ") + QString(http_request).mid(10, (QString(http_request).length())-10 ); |
408 | } else if ( QString( http_request ).left( 6 ) == "icy-br" ) { | 408 | } else if ( QString( http_request ).left( 6 ) == "icy-br" ) { |
409 | bitrate = tr("Bitrate: ") + QString(http_request).mid(7, (QString(http_request).length())- 7 ); | 409 | bitrate = tr("Bitrate: ") + QString(http_request).mid(7, (QString(http_request).length())- 7 ); |
410 | } else if ( QString( http_request ).left( 7 ) == "icy-url" ) { | 410 | } else if ( QString( http_request ).left( 7 ) == "icy-url" ) { |
411 | url = tr("URL: ") + QString(http_request).mid(8, (QString(http_request).length())- 8 ); | 411 | url = tr("URL: ") + QString(http_request).mid(8, (QString(http_request).length())- 8 ); |
412 | } else if ( QString( http_request ).left( 10 ) == "icy-notice" ) { | 412 | } else if ( QString( http_request ).left( 10 ) == "icy-notice" ) { |
413 | message += QString(http_request).mid(11, QString(http_request).length()-11 ) ; | 413 | message += QString(http_request).mid(11, QString(http_request).length()-11 ) ; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | } while (strcmp(http_request, "\n") != 0); | 416 | } while (strcmp(http_request, "\n") != 0); |
417 | 417 | ||
418 | info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " ); | 418 | info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " ); |
419 | 419 | ||
420 | qDebug("Stream info: " + info); | 420 | // qDebug("Stream info: " + info); |
421 | 421 | ||
422 | return (tcp_sock); | 422 | return (tcp_sock); |
423 | } | 423 | } |
424 | 424 | ||
425 | 425 | ||
426 | 426 | ||
427 | bool LibMadPlugin::open( const QString& path ) { | 427 | bool LibMadPlugin::open( const QString& path ) { |
428 | debugMsg( "LibMadPlugin::open" ); | 428 | debugMsg( "LibMadPlugin::open" ); |
429 | Config cfg("OpiePlayer"); | 429 | Config cfg("OpiePlayer"); |
430 | cfg.setGroup("Options"); | 430 | cfg.setGroup("Options"); |
431 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); | 431 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); |
432 | qDebug("buffer size is %d", bufferSize); | 432 | // qDebug("buffer size is %d", bufferSize); |
433 | d->bad_last_frame = 0; | 433 | d->bad_last_frame = 0; |
434 | d->flush = TRUE; | 434 | d->flush = TRUE; |
435 | info = QString( "" ); | 435 | info = QString( "" ); |
436 | 436 | ||
437 | //qDebug( "Opening %s", path.latin1() ); | 437 | //qDebug( "Opening %s", path.latin1() ); |
438 | 438 | ||
439 | if (path.left( 4 ) == "http" ) { | 439 | if (path.left( 4 ) == "http" ) { |
440 | // in case of any error we get 0 here | 440 | // in case of any error we get 0 here |
441 | if ( !(http_open(path) == 0) ) { | 441 | if ( !(http_open(path) == 0) ) { |
442 | d->input.fd = http_open(path); | 442 | d->input.fd = http_open(path); |
443 | } else { | 443 | } else { |
444 | return FALSE; | 444 | return FALSE; |
445 | } | 445 | } |
446 | } else { | 446 | } else { |
447 | d->input.path = path.latin1(); | 447 | d->input.path = path.latin1(); |
448 | d->input.fd = ::open( d->input.path, O_RDONLY ); | 448 | d->input.fd = ::open( d->input.path, O_RDONLY ); |
449 | // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams | 449 | // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams |
450 | printID3Tags(); | 450 | printID3Tags(); |
451 | } | 451 | } |
452 | if (d->input.fd == -1) { | 452 | if (d->input.fd == -1) { |
453 | qDebug("error opening %s", d->input.path ); | 453 | // qDebug("error opening %s", d->input.path ); |
454 | return FALSE; | 454 | return FALSE; |
455 | } | 455 | } |
456 | 456 | ||
457 | struct stat stat; | 457 | struct stat stat; |
458 | if (fstat(d->input.fd, &stat) == -1) { | 458 | if (fstat(d->input.fd, &stat) == -1) { |
459 | qDebug("error calling fstat"); return FALSE; | 459 | // qDebug("error calling fstat"); return FALSE; |
460 | } | 460 | } |
461 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) | 461 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) |
462 | d->input.fileLength = stat.st_size; | 462 | d->input.fileLength = stat.st_size; |
463 | else | 463 | else |
464 | d->input.fileLength = 0; | 464 | d->input.fileLength = 0; |
465 | 465 | ||
466 | #if defined(HAVE_MMAP) | 466 | #if defined(HAVE_MMAP) |
467 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { | 467 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { |
468 | d->input.length = stat.st_size; | 468 | d->input.length = stat.st_size; |
469 | d->input.fdm = map_file(d->input.fd, &d->input.length); | 469 | d->input.fdm = map_file(d->input.fd, &d->input.length); |
470 | if (d->input.fdm == 0) { | 470 | if (d->input.fdm == 0) { |
471 | qDebug("error mmapping file"); return FALSE; | 471 | // qDebug("error mmapping file"); return FALSE; |
472 | } | 472 | } |
473 | d->input.data = (unsigned char *)d->input.fdm; | 473 | d->input.data = (unsigned char *)d->input.fdm; |
474 | } | 474 | } |
475 | #endif | 475 | #endif |
476 | 476 | ||
477 | if (d->input.data == 0) { | 477 | if (d->input.data == 0) { |
478 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); | 478 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); |
479 | if (d->input.data == 0) { | 479 | if (d->input.data == 0) { |
480 | qDebug("error allocating input buffer"); | 480 | // qDebug("error allocating input buffer"); |
481 | return FALSE; | 481 | return FALSE; |
482 | } | 482 | } |
483 | d->input.length = 0; | 483 | d->input.length = 0; |
484 | } | 484 | } |
485 | 485 | ||
486 | d->input.eof = 0; | 486 | d->input.eof = 0; |
487 | 487 | ||
488 | mad_stream_init(&d->stream); | 488 | mad_stream_init(&d->stream); |
489 | mad_frame_init(&d->frame); | 489 | mad_frame_init(&d->frame); |
490 | mad_synth_init(&d->synth); | 490 | mad_synth_init(&d->synth); |
491 | 491 | ||
492 | return TRUE; | 492 | return TRUE; |
493 | } | 493 | } |
494 | 494 | ||
495 | 495 | ||
496 | bool LibMadPlugin::close() { | 496 | bool LibMadPlugin::close() { |
497 | debugMsg( "LibMadPlugin::close" ); | 497 | debugMsg( "LibMadPlugin::close" ); |
498 | 498 | ||
499 | int result = TRUE; | 499 | int result = TRUE; |
500 | 500 | ||
501 | mad_synth_finish(&d->synth); | 501 | mad_synth_finish(&d->synth); |
502 | mad_frame_finish(&d->frame); | 502 | mad_frame_finish(&d->frame); |
503 | mad_stream_finish(&d->stream); | 503 | mad_stream_finish(&d->stream); |
504 | 504 | ||
505 | #if defined(HAVE_MMAP) | 505 | #if defined(HAVE_MMAP) |
506 | if (d->input.fdm) { | 506 | if (d->input.fdm) { |
507 | if (unmap_file(d->input.fdm, d->input.length) == -1) { | 507 | if (unmap_file(d->input.fdm, d->input.length) == -1) { |
508 | qDebug("error munmapping file"); | 508 | // qDebug("error munmapping file"); |
509 | result = FALSE; | 509 | result = FALSE; |
510 | } | 510 | } |
511 | d->input.fdm = 0; | 511 | d->input.fdm = 0; |
512 | d->input.data = 0; | 512 | d->input.data = 0; |
513 | } | 513 | } |
514 | #endif | 514 | #endif |
515 | 515 | ||
516 | if (d->input.data) { | 516 | if (d->input.data) { |
517 | free(d->input.data); | 517 | free(d->input.data); |
518 | d->input.data = 0; | 518 | d->input.data = 0; |
519 | } | 519 | } |
520 | 520 | ||
521 | if (::close(d->input.fd) == -1) { | 521 | if (::close(d->input.fd) == -1) { |
522 | qDebug("error closing file %s", d->input.path); | 522 | // qDebug("error closing file %s", d->input.path); |
523 | result = FALSE; | 523 | result = FALSE; |
524 | } | 524 | } |
525 | 525 | ||
526 | d->input.fd = 0; | 526 | d->input.fd = 0; |
527 | 527 | ||
528 | return result; | 528 | return result; |
529 | } | 529 | } |
530 | 530 | ||
531 | 531 | ||
532 | bool LibMadPlugin::isOpen() { | 532 | bool LibMadPlugin::isOpen() { |
533 | debugMsg( "LibMadPlugin::isOpen" ); | 533 | debugMsg( "LibMadPlugin::isOpen" ); |
534 | return ( d->input.fd != 0 ); | 534 | return ( d->input.fd != 0 ); |
535 | } | 535 | } |
536 | 536 | ||
537 | 537 | ||
538 | int LibMadPlugin::audioStreams() { | 538 | int LibMadPlugin::audioStreams() { |
539 | debugMsg( "LibMadPlugin::audioStreams" ); | 539 | debugMsg( "LibMadPlugin::audioStreams" ); |
540 | return 1; | 540 | return 1; |
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
544 | int LibMadPlugin::audioChannels( int ) { | 544 | int LibMadPlugin::audioChannels( int ) { |
545 | debugMsg( "LibMadPlugin::audioChannels" ); | 545 | debugMsg( "LibMadPlugin::audioChannels" ); |
546 | /* | 546 | /* |
547 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 547 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
548 | qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); | 548 | qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); |
549 | return d->frame.header.mode > 0 ? 2 : 1; | 549 | return d->frame.header.mode > 0 ? 2 : 1; |
550 | */ | 550 | */ |
551 | return 2; | 551 | return 2; |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | int LibMadPlugin::audioFrequency( int ) { | 555 | int LibMadPlugin::audioFrequency( int ) { |
556 | debugMsg( "LibMadPlugin::audioFrequency" ); | 556 | debugMsg( "LibMadPlugin::audioFrequency" ); |
557 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 557 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
558 | qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); | 558 | // qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); |
559 | return d->frame.header.samplerate; | 559 | return d->frame.header.samplerate; |
560 | } | 560 | } |
561 | 561 | ||
562 | 562 | ||
563 | int LibMadPlugin::audioSamples( int ) { | 563 | int LibMadPlugin::audioSamples( int ) { |
564 | debugMsg( "LibMadPlugin::audioSamples" ); | 564 | debugMsg( "LibMadPlugin::audioSamples" ); |
565 | 565 | ||
566 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 566 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
567 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); | 567 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); |
568 | /* | 568 | /* |
569 | qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, | 569 | qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, |
570 | d->frame.header.samplerate ); | 570 | d->frame.header.samplerate ); |
571 | return d->frame.header.duration.seconds * d->frame.header.samplerate; | 571 | return d->frame.header.duration.seconds * d->frame.header.samplerate; |
572 | */ | 572 | */ |
573 | if ( d->frame.header.bitrate == 0 ) | 573 | if ( d->frame.header.bitrate == 0 ) |
574 | return 0; | 574 | return 0; |
575 | int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate; | 575 | int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate; |
576 | 576 | ||
577 | qDebug( "LibMadPlugin::audioSamples: %i * %i * 8 / %i", (int)d->input.fileLength, | 577 | // qDebug( "LibMadPlugin::audioSamples: %i * %i * 8 / %i", (int)d->input.fileLength, |
578 | (int)d->frame.header.samplerate, (int)d->frame.header.bitrate ); | 578 | // (int)d->frame.header.samplerate, (int)d->frame.header.bitrate ); |
579 | qDebug( "LibMadPlugin::audioSamples: %i", samples ); | 579 | // qDebug( "LibMadPlugin::audioSamples: %i", samples ); |
580 | 580 | ||
581 | return samples; | 581 | return samples; |
582 | 582 | ||
583 | // return 10000000; | 583 | // return 10000000; |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | bool LibMadPlugin::audioSetSample( long, int ) { | 587 | bool LibMadPlugin::audioSetSample( long, int ) { |
588 | debugMsg( "LibMadPlugin::audioSetSample" ); | 588 | debugMsg( "LibMadPlugin::audioSetSample" ); |
589 | 589 | ||
590 | // long totalSamples = audioSamples(0); | 590 | // long totalSamples = audioSamples(0); |
591 | // if ( totalSamples <= 1 ) | 591 | // if ( totalSamples <= 1 ) |
592 | // return FALSE; | 592 | // return FALSE; |
593 | 593 | ||
594 | // // Seek to requested position | 594 | // // Seek to requested position |
595 | // qDebug( "seek pos: %i", (int)((double)pos * d->input.fileLength / totalSamples) ); | 595 | // qDebug( "seek pos: %i", (int)((double)pos * d->input.fileLength / totalSamples) ); |
596 | // ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET ); | 596 | // ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET ); |
597 | // mad_stream_sync(&d->stream); | 597 | // mad_stream_sync(&d->stream); |
598 | 598 | ||
599 | // mad_stream_init(&d->stream); | 599 | // mad_stream_init(&d->stream); |
600 | // mad_frame_init(&d->frame); | 600 | // mad_frame_init(&d->frame); |
601 | // mad_synth_init(&d->synth); | 601 | // mad_synth_init(&d->synth); |
602 | 602 | ||
603 | // return TRUE; | 603 | // return TRUE; |
@@ -659,49 +659,49 @@ bool LibMadPlugin::read() { | |||
659 | if (d->input.fdm == 0) { | 659 | if (d->input.fdm == 0) { |
660 | d->input.data = 0; | 660 | d->input.data = 0; |
661 | return FALSE; | 661 | return FALSE; |
662 | } | 662 | } |
663 | 663 | ||
664 | d->input.data = (unsigned char *)d->input.fdm; | 664 | d->input.data = (unsigned char *)d->input.fdm; |
665 | } | 665 | } |
666 | 666 | ||
667 | mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); | 667 | mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); |
668 | 668 | ||
669 | } else | 669 | } else |
670 | #endif | 670 | #endif |
671 | { | 671 | { |
672 | if (d->stream.next_frame) { | 672 | if (d->stream.next_frame) { |
673 | memmove(d->input.data, d->stream.next_frame, | 673 | memmove(d->input.data, d->stream.next_frame, |
674 | d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); | 674 | d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); |
675 | } | 675 | } |
676 | 676 | ||
677 | do { | 677 | do { |
678 | len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* MPEG_BUFFER_SIZE*/ - d->input.length); | 678 | len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* MPEG_BUFFER_SIZE*/ - d->input.length); |
679 | } | 679 | } |
680 | while (len == -1 && errno == EINTR); | 680 | while (len == -1 && errno == EINTR); |
681 | 681 | ||
682 | if (len == -1) { | 682 | if (len == -1) { |
683 | qDebug("error reading audio"); | 683 | // qDebug("error reading audio"); |
684 | return FALSE; | 684 | return FALSE; |
685 | } | 685 | } |
686 | else if (len == 0) { | 686 | else if (len == 0) { |
687 | d->input.eof = 1; | 687 | d->input.eof = 1; |
688 | 688 | ||
689 | assert(bufferSize /*MPEG_BUFFER_SIZE*/ - d->input.length >= MAD_BUFFER_GUARD); | 689 | assert(bufferSize /*MPEG_BUFFER_SIZE*/ - d->input.length >= MAD_BUFFER_GUARD); |
690 | 690 | ||
691 | while (len < MAD_BUFFER_GUARD) | 691 | while (len < MAD_BUFFER_GUARD) |
692 | d->input.data[d->input.length + len++] = 0; | 692 | d->input.data[d->input.length + len++] = 0; |
693 | } | 693 | } |
694 | 694 | ||
695 | mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); | 695 | mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); |
696 | } | 696 | } |
697 | 697 | ||
698 | return TRUE; | 698 | return TRUE; |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | static mad_fixed_t left_err, right_err; | 702 | static mad_fixed_t left_err, right_err; |
703 | static const int bits = 16; | 703 | static const int bits = 16; |
704 | static const int shift = MAD_F_FRACBITS + 1 - bits; | 704 | static const int shift = MAD_F_FRACBITS + 1 - bits; |
705 | 705 | ||
706 | 706 | ||
707 | inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) { | 707 | inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) { |
@@ -737,49 +737,49 @@ bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { | |||
737 | int offset = buffered; | 737 | int offset = buffered; |
738 | samplesMade = 0; | 738 | samplesMade = 0; |
739 | 739 | ||
740 | static int maxBuffered = 8000; // 65536; | 740 | static int maxBuffered = 8000; // 65536; |
741 | 741 | ||
742 | if ( samples > maxBuffered ) { | 742 | if ( samples > maxBuffered ) { |
743 | samples = maxBuffered; | 743 | samples = maxBuffered; |
744 | } | 744 | } |
745 | 745 | ||
746 | if ( d->flush ) { | 746 | if ( d->flush ) { |
747 | buffered = 0; | 747 | buffered = 0; |
748 | offset = 0; | 748 | offset = 0; |
749 | d->flush = FALSE; | 749 | d->flush = FALSE; |
750 | } | 750 | } |
751 | 751 | ||
752 | while ( buffered < maxBuffered ) { | 752 | while ( buffered < maxBuffered ) { |
753 | 753 | ||
754 | while (mad_frame_decode(&d->frame, &d->stream) == -1) { | 754 | while (mad_frame_decode(&d->frame, &d->stream) == -1) { |
755 | if (!MAD_RECOVERABLE(d->stream.error)) { | 755 | if (!MAD_RECOVERABLE(d->stream.error)) { |
756 | debugMsg( "feed me" ); | 756 | debugMsg( "feed me" ); |
757 | return FALSE; // Feed me | 757 | return FALSE; // Feed me |
758 | } | 758 | } |
759 | if ( d->stream.error == MAD_ERROR_BADCRC ) { | 759 | if ( d->stream.error == MAD_ERROR_BADCRC ) { |
760 | mad_frame_mute(&d->frame); | 760 | mad_frame_mute(&d->frame); |
761 | qDebug( "error decoding, bad crc" ); | 761 | // qDebug( "error decoding, bad crc" ); |
762 | } | 762 | } |
763 | } | 763 | } |
764 | 764 | ||
765 | mad_synth_frame(&d->synth, &d->frame); | 765 | mad_synth_frame(&d->synth, &d->frame); |
766 | int decodedSamples = d->synth.pcm.length; | 766 | int decodedSamples = d->synth.pcm.length; |
767 | memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); | 767 | memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); |
768 | if ( d->synth.pcm.channels == 2 ) | 768 | if ( d->synth.pcm.channels == 2 ) |
769 | memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); | 769 | memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); |
770 | offset += decodedSamples; | 770 | offset += decodedSamples; |
771 | buffered += decodedSamples; | 771 | buffered += decodedSamples; |
772 | } | 772 | } |
773 | 773 | ||
774 | //qApp->processEvents(); | 774 | //qApp->processEvents(); |
775 | audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); | 775 | audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); |
776 | // audio_pcm( output, samples, buffer[1], buffer[0] ); | 776 | // audio_pcm( output, samples, buffer[1], buffer[0] ); |
777 | // audio_pcm( output, samples, buffer[0], buffer[1] ); | 777 | // audio_pcm( output, samples, buffer[0], buffer[1] ); |
778 | samplesMade = samples; | 778 | samplesMade = samples; |
779 | memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); | 779 | memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); |
780 | if ( d->synth.pcm.channels == 2 ) { | 780 | if ( d->synth.pcm.channels == 2 ) { |
781 | memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); | 781 | memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); |
782 | } | 782 | } |
783 | buffered -= samples; | 783 | buffered -= samples; |
784 | 784 | ||
785 | return TRUE; | 785 | return TRUE; |
@@ -800,70 +800,70 @@ bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long sampl | |||
800 | if ( !read() ) { | 800 | if ( !read() ) { |
801 | return FALSE; | 801 | return FALSE; |
802 | } | 802 | } |
803 | 803 | ||
804 | needInput = FALSE; | 804 | needInput = FALSE; |
805 | 805 | ||
806 | if ( decode( output, samples, samplesMade ) ) | 806 | if ( decode( output, samples, samplesMade ) ) |
807 | return TRUE; | 807 | return TRUE; |
808 | else | 808 | else |
809 | needInput = TRUE; | 809 | needInput = TRUE; |
810 | } | 810 | } |
811 | while ( ( samplesMade < samples ) && ( !d->input.eof ) ); | 811 | while ( ( samplesMade < samples ) && ( !d->input.eof ) ); |
812 | 812 | ||
813 | return FALSE; | 813 | return FALSE; |
814 | } | 814 | } |
815 | 815 | ||
816 | 816 | ||
817 | double LibMadPlugin::getTime() { | 817 | double LibMadPlugin::getTime() { |
818 | debugMsg( "LibMadPlugin::getTime" ); | 818 | debugMsg( "LibMadPlugin::getTime" ); |
819 | return 0.0; | 819 | return 0.0; |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | void LibMadPlugin::printID3Tags() { | 823 | void LibMadPlugin::printID3Tags() { |
824 | qDebug( "LibMadPlugin::printID3Tags" ); | 824 | // qDebug( "LibMadPlugin::printID3Tags" ); |
825 | 825 | ||
826 | char id3v1[128 + 1]; | 826 | char id3v1[128 + 1]; |
827 | 827 | ||
828 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { | 828 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { |
829 | qDebug( "error seeking to id3 tags" ); | 829 | // qDebug( "error seeking to id3 tags" ); |
830 | return; | 830 | return; |
831 | } | 831 | } |
832 | 832 | ||
833 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { | 833 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { |
834 | qDebug( "error reading in id3 tags" ); | 834 | // qDebug( "error reading in id3 tags" ); |
835 | return; | 835 | return; |
836 | } | 836 | } |
837 | 837 | ||
838 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { | 838 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { |
839 | debugMsg( "sorry, no id3 tags" ); | 839 | debugMsg( "sorry, no id3 tags" ); |
840 | } else { | 840 | } else { |
841 | int len[5] = { 30, 30, 30, 4, 30 }; | 841 | int len[5] = { 30, 30, 30, 4, 30 }; |
842 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; | 842 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; |
843 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; | 843 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; |
844 | qDebug( "ID3 tags in file:" ); | 844 | // qDebug( "ID3 tags in file:" ); |
845 | info = ""; | 845 | info = ""; |
846 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { | 846 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { |
847 | char push = *ptr2; | 847 | char push = *ptr2; |
848 | *ptr2 = '\0'; | 848 | *ptr2 = '\0'; |
849 | char *ptr3 = ptr2; | 849 | char *ptr3 = ptr2; |
850 | while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; | 850 | while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; |
851 | char push2 = *ptr3; *ptr3 = '\0'; | 851 | char push2 = *ptr3; *ptr3 = '\0'; |
852 | if ( strcmp( ptr, "" ) ) { | 852 | if ( strcmp( ptr, "" ) ) { |
853 | if( ((QString)ptr).find(" ") == -1) // don't add anything that has blanks | 853 | if( ((QString)ptr).find(" ") == -1) // don't add anything that has blanks |
854 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; | 854 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; |
855 | } | 855 | } |
856 | // qDebug( info.latin1() ); | 856 | // qDebug( info.latin1() ); |
857 | *ptr3 = push2; | 857 | *ptr3 = push2; |
858 | *ptr2 = push; | 858 | *ptr2 = push; |
859 | } | 859 | } |
860 | if (id3v1[126] == 0 && id3v1[127] != 0) | 860 | if (id3v1[126] == 0 && id3v1[127] != 0) |
861 | info += tr( ", Track: " ) + id3v1[127]; | 861 | info += tr( ", Track: " ) + id3v1[127]; |
862 | } | 862 | } |
863 | 863 | ||
864 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { | 864 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { |
865 | qDebug( "error seeking back to beginning" ); | 865 | // qDebug( "error seeking back to beginning" ); |
866 | return; | 866 | return; |
867 | } | 867 | } |
868 | } | 868 | } |
869 | 869 | ||