Author Topic: How to do loopback recording on MAC?  (Read 299 times)

zhefengJin

  • Posts: 1
How to do loopback recording on MAC?
« on: 20 Jun '19 - 10:08 »
Hi.
Please help me.
I am trying to do loopback recording on .NET and MAC
I already succeed in loopback recording on .NET with BASSWASAPI, but I can't find WASAPI for MAC.
So I tried as follows by using thread, but the result record file had some noises now.
thank for any proposals

NSString* uniquePathToFile;
HSTREAM recordStream = 0;
HSTREAM mixerStream = 0;

NSThread *recordThread = nil;
bool bStopRecording = false;

- (void) RecordingThread
{
    DWORD length = 0;
    DWORD read = -1;
    double updatePeriod = (double)BASS_GetConfig(BASS_CONFIG_UPDATEPERIOD) / 1000;

    length = BASS_ChannelSeconds2Bytes(mixerStream, updatePeriod);
    Byte buffer[length];
   
    while(true)
    {
        if(bStopRecording)
            break;
       
        read = BASS_ChannelGetData(mixerStream, buffer, length);
       
        if (recordStream != 0)
            BASS_ChannelGetData(recordStream, buffer, read);
        else
            break;
       
        prevPos = BASS_ChannelGetPosition(mixerStream, BASS_POS_BYTE);
        [NSThread sleepForTimeInterval: updatePeriod];
    }
}

- (void) StartRecording
{
    mixerStream = waveform.sound.mixer;
   
    int sampleRate = [self getTransferRate];
    DWORD period = BASS_GetConfig(BASS_CONFIG_UPDATEPERIOD);
    recordStream = BASS_StreamCreate(sampleRate, 2, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT, nil, 0);

    BASS_Encode_Start(recordStream, [uniquePathToFile UTF8String], BASS_ENCODE_PCM | BASS_ENCODE_AUTOFREE , nil, nil); //adding WAV encoder to stream
   
    bStopRecording = false;
    recordThread = [[NSThread alloc] initWithTarget:self selector:@selector(RecordingThread) object:nil];
    [recordThread start];
}

- (void) StopRecording
{
    BASS_Encode_Stop(recordStream);
    BASS_StreamFree(recordStream);
    recordStream = 0;
   
    bStopRecording = true;
}

Ian @ un4seen

  • Administrator
  • Posts: 22247
Re: How to do loopback recording on MAC?
« Reply #1 on: 20 Jun '19 - 14:19 »
Do you want to write/encode the sound from your own app? If so, you don't need loopback recording for that. You can set the encoder on the BASS output (see BASS_StreamCreate with STREAMPROC_DEVICE), or directly on the output mixer if you're using one (as it appears you are), like this:

Code: [Select]
BASS_Encode_Start(mixerStream, [uniquePathToFile UTF8String], BASS_ENCODE_PCM | BASS_ENCODE_AUTOFREE | BASS_ENCODE_QUEUE, nil, nil); //adding WAV encoder to stream (queued to avoid IO delays)