Author Topic: Record stream and play sonds at the same time  (Read 4911 times)

Pachu

  • Posts: 5
Hi!,

I'm having problems to record a stream while some samples are running. When I call BASS_RecordStart(), the other sounds that are running, stop.
If I don't call BASS_RecordStop(), I can't play streams and sounds.

Is it possible to record something (MIC-in) with BASS and listen to streams at the same time?

Ian @ un4seen

  • Administrator
  • Posts: 26028
Re: Record stream and play sonds at the same time
« Reply #1 on: 26 May '03 - 23:52 »
What soundcard do you have? If it supports full-duplex (most do), then you can play and record simultaneously.

Pachu

  • Posts: 5
Re: Record stream and play sonds at the same time
« Reply #2 on: 27 May '03 - 17:59 »
Yes!, I have SB Audigy ( full-duplex ). This is the code:
I have Error 41 when I try to Create the Stream.

Code: [Select]
// resetea valores
char *_recBuffer = NULL;
DWORD _recLength = 0;
char *_inputName = NULL;

bool SoundManager::recordInit( int input, int level ) {

     //Inicializa Record System
     BASS_RecordInit( -1 ); //Inicializa el dispositivo de grabación
     
     _inputName = BASS_RecordGetInputName( input );
                             
     _input = input;
     
     // enable the selected input
     for ( int i = 0; BASS_RecordSetInput( i, BASS_INPUT_OFF ); ++i ); // 1st disable all inputs, then...
     
     BASS_RecordSetInput( _input, BASS_INPUT_ON ); // enable the selected

     BASS_RecordSetInput( _input, BASS_INPUT_LEVEL | level );
     
     //UpdateInputInfo(); // update info

     return TRUE;

}

// update the recording/playback counter
void UpdateRecording( ) {
     /*
     if ( _recBuffer ) {
           
           if ( BASS_ChannelIsActive( _recordStream ) ) // playing
                 
                 //Ejecutar VUMeter
                 //sprintf(text,"%I64d / %d",BASS_ChannelGetPosition(chan),reclen);
     */
}



//Recibe las grabaciones del microfono
BOOL CALLBACK recordProc( void * data, DWORD len, DWORD user ) {

     
     // increase buffer size if needed
     if ( ( _recLength % BUFSTEP ) + len >= BUFSTEP ) {
           
           _recBuffer = ( char* )realloc( _recBuffer,( ( _recLength + len ) / BUFSTEP + 1 ) * BUFSTEP );
           
           if ( !_recBuffer ) {
                 
                 MessageBox( NULL, "Bass recording Error! Out of Memory", "Voice Recognition", MB_OK | MB_ICONSTOP );
                 
                 UpdateRecording();
                 
                 return FALSE; // stop recording
           }

     }
     
     // buffer the data
     memcpy( _recBuffer + _recLength , data, len );
     
     _recLength += len;
     
     //UpdateRecording( );
     
     return TRUE; // continue recording
}

// Actualiza la informacion de la entrada de grabación
void SoundManager::UpdateInputInfo( ) {
     /*
     char *type;
     
     int it = BASS_RecordGetInput( _input ); // get info on the input
     
     switch ( it & BASS_INPUT_TYPE_MASK ) {
           
           case BASS_INPUT_TYPE_DIGITAL:
                 type="digital";
                 break;
           case BASS_INPUT_TYPE_LINE:
                 type="line-in";
                 break;
           case BASS_INPUT_TYPE_MIC:
                 type="microphone";
                 break;
           case BASS_INPUT_TYPE_SYNTH:
                 type="midi synth";
                 break;
           case BASS_INPUT_TYPE_CD:
                 type="analog cd";
                 break;
           case BASS_INPUT_TYPE_PHONE:
                 type="telephone";
                 break;
           case BASS_INPUT_TYPE_SPEAKER:
                 type="pc speaker";
                 break;
           case BASS_INPUT_TYPE_WAVE:
                 type="wave/pcm";
                 break;
           case BASS_INPUT_TYPE_AUX:
                 type="aux";
                 break;
           case BASS_INPUT_TYPE_ANALOG:
                 type="analog";
                 break;
           default:
                 type="undefined";
     }
     
      // display the type */
}

void SoundManager::recordStop( ) {

     BASS_ChannelStop( RECORDCHAN );
     
     // create a stream from the recording
     _recordStream = BASS_StreamCreateFile( TRUE, _recBuffer, 0, _recLength, 0 );

     if( int error = BASS_ErrorGetCode( ) ) {
           
                 MessageBox( NULL, "Error al grabar sonido!", "Error!", MB_OK | MB_ICONSTOP );
     }
     
     _recording = FALSE;

     //BASS_Start( );
     
}

void SoundManager::playRecordStream( ) {

     BASS_StreamPlay( _recordStream, TRUE, 0 );      
}

void SoundManager::recordStart( ) {

     if( !_recording ) {
     
           // clear any old recording
           if ( _recBuffer ) {
                 
                 BASS_Stop();
                 BASS_StreamFree( _recordStream );
                 free( _recBuffer );
                 _recBuffer = NULL;
                 //UpdateRecording( );
           }
           
           // allocate initial buffer and length
           _recBuffer = ( char* ) malloc( BUFSTEP );
           _recLength = 0;
           
           // start recording
           if ( !BASS_RecordStart( 11025, BASS_SAMPLE_8BITS, &recordProc, 0 ) ) {
                 
                 MessageBox( NULL, "Error al iniciar la grabación!", "Voice Recognition!", MB_OK | MB_ICONSTOP );
                 free( _recBuffer );
                 _recBuffer = 0;
           }
           
           if( int error = BASS_ErrorGetCode( ) ) {
           
                 MessageBox( NULL, "No furula la grabacion!", "Error!", MB_OK | MB_ICONSTOP );
           }

           _recording = TRUE;      
     }
     
}



Thank You!

Ian @ un4seen

  • Administrator
  • Posts: 26028
Re: Record stream and play sonds at the same time
« Reply #3 on: 27 May '03 - 22:20 »
The problem is you've not put a WAVE header at the front of the recorded data, so BASS doesn't recognise the format when you try to stream it (hence the error is BASS_ERROR_FILEFORM).

You've forgotten that part of the "StartRecording" function :)