/// <summary> /// Creates a new audio track with the specified number of blocks. /// Audio CDs may have between 1 and 99 tracks. /// </summary> /// <param name="blocks">Number of audio blocks for this track.</param> /// <exception cref="COMException"></exception> /// <exception cref="DiscMasterNotOpenedException"></exception> /// <exception cref="TrackOpenException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> public void CreateAudioTrack( int blocks ) { if ( blocks < 1 ) { throw new ArgumentOutOfRangeException( "blocks", blocks, Resources.Error_Msg_RedbookDiscMaster_AtLeastOneAudioBlock ); } // End if (blocks < 1) _owner.NotifyTrackProgress( _track, _track + 1 ); Monitor.Enter( _redbookMaster ); try { _redbookMaster.CreateAudioTrack( blocks ); } catch ( COMException ex ) { switch ( (uint) ex.ErrorCode ) { case ErrorCodes.IMAPI_E_NOTOPENED: throw new DiscMasterNotOpenedException(); case ErrorCodes.IMAPI_E_TRACKOPEN: throw new TrackOpenException(); default: throw; } } finally { Monitor.Exit( _redbookMaster ); } Monitor.Enter( _buffer ); if ( _buffer == null ) { _buffer = new PinnedByteBuffer( AudioBlockSize * BLOCK_MULTIPLE ); } // End if (_buffer == null) Monitor.Exit( _buffer ); }
/// <summary> /// Disposes the specified disposing. /// </summary> /// <param name="disposing"> /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// </param> protected override void Dispose( bool disposing ) { // Check to see if Dispose has already been called. if ( disposing && !IsDisposed ) { // Dispose managed resources. Marshal.ReleaseComObject( _redbookMaster ); _redbookMaster = null; if ( _buffer != null ) { _buffer.Dispose(); _buffer = null; } // End if } base.Dispose( disposing ); }
public void AddAudioTrackFromStream( Stream rawAudioStream ) { if ( rawAudioStream == null ) { throw new ArgumentNullException( "rawAudioStream" ); } // End if (rawAudioStream == null) int cancel = 0; int Completed = 0; _owner.QueryCancelRequest( out cancel ); if ( cancel == 0 ) { if ( _buffer == null ) { _buffer = new PinnedByteBuffer( AudioBlockSize * BLOCK_MULTIPLE ); } // End if (_buffer == null) var blocks = (int) Math.Ceiling( ( (double) rawAudioStream.Length ) / AudioBlockSize ); CreateAudioTrack( blocks ); _owner.QueryCancelRequest( out cancel ); if ( cancel == 0 ) { int size = 0; while ( ( size = rawAudioStream.Read( _buffer.Bytes, 0, _buffer.Size ) ) > 0 ) { size = ZeroTrailingBufferBytes( size ); Monitor.Enter( _redbookMaster ); try { _redbookMaster.AddAudioTrackBlocks( _buffer.BufferAddress, size ); } catch ( COMException ex ) { switch ( (uint) ex.ErrorCode ) { case ErrorCodes.IMAPI_E_NOTOPENED: throw new DiscMasterNotOpenedException(); case ErrorCodes.IMAPI_E_TRACKNOTOPEN: throw new TrackNotOpenException(); case ErrorCodes.IMAPI_E_DISCFULL: throw new DiscFullException(); default: throw; } } finally { Monitor.Exit( _redbookMaster ); } Completed += size / AudioBlockSize; _owner.QueryCancelRequest( out cancel ); if ( cancel != 0 ) { break; } // End if (cancel != 0) } // End while ((size = rawAudioStream.Read(_buffer.Bytes, 0, (int)_buffer.Size)) > 0) CloseAudioTrack(); } // End if (cancel == 0) } // End if (cancel == 0) }