Hello,
from an "on the fly stream" (fixed frequency), i want to send data to one audio device and at the same time record it disk file, but with differents formats.
For example, with stream created in 32 bits float format, I want to be able to send to audio device in 24 bits int and record in 16 bits int or 32 bits float format.
At this time, I can run audio gen stream (works well), send it to selected output sound device (I can hear it) and record it to disk (in the selected format trough a Bass encoder).
All this works OK only when audiogen stream is in 16 bits int format, no sound seems to be output on sound device when audiogen stream is in 32 bits float format.
Following code is not full, just show it for information (don't show errors handling).
var
AudioGenStream: HSTREAM;
StreamChan: HSTREAM = 0;
RecordChan: HRECORD = 0;
function MakeWave(handle: HSTREAM; buffer: Pointer; length: DWORD; user: Pointer): DWORD; stdcall;
var
buf: ^WORD;
buf2: ^DOUBLE;
begin
// make sinus
// in 16 bits int (-3768..+32767 range) with ^WORD buf pointer <= works
// in 32 bits float (-1..+1 range) with ^DOUBLE buf2 pointer <= don't works
end;
function RecordingCallback(channel: HRECORD; buffer: Pointer; length, user: DWORD): Boolean; stdcall;
begin
Result := Bool(BASS_Encode_IsActive(channel)); // continue recording if encoder is alive
end;
procedure BASS_Init_main;
begin
BASS_Init(FAudioGen.OutDeviceIdx, FAudioGen.SampleRate, BASS_SAMPLE_FLOAT, win, nil) then
end;
procedure BASS_Rec_Start;
begin
RecordChan := BASS_RecordStart(iSR, iCh, BASS_RECORD_PAUSE or BASS_SAMPLE_FLOAT, @RecordingCallback, nil);
wBassFlags := BASS_ENCODE_PCM or BASS_ENCODE_FP_24BIT or BASS_ENCODE_AUTOFREE {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF};
BASS_Encode_Start(AudioGenStream, pwidechar(FAudioRec.OutFileName), wBassFlags, nil, nil) = 0)
BASS_ChannelPlay(RecordChan, FALSE); // resume recording
end;
procedure TfmMain.Rec_Stop;
begin
BASS_Encode_Stop(AudioGenStream);
BASS_ChannelStop(RecordChan);
RecordChan := 0;
end;
procedure TfmMain.Gen_StreamCreate();
begin
AudioGenStream := BASS_StreamCreate(FAudioGen.SampleRate, FAudioGen.Channels, GenFlags, @MakeWave, 0)
end;
What is the best method to achieve that ?
Knowing that the software must run under win7..win11, is it more judicious to opt for WASAPI now?
I admit that I'm a little lost... and I suspect error with pointer in my MakeWave proc.
Thank you for your suggestions,
Remy