Author Topic: BASS_Record on arm with multiple inputs on one device  (Read 451 times)

serkanp

  • Posts: 85
hi,
i have a 8 channel(mono) output and 6 channel (mono) input device
http://www.audioinjector.net/rpi-octo-hat
when i get BASS_RecordGetInfo and BASS_RecordGetDeviceInfo i can see 3 inputs (stereo) which is ok.
the output of the device info :

    "name": "audioinjector-octo-soundcard: ",
    "driver": "hw:0,0",
    "flags": 1,
    "enabled": true,
    "IsDefault": false,
    "IsInitialized": false,
    "typeDigital": false,
    "typeDisplayPort": false,
    "typeHandset": false,
    "typeHdmi": false,
    "typeHeadPhones": false,
    "typeHeadSet": false,
    "typeLine": false,
    "typeMask": false,
    "typeMicrophone": false,
    "typeNetwork": false,
    "typeSPDIF": false,
    "typeSpeakers": false,
    "index": 1,
    "singlein": 0,
    "inputs": 3


when i tried to set any input, only the first input works but the others not.
here is the code i used:
Code: [Select]
let recinit=bass.BASS_RecordInit(-1)
bass.BASS_RecordSetInput(2,bass.BASS_INPUT_ON,0.9)
let handle=bass.BASS_RecordStart(44100,2,bass.BASS_RECORD_PAUSE,(handle:any,len:any,buffer:any,user:any)=>{

    console.log(`len:${len}`)

})
bass.BASS_Encode_Start(handle, "lame --preset standard - output.mp3", bass.BASS_ENCODE_FP_24BIT);

bass.BASS_ChannelPlay(handle,false)


i have 2 questions now
1- how can i set any of these inputs correctly
2- how can i set ex: second input's only left channel

thank you
Serkan

Ian @ un4seen

  • Administrator
  • Posts: 21329
What is the return value from the BASS_RecordSetInput call, ie. is it reporting success or failure? If failure, also check the error code with BASS_ErrorGetCode.

CanK

  • Posts: 3
it fails setting input and err is -1 aka unknown

Ian @ un4seen

  • Administrator
  • Posts: 21329
What do you see if you run "amixer -D hw:0"?

serkanp

  • Posts: 85
 $ amixer -D hw:0
Simple mixer control 'ADC High-Pass Filter',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'ADC Soft Ramp & Zero Cross Control',0
  Capabilities: enum
  Items: 'Immediate Change' 'Zero Cross' 'Soft Ramp' 'Soft Ramp on Zero Cross'
  Item0: 'Immediate Change'
Simple mixer control 'ADC1',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 176
  Front Left: Capture 161 [91%] [16.50dB]
  Front Right: Capture 161 [91%] [16.50dB]
Simple mixer control 'ADC1 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'ADC1 Single Ended Mode',0
  Capabilities: enum
  Items: 'Differential' 'Single-Ended'
  Item0: 'Differential'
Simple mixer control 'ADC2',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 176
  Front Left: Capture 158 [90%] [15.00dB]
  Front Right: Capture 158 [90%] [15.00dB]
Simple mixer control 'ADC2 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'ADC2 Single Ended Mode',0
  Capabilities: enum
  Items: 'Differential' 'Single-Ended'
  Item0: 'Differential'
Simple mixer control 'ADC3',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 176
  Front Left: Capture 158 [90%] [15.00dB]
  Front Right: Capture 158 [90%] [15.00dB]
Simple mixer control 'ADC3 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'ADC3 Single Ended Mode',0
  Capabilities: enum
  Items: 'Differential' 'Single-Ended'
  Item0: 'Differential'
Simple mixer control 'DAC Auto Mute',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'DAC De-emphasis',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DAC Soft Ramp & Zero Cross Control',0
  Capabilities: enum
  Items: 'Immediate Change' 'Zero Cross' 'Soft Ramp' 'Soft Ramp on Zero Cross'
  Item0: 'Immediate Change'
Simple mixer control 'DAC1',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'DAC1 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'DAC2',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'DAC2 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'DAC3',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'DAC3 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'DAC4',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'DAC4 Invert',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'Mute ADC Serial Port',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]

Ian @ un4seen

  • Administrator
  • Posts: 21329
It looks like there are input volume controls ("cvolume") but no input switching controls ("cswitch") on that device, so that would explain why BASS_RecordSetInput is failing to switch inputs. Are you able to switch inputs on it with any other software?

serkanp

  • Posts: 85
yes i can
also i can see capture device in alsamixer as ADC1, ADC2, ADC3
see attached picture

Ian @ un4seen

  • Administrator
  • Posts: 21329
That appears to confirm what "amixer" said, that there are 3 volume/gain controls but no switches to set the active input(s). Have you tried setting the "chans" parameter to 6 in your BASS_RecordStart call, and are the inputs then all present in the recording? If that works then you could put the recording through a splitter (see BASS_Split_StreamCreate) to extract the channels that you want.

serkanp

  • Posts: 85
hi again,
recording 6 channel seems ok.. i tested the output with audacity and i can see the channels..
but now we have a new problem on splitting..
 here is the code i used:
Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            var recInit = Bass.BASS_RecordInit(-1);
            Console.WriteLine($"rec init:{recInit}");
           
            var success = Bass.BASS_RecordSetInput(0,BASSInput.BASS_INPUT_ON , 1);
            Console.WriteLine($"record set input result {success}");
            var handle = Bass.BASS_RecordStart(44100, 2,BASSFlag.BASS_RECORD_PAUSE ,null,IntPtr.Zero);
            Console.WriteLine($"record start handle:{handle}");
            int[] maparr={1,-1};
            var splitHandle = BassMix.BASS_Split_StreamCreate(handle,BASSFlag.BASS_SAMPLE_FLOAT, maparr);
            Console.WriteLine($"splitter handle:{splitHandle}");
            Console.WriteLine($"splitter error:{Bass.BASS_ErrorGetCode()}");
           var result= BassEnc.BASS_Encode_Start(splitHandle, "test.wav",BASSEncode.BASS_ENCODE_PCM, null, IntPtr.Zero);
            Console.WriteLine($"encoder start result {result}");
            Console.WriteLine($"BASS_Encode_Start error:{Bass.BASS_ErrorGetCode()}");
           bool playresult= Bass.BASS_ChannelPlay(splitHandle, false);
            Console.WriteLine($"Play result {playresult}");
            Thread.Sleep(5000);
            Bass.BASS_ChannelStop(handle);
            Console.WriteLine($"Recording finished");

on the test i used @radio42's dotnet component on dotnet core 2.x
on macosX (my development machine) i get this result:
Code: [Select]
record test!
rec init:True
record set input result True
record start handle:-2147483647
splitter handle:-2147483645
splitter error:BASS_OK
encoder start result -2130706428
BASS_Encode_Start error:BASS_OK
Play result True
Recording finished

and the output file is ZERO bytes.

 on raspberry:
Code: [Select]
record test!
rec init:True
record set input result False
record start handle:-2147483647
Parçalama arızası

the word "Parçalama arızası" is my locale language,but it comes from bass itself.. not from my code..



Ian @ un4seen

  • Administrator
  • Posts: 21329
It looks like the recording is left paused (BASS_RECORD_PAUSE) there, so the splitter and encoder don't receive any data.

serkanp

  • Posts: 85
Code: [Select]
bool playresult= Bass.BASS_ChannelPlay(splitHandle, false);

we have channelPlay by the way..
i also tried with the normal handle and splitHandle and both the results are same..

- what about the problem on arm?
- can i use map array as: int[] maparr={2,3,-1}; so third and fourth channels will be used only..
- are the flags are correct?

at the end of this, i just want to redirect any input channel to any selected output..
i need a basic example for that..

so recording to wav is only to get correct output from sound card..
while recording 6 channels to wav, the raspberry pi 3 cpu was %120-%140..
so when i redirect the input to output channel, will cpu again be >%100?

serkanp

  • Posts: 85
one question to radio42 for .net component
which version of dotnet component will i use for dotnet core 2.x?
winstore version seems working but encoder and some other features does not exists on it..
4.0 and 4.5 versions are not running with dotnet core
osx and linux versions runs but on each os compile, i have to change the references on project..
can you guide me to choose correct one?

radio42

  • Posts: 4636
There is currently no .Net core version available due to its marshaling limits with native libs.

Ian @ un4seen

  • Administrator
  • Posts: 21329
Code: [Select]
bool playresult= Bass.BASS_ChannelPlay(splitHandle, false);

we have channelPlay by the way..
i also tried with the normal handle and splitHandle and both the results are same..

You will need to call BASS_ChannelPlay on both handles, when BASS_RECORD_PAUSE is used in the BASS_RecordStart call.

- can i use map array as: int[] maparr={2,3,-1}; so third and fourth channels will be used only..

Yes, that is correct.

at the end of this, i just want to redirect any input channel to any selected output..
i need a basic example for that..

That sounds like a case for matrix mixing. If there are 6 inputs and 8 outputs, you would create a 6 channel recording (BASS_RecordStart) and an 8 channel mixer (BASS_Mixer_StreamCreate), plug the recording into the mixer with matrix mixing enabled (BASS_Mixer_StreamAddChannel with BASS_MIXER_MATRIX), and set an 8x6 matrix/array (BASS_Mixer_ChannelSetMatrix) for the channel mapping that you want. Please see the BASSmix documentation for details on the mentioned functions and also the "Matrix mixing" section.

while recording 6 channels to wav, the raspberry pi 3 cpu was %120-%140..

That seems unusually high. What is the CPU usage if you record without writing a WAV file, ie. just call BASS_RecordStart without BASS_Encode_Start?

Code: [Select]
var handle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

serkanp

  • Posts: 85
Re: BASS_Record on arm with multiple inputs on one device
« Reply #14 on: 13 Nov '18 - 11:08 »
hi again,
i tried matrix mixer with given documentation, however, i can't get any audio output

here is the code:
Code: [Select]


let outputs=2
let inputs=2


let init=bass.BASS_Init(-1,44100,0)
let recinit=bass.BASS_RecordInit(-1)
//let success=bass.BASS_RecordSetInput(0,bass.BASS_INPUT_ON,0.9)
//console.log(`success:${success}`)
console.log(`error:${bass.BASS_ErrorGetCode()}`)

let decodingHandle=bass.BASS_StreamCreate(44100,inputs,bass.BASS_STREAM_DECODE)

let mixerHandle=bass.BASS_Mixer_StreamCreate(44100,outputs,0)
console.log(`status mixer and error:${mixerHandle}-${bass.BASS_ErrorGetCode()}`)


let streamAddStatus=bass.BASS_Mixer_StreamAddChannel(mixerHandle,decodingHandle,bass.BASS_MIXER_MATRIX)
console.log(`sstreamAddStatus and error:${streamAddStatus}-${bass.BASS_ErrorGetCode()}`)


let handle=bass.BASS_RecordStart(44100,inputs,bass.BASS_RECORD_PAUSE,(handle:any,len:any,buffer:any,user:any)=>{
    bass.BASS_StreamPutData(decodingHandle,buffer,len)
    console.log(`len:${len}`)
})

let matrix=new Array();
matrix=[[0,1],[1,0]]

let MatrixResult=bass.BASS_Mixer_ChannelSetMatrix(decodingHandle,matrix)
console.log(`MatrixResult:${MatrixResult}`)
console.log(`error:${bass.BASS_ErrorGetCode()}`)

bass.BASS_ChannelPlay(handle,false)
bass.BASS_ChannelPlay(decodingHandle,false)
bass.BASS_ChannelPlay(mixerHandle,false)

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Record on arm with multiple inputs on one device
« Reply #15 on: 13 Nov '18 - 13:22 »
The BASS_StreamPutData call will be failing because "decodingHandle" isn't a push stream (STREAMPROC_PUSH). When you want to play a recording channel through a mixer, you can remove the RECORDPROC from the BASS_RecordStart call and plug the recording directly into the mixer, with no need for an intermediate stream. For example:

Code: [Select]
mixer = BASS_Mixer_StreamCreate(44100, outputs, 0); // create a mixer
recording = BASS_RecordStart(44100, inputs, 0, NULL, NULL); // start recording without a RECORDPROC
BASS_Mixer_StreamAddChannel(mixer, recording, BASS_MIXER_MATRIX); // plug it into the mixer
// set matrix here if needed
BASS_ChannelPlay(mixer, 0); // start the mixer

serkanp

  • Posts: 85
Re: BASS_Record on arm with multiple inputs on one device
« Reply #16 on: 13 Nov '18 - 14:59 »
forget the previous post :)
i get sound and matrix mixer works on mac, windows but not on raspberry

the code on mac and windows outputs the mic to left channel of the speakers.

same code on raspberry gives crackling and distorted output for only 1 second , then nothing.. and the cpu usage is %100-%140


here is the latest code:
Code: [Select]
let outputs=2
let inputs=2


let init=bass.BASS_Init(-1,44100,0)
let recinit=bass.BASS_RecordInit(-1)

console.log(`error:${bass.BASS_ErrorGetCode()}`)

let decodingHandle=bass.BASS_StreamCreate(44100,inputs,bass.BASS_STREAM_DECODE)

let mixerHandle=bass.BASS_Mixer_StreamCreate(44100,outputs,0)
console.log(`status mixer and error:${mixerHandle}-${bass.BASS_ErrorGetCode()}`)
var playresult= bass.BASS_ChannelPlay(mixerHandle, false);

let streamAddStatus=bass.BASS_Mixer_StreamAddChannel(mixerHandle,decodingHandle,bass.BASS_MIXER_MATRIX)
console.log(`sstreamAddStatus and error:${streamAddStatus}-${bass.BASS_ErrorGetCode()}`)


let handle=bass.BASS_RecordStart(44100,inputs,bass.BASS_RECORD_PAUSE,(handle:any,len:any,buffer:any,user:any)=>{
    bass.BASS_StreamPutData(decodingHandle,buffer,len)
    console.log(`len:${len}`)
})
bass.BASS_ChannelPlay(handle,false)




let m=[[1,0],[0,0]]
let MatrixResult=bass.BASS_Mixer_ChannelSetMatrix(decodingHandle,m)
console.log(`MatrixResult:${MatrixResult}`)
console.log(`error:${bass.BASS_ErrorGetCode()}`)



i think there is a problem with the latest bass components for armhf
maybe you can give a test executable to test on raspberry..

serkanp

  • Posts: 85
Re: BASS_Record on arm with multiple inputs on one device
« Reply #17 on: 13 Nov '18 - 15:06 »
The BASS_StreamPutData call will be failing because "decodingHandle" isn't a push stream (STREAMPROC_PUSH). When you want to play a recording channel through a mixer, you can remove the RECORDPROC from the BASS_RecordStart call and plug the recording directly into the mixer, with no need for an intermediate stream. For example:

Code: [Select]
mixer = BASS_Mixer_StreamCreate(44100, outputs, 0); // create a mixer
recording = BASS_RecordStart(44100, inputs, 0, NULL, NULL); // start recording without a RECORDPROC
BASS_Mixer_StreamAddChannel(mixer, recording, BASS_MIXER_MATRIX); // plug it into the mixer
// set matrix here if needed
BASS_ChannelPlay(mixer, 0); // start the mixer



i wrote the same code as you mentioned
Code: [Select]
let outputs=2
let inputs=2


let init=bass.BASS_Init(-1,44100,0)
let recinit=bass.BASS_RecordInit(-1)



let mixerHandle=bass.BASS_Mixer_StreamCreate(44100,outputs,0)
console.log(`status mixer and error:${mixerHandle}-${bass.BASS_ErrorGetCode()}`)

let recording=bass.BASS_RecordStart(44100,inputs,0,null)

let streamAddStatus=bass.BASS_Mixer_StreamAddChannel(mixerHandle,recording,bass.BASS_MIXER_MATRIX)
console.log(`sstreamAddStatus and error:${streamAddStatus}-${bass.BASS_ErrorGetCode()}`)

var playresult= bass.BASS_ChannelPlay(mixerHandle, false);

BASS_Mixer_StreamAddChannel gives error code 38

serkanp

  • Posts: 85
Re: BASS_Record on arm with multiple inputs on one device
« Reply #18 on: 14 Nov '18 - 14:42 »
The BASS_StreamPutData call will be failing because "decodingHandle" isn't a push stream (STREAMPROC_PUSH). When you want to play a recording channel through a mixer, you can remove the RECORDPROC from the BASS_RecordStart call and plug the recording directly into the mixer, with no need for an intermediate stream. For example:

Code: [Select]
mixer = BASS_Mixer_StreamCreate(44100, outputs, 0); // create a mixer
recording = BASS_RecordStart(44100, inputs, 0, NULL, NULL); // start recording without a RECORDPROC
BASS_Mixer_StreamAddChannel(mixer, recording, BASS_MIXER_MATRIX); // plug it into the mixer
// set matrix here if needed
BASS_ChannelPlay(mixer, 0); // start the mixer



i wrote the same code as you mentioned
Code: [Select]
let outputs=2
let inputs=2


let init=bass.BASS_Init(-1,44100,0)
let recinit=bass.BASS_RecordInit(-1)



let mixerHandle=bass.BASS_Mixer_StreamCreate(44100,outputs,0)
console.log(`status mixer and error:${mixerHandle}-${bass.BASS_ErrorGetCode()}`)

let recording=bass.BASS_RecordStart(44100,inputs,0,null)

let streamAddStatus=bass.BASS_Mixer_StreamAddChannel(mixerHandle,recording,bass.BASS_MIXER_MATRIX)
console.log(`sstreamAddStatus and error:${streamAddStatus}-${bass.BASS_ErrorGetCode()}`)

var playresult= bass.BASS_ChannelPlay(mixerHandle, false);

BASS_Mixer_StreamAddChannel gives error code 38

this code works on mac but not on raspberry..
s

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Record on arm with multiple inputs on one device
« Reply #19 on: 14 Nov '18 - 14:47 »
I'm not seeing those problems on an RPi2 here, when running the code I posted above with the latest libraries from the ARM Linux thread. It is sounding fine and using less than 3% CPU. If you would like to try it there, here's the compiled version that I used (includes some info display):

   www.un4seen.com/stuff/armlinux-mixtest

serkanp

  • Posts: 85
Re: BASS_Record on arm with multiple inputs on one device
« Reply #20 on: 14 Nov '18 - 14:56 »
here is the result..
crackling sound for 1-2 seconds.. then nothing..
and the cpu usage is ~%80

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Record on arm with multiple inputs on one device
« Reply #21 on: 14 Nov '18 - 15:22 »
That's strange. Please build the DEVLIST example from the Linux BASS package and post the output from that. You can build the Linux examples for ARM Linux by first extracting the Linux BASS package and then extracting the ARM Linux package into the same directory, and running "make".