44 bit difference

View: New views
5 Messages — Rating Filter:   Alert me  

44 bit difference

by Cuke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

my extracted audio track differ from the cd-paranoia's one of 44bit.My track isn't played either..this is the i use for extraction. the qdebug() function is just for display debug info in qt project. where i'm mistaking?

cdrom_drive_t *d = NULL;
    char **ppsz_cd_drives;

    ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);

    if (ppsz_cd_drives) {
        d=cdda_identify(*ppsz_cd_drives, 1, NULL);
    }else{
        qDebug() << "Unable to access to a cdrom with audio cd in it";
        return;
    }

    cdio_free_device_list(ppsz_cd_drives);

    if ( !d ) {
        qDebug() << "Unable to identify audio CD disc.\n";
        return;
    }

    cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);

    if ( 0 != cdda_open(d) ) {
        qDebug() << "Unable to open disc.\n";
        return;
    }

    cdrom_paranoia_t* p = cdio_paranoia_init(d);
    lsn_t i_first_lsn = cdda_disc_firstsector(d);

    if ( -1 == i_first_lsn ) {
      qDebug() << "Trouble getting starting LSN\n";
    }
    else {
        lsn_t   i_cursor;
        track_t i_track    = cdda_sector_gettrack(d, i_first_lsn);
        lsn_t   i_last_lsn = cdda_track_lastsector(d, i_track);

        //paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
        paranoia_seek(p, i_first_lsn, SEEK_SET);

        qDebug() << i_first_lsn << "-" << i_last_lsn;

        QFile file(tr("outtrack.wav"));
        if(!file.open(QIODevice::WriteOnly|QIODevice::Append)){
            qDebug() << "impossibile aprire il file di scrittura";
        }
        for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {

            int16_t *p_readbuf=paranoia_read(p, NULL);
            char *psz_err=cdda_errors(d);
            char *psz_mes=cdda_messages(d);

            if (psz_mes || psz_err)
                qDebug() << psz_err << psz_mes;
            if (psz_err) free(psz_err);
            if (psz_mes) free(psz_mes);
            if( !p_readbuf ) {
                qDebug() << "paranoia read error. Stopping.\n";
                break;
            }

            char *temp= (char*) p_readbuf;
            file.write(temp,(qint64)CDIO_CD_FRAMESIZE_RAW);
        }
        file.close();


        qDebug() << i_first_lsn << "\t" << i_last_lsn ;
        qDebug() << cdda_track_firstsector(d,i_track);
    }
    paranoia_free(p);

    cdda_close(d);

    return;

Re: 44 bit difference

by Cuke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

if you need more info i'm here!
Cuke wrote:
my extracted audio track differ from the cd-paranoia's one of 44bit.My track isn't played either..this is the i use for extraction. the qdebug() function is just for display debug info in qt project. where i'm mistaking?

cdrom_drive_t *d = NULL;
    char **ppsz_cd_drives;

    ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);

    if (ppsz_cd_drives) {
        d=cdda_identify(*ppsz_cd_drives, 1, NULL);
    }else{
        qDebug() << "Unable to access to a cdrom with audio cd in it";
        return;
    }

    cdio_free_device_list(ppsz_cd_drives);

    if ( !d ) {
        qDebug() << "Unable to identify audio CD disc.\n";
        return;
    }

    cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);

    if ( 0 != cdda_open(d) ) {
        qDebug() << "Unable to open disc.\n";
        return;
    }

    cdrom_paranoia_t* p = cdio_paranoia_init(d);
    lsn_t i_first_lsn = cdda_disc_firstsector(d);

    if ( -1 == i_first_lsn ) {
      qDebug() << "Trouble getting starting LSN\n";
    }
    else {
        lsn_t   i_cursor;
        track_t i_track    = cdda_sector_gettrack(d, i_first_lsn);
        lsn_t   i_last_lsn = cdda_track_lastsector(d, i_track);

        //paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
        paranoia_seek(p, i_first_lsn, SEEK_SET);

        qDebug() << i_first_lsn << "-" << i_last_lsn;

        QFile file(tr("outtrack.wav"));
        if(!file.open(QIODevice::WriteOnly|QIODevice::Append)){
            qDebug() << "impossibile aprire il file di scrittura";
        }
        for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {

            int16_t *p_readbuf=paranoia_read(p, NULL);
            char *psz_err=cdda_errors(d);
            char *psz_mes=cdda_messages(d);

            if (psz_mes || psz_err)
                qDebug() << psz_err << psz_mes;
            if (psz_err) free(psz_err);
            if (psz_mes) free(psz_mes);
            if( !p_readbuf ) {
                qDebug() << "paranoia read error. Stopping.\n";
                break;
            }

            char *temp= (char*) p_readbuf;
            file.write(temp,(qint64)CDIO_CD_FRAMESIZE_RAW);
        }
        file.close();


        qDebug() << i_first_lsn << "\t" << i_last_lsn ;
        qDebug() << cdda_track_firstsector(d,i_track);
    }
    paranoia_free(p);

    cdda_close(d);

    return;

Re: 44 bit difference

by Cuke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok so with the help of rocky i found that my program i post you didn't add the wav header. So i just add this lines of code after the OUTFILE open:

        //Get the track size in bytes and conver
        int bytes= ( i_last_lsn - i_first_lsn + 1 ) * CDIO_CD_FRAMESIZE_RAW;
        cout << "Nr Bytes:" << bytes+44 << endl;
       
        //Open the output file
        ofstream outfile ("temp.wav",ofstream::binary | ofstream::app | ofstream::out);
       
        //Waw format header specification
        int waweChunkLength=bytes+44-8;
        int fmtChunkLength=16;
        int compressionCode=1;
        int numberOfChannels=2;
        int sampleRate=44100;
        int blockAlign=44100*2*2;
        int significantBps=4;
        int extraFormatBytes=16;
       
        outfile.write("RIFF",4);
        outfile.write((char*)&waweChunkLength,4);
        outfile.write("WAVEfmt ",8);
        outfile.write((char*)&fmtChunkLength,4);
        outfile.write((char*)&compressionCode,2);
        outfile.write((char*)&numberOfChannels,2);
        outfile.write((char*)&sampleRate,4);
        outfile.write((char*)&blockAlign,4);
        outfile.write((char*)&significantBps,2);
        outfile.write((char*)&extraFormatBytes,2);
        outfile.write("data",4);
        outfile.write((char*)&bytes,4);

        //Track Rip
        for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {

Bare in mind hwr that the (char *) conversion is platform dependent and that this changed doesn't deal with endianness. main.cpp i included a working c++ source file.

Re: 44 bit difference

by Robert William Fuller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So it was a 44 byte difference, not a "44 bit" difference.  I might have
guessed something like that if you had said "bytes" instead of "bits" in
the subject.  It helps to be very careful when you state a problem.  I'm
glad to hear you solved it :-)

Cuke wrote:

> Ok so with the help of rocky i found that my program i post you didn't add
> the wav header. So i just add this lines of code after the OUTFILE open:
>
>         //Get the track size in bytes and conver
> int bytes= ( i_last_lsn - i_first_lsn + 1 ) * CDIO_CD_FRAMESIZE_RAW;
> cout << "Nr Bytes:" << bytes+44 << endl;
>
> //Open the output file
> ofstream outfile ("temp.wav",ofstream::binary | ofstream::app |
> ofstream::out);
>        
> //Waw format header specification
> int waweChunkLength=bytes+44-8;
> int fmtChunkLength=16;
> int compressionCode=1;
> int numberOfChannels=2;
> int sampleRate=44100;
> int blockAlign=44100*2*2;
> int significantBps=4;
> int extraFormatBytes=16;
>
> outfile.write("RIFF",4);
> outfile.write((char*)&waweChunkLength,4);
> outfile.write("WAVEfmt ",8);
> outfile.write((char*)&fmtChunkLength,4);
> outfile.write((char*)&compressionCode,2);
> outfile.write((char*)&numberOfChannels,2);
> outfile.write((char*)&sampleRate,4);
> outfile.write((char*)&blockAlign,4);
> outfile.write((char*)&significantBps,2);
> outfile.write((char*)&extraFormatBytes,2);
> outfile.write("data",4);
> outfile.write((char*)&bytes,4);
>
> //Track Rip
>         for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
>
> Bare in mind hwr that the (char *) conversion is platform dependent and that
> this changed doesn't deal with endianness.
> http://www.nabble.com/file/p23128111/main.cpp main.cpp  i included a working
> c++ source file.



_______________________________________________
Libcdio-help mailing list
Libcdio-help@...
http://lists.gnu.org/mailman/listinfo/libcdio-help

Re: 44 bit difference

by Cuke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

yes, sorry! :)

Robert William Fuller wrote:
So it was a 44 byte difference, not a "44 bit" difference.  I might have
guessed something like that if you had said "bytes" instead of "bits" in
the subject.  It helps to be very careful when you state a problem.  I'm
glad to hear you solved it :-)

Cuke wrote:
> Ok so with the help of rocky i found that my program i post you didn't add
> the wav header. So i just add this lines of code after the OUTFILE open:
>
>         //Get the track size in bytes and conver
> int bytes= ( i_last_lsn - i_first_lsn + 1 ) * CDIO_CD_FRAMESIZE_RAW;
> cout << "Nr Bytes:" << bytes+44 << endl;
>
> //Open the output file
> ofstream outfile ("temp.wav",ofstream::binary | ofstream::app |
> ofstream::out);
>        
> //Waw format header specification
> int waweChunkLength=bytes+44-8;
> int fmtChunkLength=16;
> int compressionCode=1;
> int numberOfChannels=2;
> int sampleRate=44100;
> int blockAlign=44100*2*2;
> int significantBps=4;
> int extraFormatBytes=16;
>
> outfile.write("RIFF",4);
> outfile.write((char*)&waweChunkLength,4);
> outfile.write("WAVEfmt ",8);
> outfile.write((char*)&fmtChunkLength,4);
> outfile.write((char*)&compressionCode,2);
> outfile.write((char*)&numberOfChannels,2);
> outfile.write((char*)&sampleRate,4);
> outfile.write((char*)&blockAlign,4);
> outfile.write((char*)&significantBps,2);
> outfile.write((char*)&extraFormatBytes,2);
> outfile.write("data",4);
> outfile.write((char*)&bytes,4);
>
> //Track Rip
>         for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
>
> Bare in mind hwr that the (char *) conversion is platform dependent and that
> this changed doesn't deal with endianness.
> http://www.nabble.com/file/p23128111/main.cpp main.cpp  i included a working
> c++ source file.



_______________________________________________
Libcdio-help mailing list
Libcdio-help@gnu.org
http://lists.gnu.org/mailman/listinfo/libcdio-help