Merlin71 Posted May 7, 2012 Share Posted May 7, 2012 Hi there, I'm trying to use bass.dll (an audio libary). I want record from Line-in and play recorded sound with option to set volume of left and right channels. I wrote script that record from line-in and play sound, but i don't have any idea how control volume of each channel. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=beta #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "Bass.au3" #include "BassEnc.au3" #include "BassExt.au3" Global $BASS_STARTUP_BYPASS_VERSIONCHECK OnAutoItExitRegister("_FreeBass") HotKeySet("{ESC}", "_Exit") _BASS_Startup() _BASS_ENCODE_Startup() _BASS_EXT_STARTUP() _BASS_Init(0, -1, 44100, 0, "") _BASS_RecordInit(-1) $aBuffer = _BASS_EXT_MemoryBufferCreate() $hRecord = _BASS_RecordStart(44100, 2, 0, $BASS_EXT_RecordProc) $hStream = 0 $pBuffer = _BASS_EXT_MemoryBufferCreate() $bMp3Data = 0 $hEncoder = _BASS_Encode_Start($hRecord, '"' & @ScriptDir & '\CenterCutCl',BitOR(0,0)) While 1 ;~ $iSize = _BASS_EXT_MemoryBufferGetSize($aBuffer) If $iSize > 1024 Then $bMp3Data = _BASS_EXT_MemoryBufferGetData($aBuffer, $iSize) ConsoleWrite(TimerDiff($timer) & " - Bytes: " & BinaryLen($bMp3Data) & @CRLF) $timer = TimerInit() If BinaryLen($bMp3Data) > 0 Then _BASS_EXT_MemoryBufferAddData($pBuffer, $bMp3Data) If Not $hStream And _BASS_EXT_MemoryBufferGetSize($pBuffer) > 4096 Then $hStream = _BASS_StreamCreateFileUser($STREAMFILE_BUFFERPUSH, BitOR($BASS_STREAM_RESTRATE, $BASS_STREAM_BLOCK), $BASS_EXT_FILEPROCS, $pBuffer[0]) _BASS_ChannelPlay($hStream, 1) EndIf EndIf $iSize = _BASS_EXT_MemoryBufferGetSize($pBuffer) If $hStream And $iSize >= 1024 Then _BASS_EXT_StreamPutFileBufferData($hStream, $pBuffer, $iSize) EndIf Sleep(50) WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _FreeBass() _BASS_Encode_Stop($hEncoder) _BASS_RecordFree() _BASS_Free() EndFunc ;==>_FreeBass#Region ;**** Directives created by AutoIt3Wrapper_GUI *** Link to comment Share on other sites More sharing options...
microera Posted May 14, 2012 Share Posted May 14, 2012 any news about this? Are you solve problem with volume? Link to comment Share on other sites More sharing options...
Merlin71 Posted May 16, 2012 Author Share Posted May 16, 2012 After many experiments, I can play different files on the left and right channel. Remains only to record and mix the input channels. Test script (maybe useful, based on sample script from help) expandcollapse popup#AutoIt3Wrapper_UseX64=n #include "Bass.au3" #include "BassMix.au3" OnAutoItExitRegister("_FreeBass") HotKeySet("{ESC}", "_Exit") $sFile1 = FileOpenDialog("Open...", "..audiofiles", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)") ___Debug($sFile1 = "", $sFile1) $sFile2 = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)") ___Debug($sFile2 = "", $sFile2) _BASS_Startup() ___Debug(@error, "load bass.dll") _BASS_MIX_Startup() ___Debug(@error, "load bassmix.dll") _BASS_Init(0, -1, 44100, 0, "") ___Debug(@error, "initialize bass") $hStream1 = _BASS_StreamCreateFile(False, $sFile1, 0, 0, $BASS_STREAM_DECODE) ___Debug(@error, "create stream from file 1") _BASS_ChannelSetAttribute($hStream1,$BASS_ATTRIB_PAN,-1) _BASS_ChannelSetAttribute($hStream1,$BASS_ATTRIB_NOBUFFER,1) $hStream2 = _BASS_StreamCreateFile(False, $sFile2, 0, 0, $BASS_STREAM_DECODE) ___Debug(@error, "create stream from file 2") _BASS_ChannelSetAttribute($hStream2,$BASS_ATTRIB_PAN,1) _BASS_ChannelSetAttribute($hStream2,$BASS_ATTRIB_NOBUFFER,1) $hMixer = _BASS_Mixer_StreamCreate(44100, 2, $BASS_MIXER_END) ___Debug(@error, "create mixer stream") _BASS_Mixer_StreamAddChannel($hMixer, $hStream1, 0) ___Debug(@error, "add stream to mixer") _BASS_Mixer_StreamAddChannel($hMixer, $hStream2, 0) ___Debug(@error, "add stream to mixer") $i2Sec_Bytes = _BASS_ChannelSeconds2Bytes($hMixer, 5) ___Debug(@error, "2 seconds = " & $i2Sec_Bytes & " bytes") _BASS_ChannelPlay($hMixer, True) ___Debug(@error, "start channel") While _BASS_ChannelIsActive($hMixer) ;~ $aEnv1 = _BASS_Mixer_ChannelGetEnvelopePos($hStream1, $BASS_MIXER_ENV_VOL) ;~ $aEnv2 = _BASS_Mixer_ChannelGetEnvelopePos($hStream2, $BASS_MIXER_ENV_VOL) ;~ ToolTip("Volume channel 1: " & $aEnv1[1] & @CRLF & "Volume channel 2: " & $aEnv2[1]) Sleep(10) WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _FreeBass() _BASS_StreamFree($hStream1) _BASS_StreamFree($hStream2) _BASS_Free() EndFunc ;==>_FreeBass Func ___DeBug($iError, $sAction) Switch $iError Case -1 ConsoleWrite(@CRLF & "-" & $sAction & @CRLF) Case -2 ConsoleWrite(@CRLF & ">" & $sAction & @CRLF) Case 0 ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF) Case Else ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED, @error: " & $iError & @CRLF) Exit EndSwitch EndFunc ;==>___DeBug Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now