I never actually saw anyone do a successful record with bass.dll, there was input meters but nothing else. Below is a script to record to a wav file. Thanks Lexikos for your assistance over one of my hurdles.
Code: Select all
SetBatchLines, -1
#Persistent
Gui, Add, Button, x182 y99 w100 h30 gStartRecord, Start
Gui, Add, Button, x182 y149 w100 h30 gStopRecord, Stop
; Generated using SmartGUI Creator for SciTE
Gui, Show, w479 h379, Untitled GUI
return
GuiClose:
ExitApp
StartRecord:
Control, Disable, , Start
RecordCallback := RegisterCallback("RecordFunction" )
FileDelete, 0_test.wav
;//// WRITE WAV HEADER /////
file := fileopen("0_test.wav", "rw", CP1252)
file.write("RIFF ") ; leave space for file size - 8
file.write("WAVEfmt ") ; Wave Container, 'fmt ' chunk, this takes up 8 bytes.
fmt_length = 0
numput(16, fmt_length, "UInt") ; 16 bytes, length of formatchunk in bytes
file.rawwrite(fmt_length, 4)
fmt_type = 0
numput(1,fmt_type, "UShort") ; format, 1 = PCM, linear aka non compressed
file.rawwrite(fmt_type, 2)
fmt_channels = 0
numput(2, fmt_channels, "UShort") ; 2 channels
file.rawwrite(fmt_channels, 2)
fmt_sample_rate = 0
numput(44100, fmt_sample_rate, "UInt") ; 44100 samples per second
file.rawwrite(fmt_sample_rate, 4)
fmt_byte_rate = 0
numput(176400, fmt_byte_rate, "UInt") ; bytes per second, 176400
file.rawwrite(fmt_byte_rate, 4)
fmt_blockalign=0
numput(4, fmt_blockalign, "UShort") ; NumChannels * BitsPerSample/8
file.rawwrite(fmt_blockalign, 2)
fmt_bitspersample=0
numput(16, fmt_bitspersample, "UShort") ; 16 bit resolution
file.rawwrite(fmt_bitspersample, 2)
file.write("data ") ; this takes up 8 bytes. leave space to write in the size of data chunk.
datasize = 0
;////// WAV HEADER COMPLETE, MOSTLY ///////
;////// LOAD BASS AND START RECORDING /////////
DllCall("LoadLibrary","str",A_ScriptDir "\bass.dll")
DllCall(A_ScriptDir "\bass.dll\BASS_RecordInit", Int,-1)
DllCall(A_ScriptDir "\bass.dll\BASS_ErrorGetCode")
hrecord := DllCall(A_ScriptDir "\bass.dll\BASS_RecordStart", UInt, 44100, UInt, 2, UInt, 0, UInt, RecordCallback, UInt, 0)
return
StopRecord:
DllCall(A_ScriptDir "\bass.dll\BASS_ChannelStop", UInt,hrecord)
;///// BACK TO HEADER //////
file.seek(40)
data_datasize=0
numput(datasize, data_datasize, "UInt") ; little endian
file.rawwrite(data_datasize, 4)
datasize+=36
file.seek(4)
riff_size=0
numput(datasize, riff_size, "UInt") ; little endian
file.rawwrite(riff_size, 4)
;///// DONE ///////
ExitApp
return
RecordFunction(handle, buffer, length, user)
{
global file
global datasize
file.rawwrite(buffer+0,length)
datasize += length
return true
}