Author Topic: Bass CD Speed Issue  (Read 575 times)

quadamage

  • Posts: 8
Bass CD Speed Issue
« on: 12 Jul '17 - 02:04 »
Hi there.

I am working on a small CD extraction program recently and were experiencing with slow CD speed issue under certain circumstances.

Code: [Select]
if ( !BASS_Init( -1, 44100, 0, 0, NULL ) )
{
AfxMessageBox( _T( "Can't initialize sound device!" ), MB_ICONSTOP );
return;
}
BASS_CD_SetInterface( BASS_CD_IF_WIO );


DWORD hChannel;
uint32_t nBytes = 0;
uint8_t* buf = new uint8_t[1024*1024];
CString cs;


hChannel = BASS_CD_StreamCreate( 0, 0, BASS_STREAM_DECODE );

DWORD dw = GetTickCount();

while ( BASS_ChannelIsActive( hChannel ) )
nBytes += BASS_ChannelGetData( hChannel, buf, 1048576 );

BASS_StreamFree( hChannel );
BASS_CD_Release( 0 );
delete [] buf;

float fSec =(GetTickCount() - dw)/1000.f;
cs.Format( L"Time: %4.2f secs,  Speed:  %4.2fX", fSec, nBytes/176400.0/fSec);
AfxMessageBox( cs );

The above code worked fine for me, CD drive spinned up and ran at full speed(22x or so). However if I use the SPTI interface instead,
Code: [Select]
BASS_CD_SetInterface( BASS_CD_IF_SPTI );the drive can not speed up and seemed to be locked at 6x slow speed. I am running on a Win7 x64 computer, the drive is a pioneer DVD writer DVR-217 model.

I used the same drive loaded the same brand new disc with CD ripping software like EAC, CDex, they all ran at full speed(over 20x) with SPTI interface, so it appeared this is not a hardware or OS issue.

Did I do something wrong? Can you help?
Thanks in advance.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #1 on: 12 Jul '17 - 17:10 »
With some drives, it can help to set the drive's speed prior to creating the stream. For example:

Code: [Select]
...
BASS_CD_SetSpeed(0, -1); // request optimal performance
hChannel = BASS_CD_StreamCreate( 0, 0, BASS_STREAM_DECODE );
...

See if that helps with your drive.

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #2 on: 13 Jul '17 - 02:18 »
Hi, thanks for your prompt reply, unfortunately
Code: [Select]
BASS_CD_SetSpeed(0, -1); // request optimal performancedid not help for me.

I read the drive manual, the maximum CD Rom reading speed is 40x.

I also tried to get/set the cd speed before created the stream
Code: [Select]

        cs.Format( L"Drive Speed: %d", BASS_CD_GetSpeed( 0 ) );
AfxMessageBox( cs );

if ( ! BASS_CD_SetSpeed(0, 3528) )
{
cs.Format( L"Error Code: %d", BASS_ErrorGetCode() );
AfxMessageBox( cs, MB_ICONERROR );
}

cs.Format( L"Drive Speed: %d", BASS_CD_GetSpeed( 0 ) );
AfxMessageBox( cs );

Whatever value I entered in BASS_CD_SetSpeed,  BASS_CD_GetSpeed always returned 7056, 40x, then the drive can not spin up and was locked at 6x silently.

If I used other CD ripping programs like CDex or WMP to spin up the drive first, then used bass to read before it spinned down, the speed was normal (over 20x). Is it possible to spin up/down programmatically with your library?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #3 on: 13 Jul '17 - 17:46 »
Another thing you could try is this latest BASSCD build:

   www.un4seen.com/stuff/basscd.zip

It adds a BASS_CONFIG_CD_READ option to set (via BASS_SetConfig) the read block size in frames (the default is 16), which you could try playing around with to see if it makes a difference (check what block size the other software you're testing uses if possible). That should be set before the BASS_CD_StreamCreate call.

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #4 on: 14 Jul '17 - 02:15 »
Hi, I tried the new file, it did help somewhat but did not eliminate the issue completly.

For a 12 tracks, 70 min disc, all other ripping program behaved normally, the speed of first track was 20x, then increased steadly, the speed of the last was over 35x. They all spinned up with noise & vibrations.

The buffer size of my program is 26*2352 bytes, so I set BASS_CONFIG_CD_READ value to 26, 52, 78 and 104 to test,
the speed was always constant & locked for all tracks and the drive never spinned up and ran silently.

BASS_CONFIG_CD_READ value 26, 52  the speed was 4x
BASS_CONFIG_CD_READ value 78  the speed was 22x
BASS_CONFIG_CD_READ value 104  the speed was 20x
BASS_CONFIG_CD_READ value 156 the speed was 17x
BASS_CONFIG_CD_READ value 208  the speed was 14x

It did read faster with certain values, but still not at full speed. The bass cd stream is perfect for playback usage, however not suitable for ripping purpose. Since the speed was constant, I guessed the internal buffer of the stream is too small, if you want full speed, you need to keep reading incessantly.

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #5 on: 15 Jul '17 - 22:31 »
The latest build seemed to introduce a bug, if I call BASS_CD_SetOffset before BASS_CD_StreamCreate, sometimes when the reading finished, BASS_ChannelIsActive did not return BASS_ACTIVE_STOPPED as expected, so the following loop will never terminate.

Code: [Select]
while ( BASS_ChannelIsActive( hChannel ) )
nBytes += BASS_ChannelGetData( hChannel, buf, 1048576 );

I have no trouble in using BASS_CD_SetOffset with public build 2.4.1.2, this bug only arised when using the latest build.


Another thing you could try is this latest BASSCD build:

   www.un4seen.com/stuff/basscd.zip

It adds a BASS_CONFIG_CD_READ option to set (via BASS_SetConfig) the read block size in frames (the default is 16), which you could try playing around with to see if it makes a difference (check what block size the other software you're testing uses if possible). That should be set before the BASS_CD_StreamCreate call.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #6 on: 17 Jul '17 - 17:54 »
Oops! Here's an update that should fix that:

   www.un4seen.com/stuff/basscd.zip

Let me know if you still have the problem with that.

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #7 on: 18 Jul '17 - 01:12 »
Oops! Here's an update that should fix that:

   www.un4seen.com/stuff/basscd.zip

Let me know if you still have the problem with that.

Yes, BASS_ChannelIsActive always returns BASS_ACTIVE_STOPPED when reading ended now, thanks.

However, comparing with build 2.4.1.2 or TOC, the returned track data was truncated if I call BASS_CD_SetOffset, the count of missing bytes was multiples of 2352, so a few frames were discarded?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #8 on: 18 Jul '17 - 18:07 »
That doesn't seem to be happening here, ie. the length of the data is still a multiple of 2352 bytes (16-bit data) with a non-0 offset. What offset are you using and what lengths are you getting with and without that offset? Also, what BASS_CONFIG_CD_SKIPERROR setting?

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #9 on: 18 Jul '17 - 19:44 »
I did not change the BASS_CONFIG_CD_SKIPERROR setting.
Build 2.4.1.2 worked fine, always auto stopped and returned accurate track length whether I called BASS_CD_SetOffset.

The latest basscd.dll also behaved normally if I did NOT call BASS_CD_SetOffset.
I set the drive offset values to 6 or 96 for 2 drives.

If I called BASS_CD_SetOffset, all tracks auto stopped, but some of the tracks returned inaccurate length, others with accurate length. For example, reading 10 sequential tracks

Code: [Select]
BASS_CD_SetOffset( g_sDriveNum, 6 );
for ( int i = 0; i < 11; i++ )
{
hChannel = BASS_CD_StreamCreate( 0, i, BASS_STREAM_DECODE );
uint32_t nCnt = 0;
while ( BASS_ChannelIsActive( hChannel ) )
{
nBytes += BASS_ChannelGetData( hChannel, buf, 1048576 );
nCnt++;
if ( 0 == nCnt % 1000000 )
{
AfxMessageBox( L"Infinite Loop" );
break;
}
}

BASS_StreamFree( hChannel );

}

The returned bytes were usually 99.9X% of the expected,  the count of missing bytes was always multiples of 2352.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #10 on: 19 Jul '17 - 13:29 »
If I called BASS_CD_SetOffset, all tracks auto stopped, but some of the tracks returned inaccurate length, others with accurate length. For example, reading 10 sequential tracks

Oh yes, I can reproduce the problem now (the track I tried yesterday happened to be OK). Here's an update that should fix it:

   www.un4seen.com/stuff/basscd.zip

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #11 on: 20 Jul '17 - 15:32 »
Thank you, almost all tracks are extracted well now. I think you nearly fixed the problem.

For error detection purpose, I ripped tracks twice, then calculated & compared CRC values of every frame. I have a CD which has a "bad" track, usually less than 10 bad frame with mismatched CRCs were found. With you last build, after setting the drive offset, I got hundreds or thousands sequential bad frame. For example, frame 4291 is a bad frame, now from 4292 to frame 5000 or 8000 are all with mismatched CRCs, this never happened before.

I can confirm that build 2.4.1.2 and other rippers only detected less than 10 bad frames. The last basscd.dll also behaved normally if I did NOT call BASS_CD_SetOffset. All "good" tracks also were extracted fine with offset.

If a read error or a retry occurs, is the offset setting still applied appropriately?


Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #12 on: 21 Jul '17 - 15:15 »
The read error handling shouldn't be affected by the offset setting. Please try setting a BASS_SYNC_CD_ERROR sync (via BASS_ChannelSetSync) on an affected CD stream and compare how often that gets triggered (and the "data" value) with the release and latest BASSCD builds.

quadamage

  • Posts: 8
Re: Bass CD Speed Issue
« Reply #13 on: 22 Jul '17 - 16:24 »
I need to calculate CRC values frame by frame, I call BASS_ChannelGetData in this way

Code: [Select]
BASS_ChannelGetData( hChannel, buf, X*2352);
the data length is multiples of 2352 and I assume the returned data length is Y*2352, Y<=X.
In fact, this is always true for the public release (with or without offset) and the latest build (without offset).
but this is no longer true for certain "bad" tracks when using the latest with offset, so I got large block with mismatched CRCs.

Although it is not bass' fault, I think the assumption is reasonable since a CD reading operation is always frame-level. I hope a BASS_DATA_FRAME flag is available for a CD stream channel. Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Bass CD Speed Issue
« Reply #14 on: 24 Jul '17 - 17:33 »
Is the problem you're having due to BASS_ChannelGetData sometimes not returning a multiple of 2352 bytes when there's a read error and offset is non-0? If so, perhaps you could call it again to get the remainder? The difference between the release and updated BASSCD versions is that the updated version won't wait indefinitely for the requested amount of data.

Note that when offset is non-0, your frame boundaries won't match the CD's frame boundaries. For example, if offset=6 then your frame will consist of 2346 bytes from one CD frame and 6 bytes from the next CD frame. If there happens to be an error/delay when reading the next frame then you might only receive 2346 bytes.